Introduce the helper function zbd_get_zone_from_offset() to get a zone structure using a file offset. This replaces the common code pattern: zone_idx = zbd_zone_idx_from_offset(f, _offset); z = zbd_get_zone(f, zone_idx); with a single function call in many functions. Signed-off-by: Damien Le Moal <damien.lemoal@xxxxxxxxxxxxxxxxxx> --- zbd.c | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/zbd.c b/zbd.c index 5c0fe00b..ba583c9f 100644 --- a/zbd.c +++ b/zbd.c @@ -129,6 +129,12 @@ static inline struct fio_zone_info *zbd_get_zone(const struct fio_file *f, return &f->zbd_info->zone_info[zone_idx]; } +static inline struct fio_zone_info * +zbd_get_zone_from_offset(const struct fio_file *f, uint64_t offset) +{ + return zbd_get_zone(f, zbd_zone_idx_from_offset(f, offset)); +} + /** * zbd_get_zoned_model - Get a device zoned model * @td: FIO thread data @@ -507,7 +513,6 @@ static bool zbd_verify_file_sizes(struct thread_data *td, struct fio_file *f) { const struct fio_zone_info *z; uint64_t new_offset, new_end; - uint32_t zone_idx; if (!f->zbd_info) return true; @@ -537,8 +542,7 @@ static bool zbd_verify_file_sizes(struct thread_data *td, struct fio_file *f) return false; } - zone_idx = zbd_zone_idx_from_offset(f, f->file_offset); - z = zbd_get_zone(f, zone_idx); + z = zbd_get_zone_from_offset(f, f->file_offset); if ((f->file_offset != z->start) && (td->o.td_ddir != TD_DDIR_READ)) { new_offset = zbd_zone_end(z); @@ -554,8 +558,7 @@ static bool zbd_verify_file_sizes(struct thread_data *td, struct fio_file *f) f->file_offset = new_offset; } - zone_idx = zbd_zone_idx_from_offset(f, f->file_offset + f->io_size); - z = zbd_get_zone(f, zone_idx); + z = zbd_get_zone_from_offset(f, f->file_offset + f->io_size); new_end = z->start; if ((td->o.td_ddir != TD_DDIR_READ) && (f->file_offset + f->io_size != new_end)) { @@ -1592,15 +1595,11 @@ static void zbd_queue_io(struct thread_data *td, struct io_u *io_u, int q, const struct fio_file *f = io_u->file; struct zoned_block_device_info *zbd_info = f->zbd_info; struct fio_zone_info *z; - uint32_t zone_idx; uint64_t zone_end; assert(zbd_info); - zone_idx = zbd_zone_idx_from_offset(f, io_u->offset); - assert(zone_idx < zbd_info->nr_zones); - z = zbd_get_zone(f, zone_idx); - + z = zbd_get_zone_from_offset(f, io_u->offset); assert(z->has_wp); if (!success) @@ -1608,7 +1607,7 @@ static void zbd_queue_io(struct thread_data *td, struct io_u *io_u, int q, dprint(FD_ZBD, "%s: queued I/O (%lld, %llu) for zone %u\n", - f->file_name, io_u->offset, io_u->buflen, zone_idx); + f->file_name, io_u->offset, io_u->buflen, zbd_zone_idx(f, z)); switch (io_u->ddir) { case DDIR_WRITE: @@ -1651,19 +1650,15 @@ static void zbd_put_io(struct thread_data *td, const struct io_u *io_u) const struct fio_file *f = io_u->file; struct zoned_block_device_info *zbd_info = f->zbd_info; struct fio_zone_info *z; - uint32_t zone_idx; assert(zbd_info); - zone_idx = zbd_zone_idx_from_offset(f, io_u->offset); - assert(zone_idx < zbd_info->nr_zones); - z = zbd_get_zone(f, zone_idx); - + z = zbd_get_zone_from_offset(f, io_u->offset); assert(z->has_wp); dprint(FD_ZBD, "%s: terminate I/O (%lld, %llu) for zone %u\n", - f->file_name, io_u->offset, io_u->buflen, zone_idx); + f->file_name, io_u->offset, io_u->buflen, zbd_zone_idx(f, z)); zbd_end_zone_io(td, io_u, z); @@ -1705,14 +1700,12 @@ void setup_zbd_zone_mode(struct thread_data *td, struct io_u *io_u) struct fio_file *f = io_u->file; enum fio_ddir ddir = io_u->ddir; struct fio_zone_info *z; - uint32_t zone_idx; assert(td->o.zone_mode == ZONE_MODE_ZBD); assert(td->o.zone_size); assert(f->zbd_info); - zone_idx = zbd_zone_idx_from_offset(f, f->last_pos[ddir]); - z = zbd_get_zone(f, zone_idx); + z = zbd_get_zone_from_offset(f, f->last_pos[ddir]); /* * When the zone capacity is smaller than the zone size and the I/O is @@ -1726,7 +1719,7 @@ void setup_zbd_zone_mode(struct thread_data *td, struct io_u *io_u) "%s: Jump from zone capacity limit to zone end:" " (%"PRIu64" -> %"PRIu64") for zone %u (%"PRIu64")\n", f->file_name, f->last_pos[ddir], - zbd_zone_end(z), zone_idx, z->capacity); + zbd_zone_end(z), zbd_zone_idx(f, z), z->capacity); td->io_skip_bytes += zbd_zone_end(z) - f->last_pos[ddir]; f->last_pos[ddir] = zbd_zone_end(z); } @@ -1807,7 +1800,6 @@ enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u) { struct fio_file *f = io_u->file; struct zoned_block_device_info *zbdi = f->zbd_info; - uint32_t zone_idx_b; struct fio_zone_info *zb, *zl, *orig_zb; uint32_t orig_len = io_u->buflen; uint64_t min_bs = td->o.min_bs[io_u->ddir]; @@ -1819,8 +1811,7 @@ enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u) assert(is_valid_offset(f, io_u->offset)); assert(io_u->buflen); - zone_idx_b = zbd_zone_idx_from_offset(f, io_u->offset); - zb = zbd_get_zone(f, zone_idx_b); + zb = zbd_get_zone_from_offset(f, io_u->offset); orig_zb = zb; if (!zb->has_wp) { @@ -2099,12 +2090,9 @@ int zbd_do_io_u_trim(const struct thread_data *td, struct io_u *io_u) { struct fio_file *f = io_u->file; struct fio_zone_info *z; - uint32_t zone_idx; int ret; - zone_idx = zbd_zone_idx_from_offset(f, io_u->offset); - z = zbd_get_zone(f, zone_idx); - + z = zbd_get_zone_from_offset(f, io_u->offset); if (!z->has_wp) return 0; -- 2.31.1