X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=zbd.c;h=2383c57dfc90aa8258e4ebcb5a2c6264de40457b;hb=379e5f09a16f789f3d15ff5541a42e1e74d2b383;hp=310b1732749702e551f475d1af4dd0f3b57c60dc;hpb=d9ed3e63e5280899e2e0bc7e55124c2a1acb30ca;p=fio.git diff --git a/zbd.c b/zbd.c index 310b1732..2383c57d 100644 --- a/zbd.c +++ b/zbd.c @@ -186,11 +186,14 @@ static bool zbd_verify_bs(void) * size of @buf. * * Returns 0 upon success and a negative error code upon failure. + * If the zone report is empty, always assume an error (device problem) and + * return -EIO. */ static int read_zone_info(int fd, uint64_t start_sector, void *buf, unsigned int bufsz) { struct blk_zone_report *hdr = buf; + int ret; if (bufsz < sizeof(*hdr)) return -EINVAL; @@ -199,7 +202,12 @@ static int read_zone_info(int fd, uint64_t start_sector, hdr->nr_zones = (bufsz - sizeof(*hdr)) / sizeof(struct blk_zone); hdr->sector = start_sector; - return ioctl(fd, BLKREPORTZONE, hdr) >= 0 ? 0 : -errno; + ret = ioctl(fd, BLKREPORTZONE, hdr); + if (ret) + return -errno; + if (!hdr->nr_zones) + return -EIO; + return 0; } /* @@ -418,8 +426,6 @@ static int parse_zone_info(struct thread_data *td, struct fio_file *f) p->start = z->start << 9; switch (z->cond) { case BLK_ZONE_COND_NOT_WP: - p->wp = p->start; - break; case BLK_ZONE_COND_FULL: p->wp = p->start + zone_size; break; @@ -475,7 +481,7 @@ out: * * Returns 0 upon success and a negative error code upon failure. */ -int zbd_create_zone_info(struct thread_data *td, struct fio_file *f) +static int zbd_create_zone_info(struct thread_data *td, struct fio_file *f) { enum blk_zoned_model zbd_model; int ret = 0; @@ -927,8 +933,8 @@ static void zbd_close_zone(struct thread_data *td, const struct fio_file *f, * a multiple of the fio block size. The caller must neither hold z->mutex * nor f->zbd_info->mutex. Returns with z->mutex held upon success. */ -struct fio_zone_info *zbd_convert_to_open_zone(struct thread_data *td, - struct io_u *io_u) +static struct fio_zone_info *zbd_convert_to_open_zone(struct thread_data *td, + struct io_u *io_u) { const uint32_t min_bs = td->o.min_bs[io_u->ddir]; const struct fio_file *f = io_u->file; @@ -1255,7 +1261,21 @@ enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u) zbd_check_swd(f); - pthread_mutex_lock(&zb->mutex); + /* + * Lock the io_u target zone. The zone will be unlocked if io_u offset + * is changed or when io_u completes and zbd_put_io() executed. + * To avoid multiple jobs doing asynchronous I/Os from deadlocking each + * other waiting for zone locks when building an io_u batch, first + * only trylock the zone. If the zone is already locked by another job, + * process the currently queued I/Os so that I/O progress is made and + * zones unlocked. + */ + if (pthread_mutex_trylock(&zb->mutex) != 0) { + if (!td_ioengine_flagged(td, FIO_SYNCIO)) + io_u_quiesce(td); + pthread_mutex_lock(&zb->mutex); + } + switch (io_u->ddir) { case DDIR_READ: if (td->runstate == TD_VERIFYING) {