[PATCH 2/2] btrfs-progs: do not zone reset on emulated zoned mode
From: Naohiro Aota <naohiro.aota@wdc.com>
Date: 2021-09-22 07:53:52
Subsystem:
the rest · Maintainer:
Linus Torvalds
We cannot zone reset a regular file with emulated zones. So, mkfs.btrfs on such a file cause a following error. ERROR: zoned: failed to reset device '/home/naota/tmp/btrfs.img' zones: Inappropriate ioctl for device Intorduce btrfs_zoned_device_info->emulated to distinguish the zones are emulated or not. And, use it to decide it needs zone reset or not. Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> --- common/device-utils.c | 27 +++++++++++++++------------ kernel-shared/zoned.c | 2 ++ kernel-shared/zoned.h | 1 + 3 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/common/device-utils.c b/common/device-utils.c
index 1c853545c6ad..503705c43754 100644
--- a/common/device-utils.c
+++ b/common/device-utils.c@@ -220,18 +220,21 @@ int btrfs_prepare_device(int fd, const char *file, u64 *block_count_ret, file); return 1; } - if (opflags & PREP_DEVICE_VERBOSE) - printf("Resetting device zones %s (%u zones) ...\n", - file, zinfo->nr_zones); - /* - * We cannot ignore zone reset errors for a zoned block - * device as this could result in the inability to write to - * non-empty sequential zones of the device. - */ - if (btrfs_reset_all_zones(fd, zinfo)) { - error("zoned: failed to reset device '%s' zones: %m", - file); - goto err; + + if (!zinfo->emulated) { + if (opflags & PREP_DEVICE_VERBOSE) + printf("Resetting device zones %s (%u zones) ...\n", + file, zinfo->nr_zones); + /* + * We cannot ignore zone reset errors for a zoned block + * device as this could result in the inability to write + * to non-empty sequential zones of the device. + */ + if (btrfs_reset_all_zones(fd, zinfo)) { + error("zoned: failed to reset device '%s' zones: %m", + file); + goto err; + } } } else if (opflags & PREP_DEVICE_DISCARD) { /*
diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c
index 891a2c0aeef2..6e46354b8b52 100644
--- a/kernel-shared/zoned.c
+++ b/kernel-shared/zoned.c@@ -346,6 +346,7 @@ static int report_zones(int fd, const char *file, error("zoned: ioctl BLKREPORTZONE failed (%m)"); exit(1); } + zinfo->emulated = false; } else { ret = emulate_report_zones(file, fd, sector << SECTOR_SHIFT,
@@ -354,6 +355,7 @@ static int report_zones(int fd, const char *file, error("zoned: failed to emulate BLKREPORTZONE"); exit(1); } + zinfo->emulated = true; } if (!rep->nr_zones)
diff --git a/kernel-shared/zoned.h b/kernel-shared/zoned.h
index 99f8e9a2faac..66cf081b84c3 100644
--- a/kernel-shared/zoned.h
+++ b/kernel-shared/zoned.h@@ -54,6 +54,7 @@ struct btrfs_zoned_device_info { u64 max_zone_append_size; u32 nr_zones; struct blk_zone *zones; + bool emulated; }; enum btrfs_zoned_model zoned_model(const char *file);
--
2.33.0