btrfs-progs: do not zone reset on emulated zoned mode

We cannot zone reset a regular file with emulated zones. So, mkfs.btrfs
on such a file causes the following error.

  ERROR: zoned: failed to reset device '/home/naota/tmp/btrfs.img' zones: Inappropriate ioctl for device

Introduce 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>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Naohiro Aota 2021-09-22 16:53:43 +09:00 committed by David Sterba
parent 0ccf519678
commit 53ec59ead0
3 changed files with 18 additions and 12 deletions

View File

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

View File

@ -343,6 +343,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,
@ -351,6 +352,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)

View File

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