X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=oslib%2Flinux-blkzoned.c;h=0a8a577a59e9d0f8488d34454af15f2c220ea034;hb=b4824992dca5ac9025e6259ae231d93872e7888e;hp=61ea3a53d6d5ce1b029db3bef33a18ece1baa4ac;hpb=427a7e0950a49a6e350a8e63a31cd8b1f331d4cc;p=fio.git diff --git a/oslib/linux-blkzoned.c b/oslib/linux-blkzoned.c index 61ea3a53..0a8a577a 100644 --- a/oslib/linux-blkzoned.c +++ b/oslib/linux-blkzoned.c @@ -113,6 +113,16 @@ out: return 0; } +static uint64_t zone_capacity(struct blk_zone_report *hdr, + struct blk_zone *blkz) +{ +#ifdef CONFIG_HAVE_REP_CAPACITY + if (hdr->flags & BLK_ZONE_REP_CAPACITY) + return blkz->capacity << 9; +#endif + return blkz->len << 9; +} + int blkzoned_report_zones(struct thread_data *td, struct fio_file *f, uint64_t offset, struct zbd_zone *zones, unsigned int nr_zones) @@ -143,12 +153,13 @@ int blkzoned_report_zones(struct thread_data *td, struct fio_file *f, } nr_zones = hdr->nr_zones; - blkz = &hdr->zones[0]; + blkz = (void *) hdr + sizeof(*hdr); z = &zones[0]; for (i = 0; i < nr_zones; i++, z++, blkz++) { z->start = blkz->start << 9; z->wp = blkz->wp << 9; z->len = blkz->len << 9; + z->capacity = zone_capacity(hdr, blkz); switch (blkz->type) { case BLK_ZONE_TYPE_CONVENTIONAL: @@ -211,9 +222,21 @@ int blkzoned_reset_wp(struct thread_data *td, struct fio_file *f, .sector = offset >> 9, .nr_sectors = length >> 9, }; + int fd, ret = 0; + + /* If the file is not yet opened, open it for this function. */ + fd = f->fd; + if (fd < 0) { + fd = open(f->file_name, O_RDWR | O_LARGEFILE); + if (fd < 0) + return -errno; + } - if (ioctl(f->fd, BLKRESETZONE, &zr) < 0) - return -errno; + if (ioctl(fd, BLKRESETZONE, &zr) < 0) + ret = -errno; - return 0; + if (f->fd < 0) + close(fd); + + return ret; }