@@ -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);
@@ -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)
@@ -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)
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(+)