@@ -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) {
/*
@@ -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)
@@ -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);
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(-)