diff mbox series

[24/26] btrfs-progs: zoned: wipe temporary superblocks in superblock log zone

Message ID 3425b775916cd02bb7bdf57e018ea0ead833db4e.1619416549.git.naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: zoned: zoned block device support | expand

Commit Message

Naohiro Aota April 26, 2021, 6:27 a.m. UTC
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 <naohiro.aota@wdc.com>
---
 kernel-shared/disk-io.c |  6 ++++++
 kernel-shared/zoned.c   | 20 ++++++++++++++++++++
 kernel-shared/zoned.h   |  6 ++++++
 3 files changed, 32 insertions(+)
diff mbox series

Patch

diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index d79d6a00cdf8..355010277ca9 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -1951,6 +1951,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 3c476eebf004..8801ed43157e 100644
--- a/kernel-shared/zoned.c
+++ b/kernel-shared/zoned.c
@@ -975,6 +975,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 9e1ce3ae103f..a2e84464a221 100644
--- a/kernel-shared/zoned.h
+++ b/kernel-shared/zoned.h
@@ -94,6 +94,7 @@  int btrfs_reset_chunk_zones(struct btrfs_fs_info *fs_info, u64 devid,
 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
 #define sbread(fd, buf, offset) \
 	pread64(fd, buf, BTRFS_SUPER_INFO_SIZE, offset)
@@ -154,6 +155,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)