From 8c2dfa6387f2a396e179be0c213b35ef46d2b4d2 Mon Sep 17 00:00:00 2001 From: Naohiro Aota Date: Mon, 26 Apr 2021 15:27:40 +0900 Subject: [PATCH] btrfs-progs: zoned: wipe temporary superblocks in superblock log zone mkfs.btrfs uses a temporary superblock during the initialization process. The temporary superblock uses BTRFS_MAGIC_TEMPORARY as its magic which is different from a regular superblock. As a result, libblkid, which only supports the usual magic, cannot recognize the volume as btrfs. So, let's wipe the temporary magic before writing out the usual superblock. Technically, we can add the temporary magic to the libblkid's table. But, it will result in recognizing a half-baked filesystem as btrfs, which is not ideal. Signed-off-by: Naohiro Aota Signed-off-by: David Sterba --- kernel-shared/disk-io.c | 6 ++++++ kernel-shared/zoned.c | 20 ++++++++++++++++++++ kernel-shared/zoned.h | 7 ++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c index 0205ce97..d976f29d 100644 --- a/kernel-shared/disk-io.c +++ b/kernel-shared/disk-io.c @@ -1953,6 +1953,12 @@ int close_ctree_fs_info(struct btrfs_fs_info *fs_info) } if (fs_info->finalize_on_close) { + ret = btrfs_wipe_temporary_sb(fs_info->fs_devices); + if (ret) { + error("zoned: failed to wipe temporary super blocks: %m"); + goto skip_commit; + } + btrfs_set_super_magic(fs_info->super_copy, BTRFS_MAGIC); root->fs_info->finalize_on_close = 0; ret = write_all_supers(fs_info); diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index 897bd2eb..30575493 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -968,6 +968,26 @@ int btrfs_reset_chunk_zones(struct btrfs_fs_info *fs_info, u64 devid, return 0; } +int btrfs_wipe_temporary_sb(struct btrfs_fs_devices *fs_devices) +{ + struct list_head *head = &fs_devices->devices; + struct btrfs_device *dev; + int ret = 0; + + list_for_each_entry(dev, head, dev_list) { + struct btrfs_zoned_device_info *zinfo = dev->zone_info; + + if (!zinfo) + continue; + + ret = btrfs_reset_dev_zone(dev->fd, &zinfo->zones[0]); + if (ret) + break; + } + + return ret; +} + #endif int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info) diff --git a/kernel-shared/zoned.h b/kernel-shared/zoned.h index f8fedf6a..a246e161 100644 --- a/kernel-shared/zoned.h +++ b/kernel-shared/zoned.h @@ -95,9 +95,9 @@ bool btrfs_redirty_extent_buffer_for_zoned(struct btrfs_fs_info *fs_info, int btrfs_reset_chunk_zones(struct btrfs_fs_info *fs_info, u64 devid, u64 offset, u64 length); int btrfs_reset_all_zones(int fd, struct btrfs_zoned_device_info *zinfo); - int zero_zone_blocks(int fd, struct btrfs_zoned_device_info *zinfo, off_t start, size_t len); +int btrfs_wipe_temporary_sb(struct btrfs_fs_devices *fs_devices); #else @@ -160,6 +160,11 @@ static inline int zero_zone_blocks(int fd, return -EOPNOTSUPP; } +static inline int btrfs_wipe_temporary_sb(struct btrfs_fs_devices *fs_devices) +{ + return 0; +} + #endif /* BTRFS_ZONED */ static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos)