The zoned btrfs puts a superblock at the beginning of SB logging zones
if the zone is conventional. This difference causes a chicken-and-egg
problem for emulated zoned mode. Since the device is a regular
(non-zoned) device, we cannot know if the btrfs is regular or emulated
zoned while we read the superblock. But, to load proper superblock, we
need to see if it is emulated zoned or not.

We place the SBs at the same location as the regular btrfs on emulated
zoned mode to solve the problem. It is possible because it's ensured
that all the SB locations are at a conventional zone on emulated zoned
mode.

Reviewed-by: Josef Bacik <jo...@toxicpanda.com>
Signed-off-by: Naohiro Aota <naohiro.a...@wdc.com>
---
 fs/btrfs/zoned.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index bcabdb2c97f1..87172ce7173b 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -553,7 +553,13 @@ int btrfs_sb_log_location(struct btrfs_device *device, int 
mirror, int rw,
        struct btrfs_zoned_device_info *zinfo = device->zone_info;
        u32 zone_num;
 
-       if (!zinfo) {
+       /*
+        * With btrfs zoned mode on a non-zoned block device, use the same
+        * super block locations as regular btrfs. Doing so, the super
+        * block can always be retrieved and the zoned-mode of the volume
+        * detected from the super block information.
+        */
+       if (!bdev_is_zoned(device->bdev)) {
                *bytenr_ret = btrfs_sb_offset(mirror);
                return 0;
        }
-- 
2.27.0

Reply via email to