zbd: allow zonemode=zbd with regular files by emulating zones
authorNiklas Cassel <niklas.cassel@wdc.com>
Mon, 14 Jun 2021 13:49:04 +0000 (13:49 +0000)
committerJens Axboe <axboe@kernel.dk>
Mon, 14 Jun 2021 14:54:49 +0000 (08:54 -0600)
Currently when using zonemode=zbd and running against a regular file,
fio will fail with:
fio: file hash not empty on exit

Treat regular files just like how we treat regular (non-zoned) block
devices: return ZBD_NONE and let zbd.c emulate zones inside the regular
file/block device.

Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
zbd.c
zbd_types.h

diff --git a/zbd.c b/zbd.c
index 60325d28fa6f4c3cfba577b3c9f7d17b7862abae..d1db9adc296a74a1bcd53203b7370eb767246406 100644 (file)
--- a/zbd.c
+++ b/zbd.c
@@ -37,6 +37,12 @@ int zbd_get_zoned_model(struct thread_data *td, struct fio_file *f,
                return -EINVAL;
        }
 
+       /* If regular file, always emulate zones inside the file. */
+       if (f->filetype == FIO_TYPE_FILE) {
+               *model = ZBD_NONE;
+               return 0;
+       }
+
        if (td->io_ops && td->io_ops->get_zoned_model)
                ret = td->io_ops->get_zoned_model(td, f, model);
        else
@@ -414,7 +420,7 @@ static int init_zone_info(struct thread_data *td, struct fio_file *f)
        int i;
 
        if (zone_size == 0) {
-               log_err("%s: Specifying the zone size is mandatory for regular block devices with --zonemode=zbd\n\n",
+               log_err("%s: Specifying the zone size is mandatory for regular file/block device with --zonemode=zbd\n\n",
                        f->file_name);
                return 1;
        }
@@ -435,6 +441,12 @@ static int init_zone_info(struct thread_data *td, struct fio_file *f)
                return 1;
        }
 
+       if (f->real_file_size < zone_size) {
+               log_err("%s: file/device size %"PRIu64" is smaller than zone size %"PRIu64"\n",
+                       f->file_name, f->real_file_size, zone_size);
+               return -EINVAL;
+       }
+
        nr_zones = (f->real_file_size + zone_size - 1) / zone_size;
        zbd_info = scalloc(1, sizeof(*zbd_info) +
                           (nr_zones + 1) * sizeof(zbd_info->zone_info[0]));
index 5ed41aa06c8ac371e264b9fd62af3a33a848bf9f..d0f4c44e23d1abd7a5289f1fb2770e3a9254a6a2 100644 (file)
@@ -15,7 +15,7 @@
  */
 enum zbd_zoned_model {
        ZBD_IGNORE,             /* Ignore file */
-       ZBD_NONE,               /* Regular block device */
+       ZBD_NONE,               /* No zone support. Emulate zones. */
        ZBD_HOST_AWARE,         /* Host-aware zoned block device */
        ZBD_HOST_MANAGED,       /* Host-managed zoned block device */
 };