@@ -1998,6 +1998,13 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
return transid > 0 ? 0 : -1;
}
+static bool check_sb_location(struct btrfs_device *device, u64 bytenr)
+{
+ if (!device->zone_info)
+ return bytenr + BTRFS_SUPER_INFO_SIZE <= device->total_bytes;
+ return btrfs_sb_zone_exists(device, bytenr);
+}
+
static int write_dev_supers(struct btrfs_fs_info *fs_info,
struct btrfs_super_block *sb,
struct btrfs_device *device)
@@ -2048,7 +2055,7 @@ static int write_dev_supers(struct btrfs_fs_info *fs_info,
for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
bytenr = btrfs_sb_offset(i);
- if (bytenr + BTRFS_SUPER_INFO_SIZE > device->total_bytes)
+ if (!check_sb_location(device, bytenr))
break;
btrfs_set_super_bytenr(sb, bytenr);
@@ -1175,3 +1175,11 @@ int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info)
out:
return ret;
}
+
+bool btrfs_sb_zone_exists(struct btrfs_device *device, u64 bytenr)
+{
+ u32 zone_num = sb_bytenr_to_sb_zone(bytenr,
+ ilog2(device->zone_info->zone_size));
+
+ return zone_num + 1 <= device->zone_info->nr_zones - 1;
+}
@@ -153,6 +153,7 @@ 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);
+bool btrfs_sb_zone_exists(struct btrfs_device *device, u64 bytenr);
#else
@@ -225,6 +226,11 @@ static inline bool zoned_profile_supported(u64 map_type, bool rst)
return false;
}
+static inline bool btrfs_sb_zone_exists(struct btrfs_device *device, u64 bytenr)
+{
+ return true;
+}
+
#endif /* BTRFS_ZONED */
/*
Currently, write_dev_supers() compares the superblock location vs the size of the device to check if it can write the superblock. This is not correct for a zoned device, whose superblock location is different than a regular device. Introduce check_sb_location() to check if the superblock zone exists for the zoned case. Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> --- kernel-shared/disk-io.c | 9 ++++++++- kernel-shared/zoned.c | 8 ++++++++ kernel-shared/zoned.h | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-)