On 2021/06/04 21:18, Niklas Cassel wrote: > From: Niklas Cassel <niklas.cassel@xxxxxxx> > > 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@xxxxxxx> > --- > zbd.c | 14 +++++++++++++- > zbd_types.h | 2 +- > 2 files changed, 14 insertions(+), 2 deletions(-) > > diff --git a/zbd.c b/zbd.c > index 60325d28..fb20f6cc 100644 > --- a/zbd.c > +++ b/zbd.c > @@ -37,6 +37,18 @@ 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) { > + if (!f->real_file_size) { > + log_err("%s: file size cannot be zero\n", > + f->file_name); > + return -EINVAL; > + } This check is not strong enough. The file size must be at least equal to the zone size. I think this check should go into init_zone_info(). In that function, the number of zones is calculated as: nr_zones = (f->real_file_size + zone_size - 1) / zone_size; And followed with: zbd_info = scalloc(1, sizeof(*zbd_info) + (nr_zones + 1) * sizeof(zbd_info->zone_info[0])); if (!zbd_info) return -ENOMEM; So even if nr_zones is 0 (i.e. f->real_file_size < zone_size), there will be no errors. We need to check that nr_zones > 0, or that f->real_file_size >= zone_size, whichever. > + > + *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 +426,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; > } > diff --git a/zbd_types.h b/zbd_types.h > index 5ed41aa0..d0f4c44e 100644 > --- a/zbd_types.h > +++ b/zbd_types.h > @@ -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 */ > }; > -- Damien Le Moal Western Digital Research