2 * Copyright (C) 2018 Western Digital Corporation or its affiliates.
4 * This file is released under the GPL.
19 #include "oslib/asprintf.h"
26 * zbd_get_zoned_model - Get a device zoned model
27 * @td: FIO thread data
28 * @f: FIO file for which to get model information
30 int zbd_get_zoned_model(struct thread_data *td, struct fio_file *f,
31 enum zbd_zoned_model *model)
35 if (td->io_ops && td->io_ops->get_zoned_model)
36 ret = td->io_ops->get_zoned_model(td, f, model);
38 ret = blkzoned_get_zoned_model(td, f, model);
40 td_verror(td, errno, "get zoned model failed");
41 log_err("%s: get zoned model failed (%d).\n",
49 * zbd_report_zones - Get zone information
50 * @td: FIO thread data.
51 * @f: FIO file for which to get zone information
52 * @offset: offset from which to report zones
53 * @zones: Array of struct zbd_zone
54 * @nr_zones: Size of @zones array
56 * Get zone information into @zones starting from the zone at offset @offset
57 * for the device specified by @f.
59 * Returns the number of zones reported upon success and a negative error code
60 * upon failure. If the zone report is empty, always assume an error (device
61 * problem) and return -EIO.
63 int zbd_report_zones(struct thread_data *td, struct fio_file *f,
64 uint64_t offset, struct zbd_zone *zones,
65 unsigned int nr_zones)
69 if (td->io_ops && td->io_ops->report_zones)
70 ret = td->io_ops->report_zones(td, f, offset, zones, nr_zones);
72 ret = blkzoned_report_zones(td, f, offset, zones, nr_zones);
74 td_verror(td, errno, "report zones failed");
75 log_err("%s: report zones from sector %llu failed (%d).\n",
76 f->file_name, (unsigned long long)offset >> 9, errno);
77 } else if (ret == 0) {
78 td_verror(td, errno, "Empty zone report");
79 log_err("%s: report zones from sector %llu is empty.\n",
80 f->file_name, (unsigned long long)offset >> 9);
88 * zbd_reset_wp - reset the write pointer of a range of zones
89 * @td: FIO thread data.
90 * @f: FIO file for which to reset zones
91 * @offset: Starting offset of the first zone to reset
92 * @length: Length of the range of zones to reset
94 * Reset the write pointer of all zones in the range @offset...@offset+@length.
95 * Returns 0 upon success and a negative error code upon failure.
97 int zbd_reset_wp(struct thread_data *td, struct fio_file *f,
98 uint64_t offset, uint64_t length)
102 if (td->io_ops && td->io_ops->reset_wp)
103 ret = td->io_ops->reset_wp(td, f, offset, length);
105 ret = blkzoned_reset_wp(td, f, offset, length);
107 td_verror(td, errno, "resetting wp failed");
108 log_err("%s: resetting wp for %llu sectors at sector %llu failed (%d).\n",
109 f->file_name, (unsigned long long)length >> 9,
110 (unsigned long long)offset >> 9, errno);
117 * zbd_zone_idx - convert an offset into a zone number
119 * @offset: offset in bytes. If this offset is in the first zone_size bytes
120 * past the disk size then the index of the sentinel is returned.
122 static uint32_t zbd_zone_idx(const struct fio_file *f, uint64_t offset)
126 if (f->zbd_info->zone_size_log2 > 0)
127 zone_idx = offset >> f->zbd_info->zone_size_log2;
129 zone_idx = offset / f->zbd_info->zone_size;
131 return min(zone_idx, f->zbd_info->nr_zones);
135 * zbd_zone_end - Return zone end location
136 * @z: zone info pointer.
138 static inline uint64_t zbd_zone_end(const struct fio_zone_info *z)
144 * zbd_zone_capacity_end - Return zone capacity limit end location
145 * @z: zone info pointer.
147 static inline uint64_t zbd_zone_capacity_end(const struct fio_zone_info *z)
149 return z->start + z->capacity;
153 * zbd_zone_full - verify whether a minimum number of bytes remain in a zone
155 * @z: zone info pointer.
156 * @required: minimum number of bytes that must remain in a zone.
158 * The caller must hold z->mutex.
160 static bool zbd_zone_full(const struct fio_file *f, struct fio_zone_info *z,
163 assert((required & 511) == 0);
166 z->wp + required > zbd_zone_capacity_end(z);
169 static void zone_lock(struct thread_data *td, const struct fio_file *f,
170 struct fio_zone_info *z)
172 struct zoned_block_device_info *zbd = f->zbd_info;
173 uint32_t nz = z - zbd->zone_info;
175 /* A thread should never lock zones outside its working area. */
176 assert(f->min_zone <= nz && nz < f->max_zone);
181 * Lock the io_u target zone. The zone will be unlocked if io_u offset
182 * is changed or when io_u completes and zbd_put_io() executed.
183 * To avoid multiple jobs doing asynchronous I/Os from deadlocking each
184 * other waiting for zone locks when building an io_u batch, first
185 * only trylock the zone. If the zone is already locked by another job,
186 * process the currently queued I/Os so that I/O progress is made and
189 if (pthread_mutex_trylock(&z->mutex) != 0) {
190 if (!td_ioengine_flagged(td, FIO_SYNCIO))
192 pthread_mutex_lock(&z->mutex);
196 static inline void zone_unlock(struct fio_zone_info *z)
201 ret = pthread_mutex_unlock(&z->mutex);
205 static bool is_valid_offset(const struct fio_file *f, uint64_t offset)
207 return (uint64_t)(offset - f->file_offset) < f->io_size;
210 static inline struct fio_zone_info *get_zone(const struct fio_file *f,
211 unsigned int zone_nr)
213 return &f->zbd_info->zone_info[zone_nr];
216 /* Verify whether direct I/O is used for all host-managed zoned drives. */
217 static bool zbd_using_direct_io(void)
219 struct thread_data *td;
224 if (td->o.odirect || !(td->o.td_ddir & TD_DDIR_WRITE))
226 for_each_file(td, f, j) {
228 f->zbd_info->model == ZBD_HOST_MANAGED)
236 /* Whether or not the I/O range for f includes one or more sequential zones */
237 static bool zbd_is_seq_job(struct fio_file *f)
239 uint32_t zone_idx, zone_idx_b, zone_idx_e;
244 zone_idx_b = zbd_zone_idx(f, f->file_offset);
245 zone_idx_e = zbd_zone_idx(f, f->file_offset + f->io_size - 1);
246 for (zone_idx = zone_idx_b; zone_idx <= zone_idx_e; zone_idx++)
247 if (get_zone(f, zone_idx)->has_wp)
254 * Verify whether offset and size parameters are aligned with zone boundaries.
256 static bool zbd_verify_sizes(void)
258 const struct fio_zone_info *z;
259 struct thread_data *td;
261 uint64_t new_offset, new_end;
266 for_each_file(td, f, j) {
269 if (f->file_offset >= f->real_file_size)
271 if (!zbd_is_seq_job(f))
274 if (!td->o.zone_size) {
275 td->o.zone_size = f->zbd_info->zone_size;
276 if (!td->o.zone_size) {
277 log_err("%s: invalid 0 zone size\n",
281 } else if (td->o.zone_size != f->zbd_info->zone_size) {
282 log_err("%s: job parameter zonesize %llu does not match disk zone size %llu.\n",
283 f->file_name, (unsigned long long) td->o.zone_size,
284 (unsigned long long) f->zbd_info->zone_size);
288 if (td->o.zone_skip % td->o.zone_size) {
289 log_err("%s: zoneskip %llu is not a multiple of the device zone size %llu.\n",
290 f->file_name, (unsigned long long) td->o.zone_skip,
291 (unsigned long long) td->o.zone_size);
295 zone_idx = zbd_zone_idx(f, f->file_offset);
296 z = get_zone(f, zone_idx);
297 if ((f->file_offset != z->start) &&
298 (td->o.td_ddir != TD_DDIR_READ)) {
299 new_offset = zbd_zone_end(z);
300 if (new_offset >= f->file_offset + f->io_size) {
301 log_info("%s: io_size must be at least one zone\n",
305 log_info("%s: rounded up offset from %llu to %llu\n",
306 f->file_name, (unsigned long long) f->file_offset,
307 (unsigned long long) new_offset);
308 f->io_size -= (new_offset - f->file_offset);
309 f->file_offset = new_offset;
311 zone_idx = zbd_zone_idx(f, f->file_offset + f->io_size);
312 z = get_zone(f, zone_idx);
314 if ((td->o.td_ddir != TD_DDIR_READ) &&
315 (f->file_offset + f->io_size != new_end)) {
316 if (new_end <= f->file_offset) {
317 log_info("%s: io_size must be at least one zone\n",
321 log_info("%s: rounded down io_size from %llu to %llu\n",
322 f->file_name, (unsigned long long) f->io_size,
323 (unsigned long long) new_end - f->file_offset);
324 f->io_size = new_end - f->file_offset;
332 static bool zbd_verify_bs(void)
334 struct thread_data *td;
339 for_each_file(td, f, j) {
344 zone_size = f->zbd_info->zone_size;
345 for (k = 0; k < FIO_ARRAY_SIZE(td->o.bs); k++) {
346 if (td->o.verify != VERIFY_NONE &&
347 zone_size % td->o.bs[k] != 0) {
348 log_info("%s: block size %llu is not a divisor of the zone size %llu\n",
349 f->file_name, td->o.bs[k],
350 (unsigned long long)zone_size);
359 static int ilog2(uint64_t i)
371 * Initialize f->zbd_info for devices that are not zoned block devices. This
372 * allows to execute a ZBD workload against a non-ZBD device.
374 static int init_zone_info(struct thread_data *td, struct fio_file *f)
377 struct fio_zone_info *p;
378 uint64_t zone_size = td->o.zone_size;
379 uint64_t zone_capacity = td->o.zone_capacity;
380 struct zoned_block_device_info *zbd_info = NULL;
383 if (zone_size == 0) {
384 log_err("%s: Specifying the zone size is mandatory for regular block devices with --zonemode=zbd\n\n",
389 if (zone_size < 512) {
390 log_err("%s: zone size must be at least 512 bytes for --zonemode=zbd\n\n",
395 if (zone_capacity == 0)
396 zone_capacity = zone_size;
398 if (zone_capacity > zone_size) {
399 log_err("%s: job parameter zonecapacity %llu is larger than zone size %llu\n",
400 f->file_name, (unsigned long long) td->o.zone_capacity,
401 (unsigned long long) td->o.zone_size);
405 nr_zones = (f->real_file_size + zone_size - 1) / zone_size;
406 zbd_info = scalloc(1, sizeof(*zbd_info) +
407 (nr_zones + 1) * sizeof(zbd_info->zone_info[0]));
411 mutex_init_pshared(&zbd_info->mutex);
412 zbd_info->refcount = 1;
413 p = &zbd_info->zone_info[0];
414 for (i = 0; i < nr_zones; i++, p++) {
415 mutex_init_pshared_with_type(&p->mutex,
416 PTHREAD_MUTEX_RECURSIVE);
417 p->start = i * zone_size;
419 p->type = ZBD_ZONE_TYPE_SWR;
420 p->cond = ZBD_ZONE_COND_EMPTY;
421 p->capacity = zone_capacity;
425 p->start = nr_zones * zone_size;
427 f->zbd_info = zbd_info;
428 f->zbd_info->zone_size = zone_size;
429 f->zbd_info->zone_size_log2 = is_power_of_2(zone_size) ?
430 ilog2(zone_size) : 0;
431 f->zbd_info->nr_zones = nr_zones;
436 * Maximum number of zones to report in one operation.
438 #define ZBD_REPORT_MAX_ZONES 8192U
441 * Parse the device zone report and store it in f->zbd_info. Must be called
442 * only for devices that are zoned, namely those with a model != ZBD_NONE.
444 static int parse_zone_info(struct thread_data *td, struct fio_file *f)
447 struct zbd_zone *zones, *z;
448 struct fio_zone_info *p;
449 uint64_t zone_size, offset;
450 struct zoned_block_device_info *zbd_info = NULL;
451 int i, j, ret = -ENOMEM;
453 zones = calloc(ZBD_REPORT_MAX_ZONES, sizeof(struct zbd_zone));
457 nrz = zbd_report_zones(td, f, 0, zones, ZBD_REPORT_MAX_ZONES);
460 log_info("fio: report zones (offset 0) failed for %s (%d).\n",
465 zone_size = zones[0].len;
466 nr_zones = (f->real_file_size + zone_size - 1) / zone_size;
468 if (td->o.zone_size == 0) {
469 td->o.zone_size = zone_size;
470 } else if (td->o.zone_size != zone_size) {
471 log_err("fio: %s job parameter zonesize %llu does not match disk zone size %llu.\n",
472 f->file_name, (unsigned long long) td->o.zone_size,
473 (unsigned long long) zone_size);
478 dprint(FD_ZBD, "Device %s has %d zones of size %llu KB\n", f->file_name,
479 nr_zones, (unsigned long long) zone_size / 1024);
481 zbd_info = scalloc(1, sizeof(*zbd_info) +
482 (nr_zones + 1) * sizeof(zbd_info->zone_info[0]));
485 mutex_init_pshared(&zbd_info->mutex);
486 zbd_info->refcount = 1;
487 p = &zbd_info->zone_info[0];
488 for (offset = 0, j = 0; j < nr_zones;) {
490 for (i = 0; i < nrz; i++, j++, z++, p++) {
491 mutex_init_pshared_with_type(&p->mutex,
492 PTHREAD_MUTEX_RECURSIVE);
494 p->capacity = z->capacity;
496 case ZBD_ZONE_COND_NOT_WP:
497 case ZBD_ZONE_COND_FULL:
498 p->wp = p->start + p->capacity;
501 assert(z->start <= z->wp);
502 assert(z->wp <= z->start + zone_size);
508 case ZBD_ZONE_TYPE_SWR:
517 if (j > 0 && p->start != p[-1].start + zone_size) {
518 log_info("%s: invalid zone data\n",
525 offset = z->start + z->len;
528 nrz = zbd_report_zones(td, f, offset, zones,
529 min((uint32_t)(nr_zones - j),
530 ZBD_REPORT_MAX_ZONES));
533 log_info("fio: report zones (offset %llu) failed for %s (%d).\n",
534 (unsigned long long)offset,
541 zbd_info->zone_info[nr_zones].start = offset;
543 f->zbd_info = zbd_info;
544 f->zbd_info->zone_size = zone_size;
545 f->zbd_info->zone_size_log2 = is_power_of_2(zone_size) ?
546 ilog2(zone_size) : 0;
547 f->zbd_info->nr_zones = nr_zones;
558 * Allocate zone information and store it into f->zbd_info if zonemode=zbd.
560 * Returns 0 upon success and a negative error code upon failure.
562 static int zbd_create_zone_info(struct thread_data *td, struct fio_file *f)
564 enum zbd_zoned_model zbd_model;
567 assert(td->o.zone_mode == ZONE_MODE_ZBD);
569 ret = zbd_get_zoned_model(td, f, &zbd_model);
577 case ZBD_HOST_MANAGED:
578 ret = parse_zone_info(td, f);
581 ret = init_zone_info(td, f);
584 td_verror(td, EINVAL, "Unsupported zoned model");
585 log_err("Unsupported zoned model\n");
590 f->zbd_info->model = zbd_model;
591 f->zbd_info->max_open_zones = td->o.max_open_zones;
596 void zbd_free_zone_info(struct fio_file *f)
602 pthread_mutex_lock(&f->zbd_info->mutex);
603 refcount = --f->zbd_info->refcount;
604 pthread_mutex_unlock(&f->zbd_info->mutex);
606 assert((int32_t)refcount >= 0);
613 * Initialize f->zbd_info.
615 * Returns 0 upon success and a negative error code upon failure.
617 * Note: this function can only work correctly if it is called before the first
620 static int zbd_init_zone_info(struct thread_data *td, struct fio_file *file)
622 struct thread_data *td2;
626 for_each_td(td2, i) {
627 for_each_file(td2, f2, j) {
628 if (td2 == td && f2 == file)
631 strcmp(f2->file_name, file->file_name) != 0)
633 file->zbd_info = f2->zbd_info;
634 file->zbd_info->refcount++;
639 ret = zbd_create_zone_info(td, file);
641 td_verror(td, -ret, "zbd_create_zone_info() failed");
645 static bool zbd_open_zone(struct thread_data *td, const struct fio_file *f,
647 static int zbd_reset_zone(struct thread_data *td, struct fio_file *f,
648 struct fio_zone_info *z);
650 int zbd_setup_files(struct thread_data *td)
655 for_each_file(td, f, i) {
656 if (zbd_init_zone_info(td, f))
660 if (!zbd_using_direct_io()) {
661 log_err("Using direct I/O is mandatory for writing to ZBD drives\n\n");
665 if (!zbd_verify_sizes())
668 if (!zbd_verify_bs())
671 for_each_file(td, f, i) {
672 struct zoned_block_device_info *zbd = f->zbd_info;
673 struct fio_zone_info *z;
679 f->min_zone = zbd_zone_idx(f, f->file_offset);
680 f->max_zone = zbd_zone_idx(f, f->file_offset + f->io_size);
683 * When all zones in the I/O range are conventional, io_size
684 * can be smaller than zone size, making min_zone the same
685 * as max_zone. This is why the assert below needs to be made
688 if (zbd_is_seq_job(f))
689 assert(f->min_zone < f->max_zone);
691 zbd->max_open_zones = zbd->max_open_zones ?: ZBD_MAX_OPEN_ZONES;
693 if (td->o.max_open_zones > 0 &&
694 zbd->max_open_zones != td->o.max_open_zones) {
695 log_err("Different 'max_open_zones' values\n");
698 if (zbd->max_open_zones > ZBD_MAX_OPEN_ZONES) {
699 log_err("'max_open_zones' value is limited by %u\n", ZBD_MAX_OPEN_ZONES);
703 for (zi = f->min_zone; zi < f->max_zone; zi++) {
704 z = &zbd->zone_info[zi];
705 if (z->cond != ZBD_ZONE_COND_IMP_OPEN &&
706 z->cond != ZBD_ZONE_COND_EXP_OPEN)
708 if (zbd_open_zone(td, f, zi))
711 * If the number of open zones exceeds specified limits,
712 * reset all extra open zones.
714 if (zbd_reset_zone(td, f, z) < 0) {
715 log_err("Failed to reest zone %d\n", zi);
724 static inline unsigned int zbd_zone_nr(const struct fio_file *f,
725 struct fio_zone_info *zone)
727 return zone - f->zbd_info->zone_info;
731 * zbd_reset_zone - reset the write pointer of a single zone
732 * @td: FIO thread data.
733 * @f: FIO file associated with the disk for which to reset a write pointer.
736 * Returns 0 upon success and a negative error code upon failure.
738 * The caller must hold z->mutex.
740 static int zbd_reset_zone(struct thread_data *td, struct fio_file *f,
741 struct fio_zone_info *z)
743 uint64_t offset = z->start;
744 uint64_t length = (z+1)->start - offset;
745 uint64_t data_in_zone = z->wp - z->start;
751 assert(is_valid_offset(f, offset + length - 1));
753 dprint(FD_ZBD, "%s: resetting wp of zone %u.\n", f->file_name,
755 switch (f->zbd_info->model) {
757 case ZBD_HOST_MANAGED:
758 ret = zbd_reset_wp(td, f, offset, length);
766 pthread_mutex_lock(&f->zbd_info->mutex);
767 f->zbd_info->sectors_with_data -= data_in_zone;
768 f->zbd_info->wp_sectors_with_data -= data_in_zone;
769 pthread_mutex_unlock(&f->zbd_info->mutex);
773 td->ts.nr_zone_resets++;
778 /* The caller must hold f->zbd_info->mutex */
779 static void zbd_close_zone(struct thread_data *td, const struct fio_file *f,
780 unsigned int zone_idx)
782 uint32_t open_zone_idx = 0;
784 for (; open_zone_idx < f->zbd_info->num_open_zones; open_zone_idx++) {
785 if (f->zbd_info->open_zones[open_zone_idx] == zone_idx)
788 if (open_zone_idx == f->zbd_info->num_open_zones)
791 dprint(FD_ZBD, "%s: closing zone %d\n", f->file_name, zone_idx);
792 memmove(f->zbd_info->open_zones + open_zone_idx,
793 f->zbd_info->open_zones + open_zone_idx + 1,
794 (ZBD_MAX_OPEN_ZONES - (open_zone_idx + 1)) *
795 sizeof(f->zbd_info->open_zones[0]));
796 f->zbd_info->num_open_zones--;
797 td->num_open_zones--;
798 get_zone(f, zone_idx)->open = 0;
802 * Reset a range of zones. Returns 0 upon success and 1 upon failure.
803 * @td: fio thread data.
804 * @f: fio file for which to reset zones
805 * @zb: first zone to reset.
806 * @ze: first zone not to reset.
807 * @all_zones: whether to reset all zones or only those zones for which the
808 * write pointer is not a multiple of td->o.min_bs[DDIR_WRITE].
810 static int zbd_reset_zones(struct thread_data *td, struct fio_file *f,
811 struct fio_zone_info *const zb,
812 struct fio_zone_info *const ze, bool all_zones)
814 struct fio_zone_info *z;
815 const uint32_t min_bs = td->o.min_bs[DDIR_WRITE];
821 dprint(FD_ZBD, "%s: examining zones %u .. %u\n", f->file_name,
822 zbd_zone_nr(f, zb), zbd_zone_nr(f, ze));
823 for (z = zb; z < ze; z++) {
824 uint32_t nz = zbd_zone_nr(f, z);
830 pthread_mutex_lock(&f->zbd_info->mutex);
831 zbd_close_zone(td, f, nz);
832 pthread_mutex_unlock(&f->zbd_info->mutex);
834 reset_wp = z->wp != z->start;
836 reset_wp = z->wp % min_bs != 0;
839 dprint(FD_ZBD, "%s: resetting zone %u\n",
840 f->file_name, zbd_zone_nr(f, z));
841 if (zbd_reset_zone(td, f, z) < 0)
851 * Reset zbd_info.write_cnt, the counter that counts down towards the next
854 static void _zbd_reset_write_cnt(const struct thread_data *td,
855 const struct fio_file *f)
857 assert(0 <= td->o.zrf.u.f && td->o.zrf.u.f <= 1);
859 f->zbd_info->write_cnt = td->o.zrf.u.f ?
860 min(1.0 / td->o.zrf.u.f, 0.0 + UINT_MAX) : UINT_MAX;
863 static void zbd_reset_write_cnt(const struct thread_data *td,
864 const struct fio_file *f)
866 pthread_mutex_lock(&f->zbd_info->mutex);
867 _zbd_reset_write_cnt(td, f);
868 pthread_mutex_unlock(&f->zbd_info->mutex);
871 static bool zbd_dec_and_reset_write_cnt(const struct thread_data *td,
872 const struct fio_file *f)
874 uint32_t write_cnt = 0;
876 pthread_mutex_lock(&f->zbd_info->mutex);
877 assert(f->zbd_info->write_cnt);
878 if (f->zbd_info->write_cnt)
879 write_cnt = --f->zbd_info->write_cnt;
881 _zbd_reset_write_cnt(td, f);
882 pthread_mutex_unlock(&f->zbd_info->mutex);
884 return write_cnt == 0;
892 /* Calculate the number of sectors with data (swd) and perform action 'a' */
893 static uint64_t zbd_process_swd(struct thread_data *td,
894 const struct fio_file *f, enum swd_action a)
896 struct fio_zone_info *zb, *ze, *z;
900 zb = get_zone(f, f->min_zone);
901 ze = get_zone(f, f->max_zone);
902 for (z = zb; z < ze; z++) {
905 wp_swd += z->wp - z->start;
907 swd += z->wp - z->start;
909 pthread_mutex_lock(&f->zbd_info->mutex);
912 assert(f->zbd_info->sectors_with_data == swd);
913 assert(f->zbd_info->wp_sectors_with_data == wp_swd);
916 f->zbd_info->sectors_with_data = swd;
917 f->zbd_info->wp_sectors_with_data = wp_swd;
920 pthread_mutex_unlock(&f->zbd_info->mutex);
921 for (z = zb; z < ze; z++)
929 * The swd check is useful for debugging but takes too much time to leave
930 * it enabled all the time. Hence it is disabled by default.
932 static const bool enable_check_swd = false;
934 /* Check whether the values of zbd_info.*sectors_with_data are correct. */
935 static void zbd_check_swd(struct thread_data *td, const struct fio_file *f)
937 if (!enable_check_swd)
940 zbd_process_swd(td, f, CHECK_SWD);
943 void zbd_file_reset(struct thread_data *td, struct fio_file *f)
945 struct fio_zone_info *zb, *ze;
948 if (!f->zbd_info || !td_write(td))
951 zb = get_zone(f, f->min_zone);
952 ze = get_zone(f, f->max_zone);
953 swd = zbd_process_swd(td, f, SET_SWD);
954 dprint(FD_ZBD, "%s(%s): swd = %" PRIu64 "\n", __func__, f->file_name,
957 * If data verification is enabled reset the affected zones before
958 * writing any data to avoid that a zone reset has to be issued while
959 * writing data, which causes data loss.
961 zbd_reset_zones(td, f, zb, ze, td->o.verify != VERIFY_NONE &&
962 td->runstate != TD_VERIFYING);
963 zbd_reset_write_cnt(td, f);
966 /* The caller must hold f->zbd_info->mutex. */
967 static bool is_zone_open(const struct thread_data *td, const struct fio_file *f,
968 unsigned int zone_idx)
970 struct zoned_block_device_info *zbdi = f->zbd_info;
973 assert(td->o.job_max_open_zones == 0 || td->num_open_zones <= td->o.job_max_open_zones);
974 assert(td->o.job_max_open_zones <= zbdi->max_open_zones);
975 assert(zbdi->num_open_zones <= zbdi->max_open_zones);
977 for (i = 0; i < zbdi->num_open_zones; i++)
978 if (zbdi->open_zones[i] == zone_idx)
985 * Open a ZBD zone if it was not yet open. Returns true if either the zone was
986 * already open or if opening a new zone is allowed. Returns false if the zone
987 * was not yet open and opening a new zone would cause the zone limit to be
990 static bool zbd_open_zone(struct thread_data *td, const struct fio_file *f,
993 const uint32_t min_bs = td->o.min_bs[DDIR_WRITE];
994 struct fio_zone_info *z = get_zone(f, zone_idx);
997 if (z->cond == ZBD_ZONE_COND_OFFLINE)
1001 * Skip full zones with data verification enabled because resetting a
1002 * zone causes data loss and hence causes verification to fail.
1004 if (td->o.verify != VERIFY_NONE && zbd_zone_full(f, z, min_bs))
1007 pthread_mutex_lock(&f->zbd_info->mutex);
1008 if (is_zone_open(td, f, zone_idx)) {
1010 * If the zone is already open and going to be full by writes
1011 * in-flight, handle it as a full zone instead of an open zone.
1013 if (z->wp >= zbd_zone_capacity_end(z))
1018 /* Zero means no limit */
1019 if (td->o.job_max_open_zones > 0 &&
1020 td->num_open_zones >= td->o.job_max_open_zones)
1022 if (f->zbd_info->num_open_zones >= f->zbd_info->max_open_zones)
1024 dprint(FD_ZBD, "%s: opening zone %d\n", f->file_name, zone_idx);
1025 f->zbd_info->open_zones[f->zbd_info->num_open_zones++] = zone_idx;
1026 td->num_open_zones++;
1031 pthread_mutex_unlock(&f->zbd_info->mutex);
1035 /* Anything goes as long as it is not a constant. */
1036 static uint32_t pick_random_zone_idx(const struct fio_file *f,
1037 const struct io_u *io_u)
1039 return io_u->offset * f->zbd_info->num_open_zones / f->real_file_size;
1043 * Modify the offset of an I/O unit that does not refer to an open zone such
1044 * that it refers to an open zone. Close an open zone and open a new zone if
1045 * necessary. The open zone is searched across sequential zones.
1046 * This algorithm can only work correctly if all write pointers are
1047 * a multiple of the fio block size. The caller must neither hold z->mutex
1048 * nor f->zbd_info->mutex. Returns with z->mutex held upon success.
1050 static struct fio_zone_info *zbd_convert_to_open_zone(struct thread_data *td,
1053 const uint32_t min_bs = td->o.min_bs[io_u->ddir];
1054 struct fio_file *f = io_u->file;
1055 struct fio_zone_info *z;
1056 unsigned int open_zone_idx = -1;
1057 uint32_t zone_idx, new_zone_idx;
1059 bool wait_zone_close;
1061 assert(is_valid_offset(f, io_u->offset));
1063 if (td->o.max_open_zones || td->o.job_max_open_zones) {
1065 * This statement accesses f->zbd_info->open_zones[] on purpose
1068 zone_idx = f->zbd_info->open_zones[pick_random_zone_idx(f, io_u)];
1070 zone_idx = zbd_zone_idx(f, io_u->offset);
1072 if (zone_idx < f->min_zone)
1073 zone_idx = f->min_zone;
1074 else if (zone_idx >= f->max_zone)
1075 zone_idx = f->max_zone - 1;
1076 dprint(FD_ZBD, "%s(%s): starting from zone %d (offset %lld, buflen %lld)\n",
1077 __func__, f->file_name, zone_idx, io_u->offset, io_u->buflen);
1080 * Since z->mutex is the outer lock and f->zbd_info->mutex the inner
1081 * lock it can happen that the state of the zone with index zone_idx
1082 * has changed after 'z' has been assigned and before f->zbd_info->mutex
1083 * has been obtained. Hence the loop.
1088 z = get_zone(f, zone_idx);
1090 zone_lock(td, f, z);
1091 pthread_mutex_lock(&f->zbd_info->mutex);
1093 if (z->cond != ZBD_ZONE_COND_OFFLINE &&
1094 td->o.max_open_zones == 0 && td->o.job_max_open_zones == 0)
1096 if (f->zbd_info->num_open_zones == 0) {
1097 dprint(FD_ZBD, "%s(%s): no zones are open\n",
1098 __func__, f->file_name);
1099 goto open_other_zone;
1104 * List of opened zones is per-device, shared across all threads.
1105 * Start with quasi-random candidate zone.
1106 * Ignore zones which don't belong to thread's offset/size area.
1108 open_zone_idx = pick_random_zone_idx(f, io_u);
1109 assert(!open_zone_idx ||
1110 open_zone_idx < f->zbd_info->num_open_zones);
1111 tmp_idx = open_zone_idx;
1112 for (i = 0; i < f->zbd_info->num_open_zones; i++) {
1115 if (tmp_idx >= f->zbd_info->num_open_zones)
1117 tmpz = f->zbd_info->open_zones[tmp_idx];
1118 if (f->min_zone <= tmpz && tmpz < f->max_zone) {
1119 open_zone_idx = tmp_idx;
1120 goto found_candidate_zone;
1126 dprint(FD_ZBD, "%s(%s): no candidate zone\n",
1127 __func__, f->file_name);
1128 pthread_mutex_unlock(&f->zbd_info->mutex);
1133 found_candidate_zone:
1134 new_zone_idx = f->zbd_info->open_zones[open_zone_idx];
1135 if (new_zone_idx == zone_idx)
1137 zone_idx = new_zone_idx;
1138 pthread_mutex_unlock(&f->zbd_info->mutex);
1143 /* Both z->mutex and f->zbd_info->mutex are held. */
1146 if (z->wp + min_bs <= zbd_zone_capacity_end(z)) {
1147 pthread_mutex_unlock(&f->zbd_info->mutex);
1152 /* Check if number of open zones reaches one of limits. */
1154 f->zbd_info->num_open_zones == f->max_zone - f->min_zone ||
1155 (td->o.max_open_zones &&
1156 f->zbd_info->num_open_zones == td->o.max_open_zones) ||
1157 (td->o.job_max_open_zones &&
1158 td->num_open_zones == td->o.job_max_open_zones);
1160 pthread_mutex_unlock(&f->zbd_info->mutex);
1162 /* Only z->mutex is held. */
1165 * When number of open zones reaches to one of limits, wait for
1166 * zone close before opening a new zone.
1168 if (wait_zone_close) {
1169 dprint(FD_ZBD, "%s(%s): quiesce to allow open zones to close\n",
1170 __func__, f->file_name);
1174 /* Zone 'z' is full, so try to open a new zone. */
1175 for (i = f->io_size / f->zbd_info->zone_size; i > 0; i--) {
1180 if (!is_valid_offset(f, z->start)) {
1182 zone_idx = f->min_zone;
1183 z = get_zone(f, zone_idx);
1185 assert(is_valid_offset(f, z->start));
1188 zone_lock(td, f, z);
1191 if (zbd_open_zone(td, f, zone_idx))
1195 /* Only z->mutex is held. */
1197 /* Check whether the write fits in any of the already opened zones. */
1198 pthread_mutex_lock(&f->zbd_info->mutex);
1199 for (i = 0; i < f->zbd_info->num_open_zones; i++) {
1200 zone_idx = f->zbd_info->open_zones[i];
1201 if (zone_idx < f->min_zone || zone_idx >= f->max_zone)
1203 pthread_mutex_unlock(&f->zbd_info->mutex);
1206 z = get_zone(f, zone_idx);
1208 zone_lock(td, f, z);
1209 if (z->wp + min_bs <= zbd_zone_capacity_end(z))
1211 pthread_mutex_lock(&f->zbd_info->mutex);
1213 pthread_mutex_unlock(&f->zbd_info->mutex);
1215 dprint(FD_ZBD, "%s(%s): did not open another zone\n", __func__,
1220 dprint(FD_ZBD, "%s(%s): returning zone %d\n", __func__, f->file_name,
1222 io_u->offset = z->start;
1224 assert(z->cond != ZBD_ZONE_COND_OFFLINE);
1228 /* The caller must hold z->mutex. */
1229 static struct fio_zone_info *zbd_replay_write_order(struct thread_data *td,
1231 struct fio_zone_info *z)
1233 const struct fio_file *f = io_u->file;
1234 const uint32_t min_bs = td->o.min_bs[DDIR_WRITE];
1236 if (!zbd_open_zone(td, f, zbd_zone_nr(f, z))) {
1238 z = zbd_convert_to_open_zone(td, io_u);
1242 if (z->verify_block * min_bs >= z->capacity) {
1243 log_err("%s: %d * %d >= %llu\n", f->file_name, z->verify_block,
1244 min_bs, (unsigned long long)z->capacity);
1246 * If the assertion below fails during a test run, adding
1247 * "--experimental_verify=1" to the command line may help.
1251 io_u->offset = z->start + z->verify_block * min_bs;
1252 if (io_u->offset + io_u->buflen >= zbd_zone_capacity_end(z)) {
1253 log_err("%s: %llu + %llu >= %llu\n", f->file_name, io_u->offset,
1254 io_u->buflen, (unsigned long long) zbd_zone_capacity_end(z));
1257 z->verify_block += io_u->buflen / min_bs;
1263 * Find another zone for which @io_u fits in the readable data in the zone.
1264 * Search in zones @zb + 1 .. @zl. For random workload, also search in zones
1267 * Either returns NULL or returns a zone pointer. When the zone has write
1268 * pointer, hold the mutex for the zone.
1270 static struct fio_zone_info *
1271 zbd_find_zone(struct thread_data *td, struct io_u *io_u,
1272 struct fio_zone_info *zb, struct fio_zone_info *zl)
1274 const uint32_t min_bs = td->o.min_bs[io_u->ddir];
1275 struct fio_file *f = io_u->file;
1276 struct fio_zone_info *z1, *z2;
1277 const struct fio_zone_info *const zf = get_zone(f, f->min_zone);
1280 * Skip to the next non-empty zone in case of sequential I/O and to
1281 * the nearest non-empty zone in case of random I/O.
1283 for (z1 = zb + 1, z2 = zb - 1; z1 < zl || z2 >= zf; z1++, z2--) {
1284 if (z1 < zl && z1->cond != ZBD_ZONE_COND_OFFLINE) {
1286 zone_lock(td, f, z1);
1287 if (z1->start + min_bs <= z1->wp)
1291 } else if (!td_random(td)) {
1294 if (td_random(td) && z2 >= zf &&
1295 z2->cond != ZBD_ZONE_COND_OFFLINE) {
1297 zone_lock(td, f, z2);
1298 if (z2->start + min_bs <= z2->wp)
1304 dprint(FD_ZBD, "%s: adjusting random read offset failed\n",
1310 * zbd_end_zone_io - update zone status at command completion
1312 * @z: zone info pointer
1314 * If the write command made the zone full, close it.
1316 * The caller must hold z->mutex.
1318 static void zbd_end_zone_io(struct thread_data *td, const struct io_u *io_u,
1319 struct fio_zone_info *z)
1321 const struct fio_file *f = io_u->file;
1323 if (io_u->ddir == DDIR_WRITE &&
1324 io_u->offset + io_u->buflen >= zbd_zone_capacity_end(z)) {
1325 pthread_mutex_lock(&f->zbd_info->mutex);
1326 zbd_close_zone(td, f, zbd_zone_nr(f, z));
1327 pthread_mutex_unlock(&f->zbd_info->mutex);
1332 * zbd_queue_io - update the write pointer of a sequential zone
1334 * @success: Whether or not the I/O unit has been queued successfully
1335 * @q: queueing status (busy, completed or queued).
1337 * For write and trim operations, update the write pointer of the I/O unit
1340 static void zbd_queue_io(struct thread_data *td, struct io_u *io_u, int q,
1343 const struct fio_file *f = io_u->file;
1344 struct zoned_block_device_info *zbd_info = f->zbd_info;
1345 struct fio_zone_info *z;
1352 zone_idx = zbd_zone_idx(f, io_u->offset);
1353 assert(zone_idx < zbd_info->nr_zones);
1354 z = get_zone(f, zone_idx);
1362 "%s: queued I/O (%lld, %llu) for zone %u\n",
1363 f->file_name, io_u->offset, io_u->buflen, zone_idx);
1365 switch (io_u->ddir) {
1367 zone_end = min((uint64_t)(io_u->offset + io_u->buflen),
1368 zbd_zone_capacity_end(z));
1369 pthread_mutex_lock(&zbd_info->mutex);
1371 * z->wp > zone_end means that one or more I/O errors
1374 if (z->wp <= zone_end) {
1375 zbd_info->sectors_with_data += zone_end - z->wp;
1376 zbd_info->wp_sectors_with_data += zone_end - z->wp;
1378 pthread_mutex_unlock(&zbd_info->mutex);
1382 assert(z->wp == z->start);
1388 if (q == FIO_Q_COMPLETED && !io_u->error)
1389 zbd_end_zone_io(td, io_u, z);
1392 if (!success || q != FIO_Q_QUEUED) {
1393 /* BUSY or COMPLETED: unlock the zone */
1395 io_u->zbd_put_io = NULL;
1400 * zbd_put_io - Unlock an I/O unit target zone lock
1403 static void zbd_put_io(struct thread_data *td, const struct io_u *io_u)
1405 const struct fio_file *f = io_u->file;
1406 struct zoned_block_device_info *zbd_info = f->zbd_info;
1407 struct fio_zone_info *z;
1413 zone_idx = zbd_zone_idx(f, io_u->offset);
1414 assert(zone_idx < zbd_info->nr_zones);
1415 z = get_zone(f, zone_idx);
1420 "%s: terminate I/O (%lld, %llu) for zone %u\n",
1421 f->file_name, io_u->offset, io_u->buflen, zone_idx);
1423 zbd_end_zone_io(td, io_u, z);
1426 zbd_check_swd(td, f);
1430 * Windows and MacOS do not define this.
1433 #define EREMOTEIO 121 /* POSIX value */
1436 bool zbd_unaligned_write(int error_code)
1438 switch (error_code) {
1447 * setup_zbd_zone_mode - handle zoneskip as necessary for ZBD drives
1448 * @td: FIO thread data.
1449 * @io_u: FIO I/O unit.
1451 * For sequential workloads, change the file offset to skip zoneskip bytes when
1452 * no more IO can be performed in the current zone.
1453 * - For read workloads, zoneskip is applied when the io has reached the end of
1454 * the zone or the zone write position (when td->o.read_beyond_wp is false).
1455 * - For write workloads, zoneskip is applied when the zone is full.
1456 * This applies only to read and write operations.
1458 void setup_zbd_zone_mode(struct thread_data *td, struct io_u *io_u)
1460 struct fio_file *f = io_u->file;
1461 enum fio_ddir ddir = io_u->ddir;
1462 struct fio_zone_info *z;
1465 assert(td->o.zone_mode == ZONE_MODE_ZBD);
1466 assert(td->o.zone_size);
1468 zone_idx = zbd_zone_idx(f, f->last_pos[ddir]);
1469 z = get_zone(f, zone_idx);
1472 * When the zone capacity is smaller than the zone size and the I/O is
1473 * sequential write, skip to zone end if the latest position is at the
1474 * zone capacity limit.
1476 if (z->capacity < f->zbd_info->zone_size && !td_random(td) &&
1477 ddir == DDIR_WRITE &&
1478 f->last_pos[ddir] >= zbd_zone_capacity_end(z)) {
1480 "%s: Jump from zone capacity limit to zone end:"
1481 " (%llu -> %llu) for zone %u (%llu)\n",
1482 f->file_name, (unsigned long long) f->last_pos[ddir],
1483 (unsigned long long) zbd_zone_end(z), zone_idx,
1484 (unsigned long long) z->capacity);
1485 td->io_skip_bytes += zbd_zone_end(z) - f->last_pos[ddir];
1486 f->last_pos[ddir] = zbd_zone_end(z);
1490 * zone_skip is valid only for sequential workloads.
1492 if (td_random(td) || !td->o.zone_skip)
1496 * It is time to switch to a new zone if:
1497 * - zone_bytes == zone_size bytes have already been accessed
1498 * - The last position reached the end of the current zone.
1499 * - For reads with td->o.read_beyond_wp == false, the last position
1500 * reached the zone write pointer.
1502 if (td->zone_bytes >= td->o.zone_size ||
1503 f->last_pos[ddir] >= zbd_zone_end(z) ||
1504 (ddir == DDIR_READ &&
1505 (!td->o.read_beyond_wp) && f->last_pos[ddir] >= z->wp)) {
1510 f->file_offset += td->o.zone_size + td->o.zone_skip;
1513 * Wrap from the beginning, if we exceed the file size
1515 if (f->file_offset >= f->real_file_size)
1516 f->file_offset = get_start_offset(td, f);
1518 f->last_pos[ddir] = f->file_offset;
1519 td->io_skip_bytes += td->o.zone_skip;
1524 * zbd_adjust_ddir - Adjust an I/O direction for zonemode=zbd.
1526 * @td: FIO thread data.
1527 * @io_u: FIO I/O unit.
1528 * @ddir: I/O direction before adjustment.
1530 * Return adjusted I/O direction.
1532 enum fio_ddir zbd_adjust_ddir(struct thread_data *td, struct io_u *io_u,
1536 * In case read direction is chosen for the first random I/O, fio with
1537 * zonemode=zbd stops because no data can be read from zoned block
1538 * devices with all empty zones. Overwrite the first I/O direction as
1539 * write to make sure data to read exists.
1541 if (ddir != DDIR_READ || !td_rw(td))
1544 if (io_u->file->zbd_info->sectors_with_data ||
1545 td->o.read_beyond_wp)
1552 * zbd_adjust_block - adjust the offset and length as necessary for ZBD drives
1553 * @td: FIO thread data.
1554 * @io_u: FIO I/O unit.
1556 * Locking strategy: returns with z->mutex locked if and only if z refers
1557 * to a sequential zone and if io_u_accept is returned. z is the zone that
1558 * corresponds to io_u->offset at the end of this function.
1560 enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u)
1562 struct fio_file *f = io_u->file;
1563 uint32_t zone_idx_b;
1564 struct fio_zone_info *zb, *zl, *orig_zb;
1565 uint32_t orig_len = io_u->buflen;
1566 uint32_t min_bs = td->o.min_bs[io_u->ddir];
1574 assert(is_valid_offset(f, io_u->offset));
1575 assert(io_u->buflen);
1576 zone_idx_b = zbd_zone_idx(f, io_u->offset);
1577 zb = get_zone(f, zone_idx_b);
1581 /* Accept non-write I/Os for conventional zones. */
1582 if (io_u->ddir != DDIR_WRITE)
1585 * Make sure that writes to conventional zones
1586 * don't cross over to any sequential zones.
1588 if (!(zb + 1)->has_wp ||
1589 io_u->offset + io_u->buflen <= (zb + 1)->start)
1592 if (io_u->offset + min_bs > (zb + 1)->start) {
1594 "%s: off=%llu + min_bs=%u > next zone %llu\n",
1595 f->file_name, io_u->offset,
1596 min_bs, (unsigned long long) (zb + 1)->start);
1597 io_u->offset = zb->start + (zb + 1)->start - io_u->offset;
1598 new_len = min(io_u->buflen, (zb + 1)->start - io_u->offset);
1600 new_len = (zb + 1)->start - io_u->offset;
1602 io_u->buflen = new_len / min_bs * min_bs;
1607 * Accept the I/O offset for reads if reading beyond the write pointer
1610 if (zb->cond != ZBD_ZONE_COND_OFFLINE &&
1611 io_u->ddir == DDIR_READ && td->o.read_beyond_wp)
1614 zbd_check_swd(td, f);
1616 zone_lock(td, f, zb);
1618 switch (io_u->ddir) {
1620 if (td->runstate == TD_VERIFYING && td_write(td)) {
1621 zb = zbd_replay_write_order(td, io_u, zb);
1625 * Check that there is enough written data in the zone to do an
1626 * I/O of at least min_bs B. If there isn't, find a new zone for
1629 range = zb->cond != ZBD_ZONE_COND_OFFLINE ?
1630 zb->wp - zb->start : 0;
1631 if (range < min_bs ||
1632 ((!td_random(td)) && (io_u->offset + min_bs > zb->wp))) {
1634 zl = get_zone(f, f->max_zone);
1635 zb = zbd_find_zone(td, io_u, zb, zl);
1638 "%s: zbd_find_zone(%lld, %llu) failed\n",
1639 f->file_name, io_u->offset,
1644 * zbd_find_zone() returned a zone with a range of at
1647 range = zb->wp - zb->start;
1648 assert(range >= min_bs);
1651 io_u->offset = zb->start;
1654 * Make sure the I/O is within the zone valid data range while
1655 * maximizing the I/O size and preserving randomness.
1657 if (range <= io_u->buflen)
1658 io_u->offset = zb->start;
1659 else if (td_random(td))
1660 io_u->offset = zb->start +
1661 ((io_u->offset - orig_zb->start) %
1662 (range - io_u->buflen)) / min_bs * min_bs;
1664 * When zbd_find_zone() returns a conventional zone,
1665 * we can simply accept the new i/o offset here.
1670 * Make sure the I/O does not cross over the zone wp position.
1672 new_len = min((unsigned long long)io_u->buflen,
1673 (unsigned long long)(zb->wp - io_u->offset));
1674 new_len = new_len / min_bs * min_bs;
1675 if (new_len < io_u->buflen) {
1676 io_u->buflen = new_len;
1677 dprint(FD_IO, "Changed length from %u into %llu\n",
1678 orig_len, io_u->buflen);
1680 assert(zb->start <= io_u->offset);
1681 assert(io_u->offset + io_u->buflen <= zb->wp);
1684 if (io_u->buflen > f->zbd_info->zone_size) {
1685 td_verror(td, EINVAL, "I/O buflen exceeds zone size");
1687 "%s: I/O buflen %llu exceeds zone size %llu\n",
1688 f->file_name, io_u->buflen,
1689 (unsigned long long) f->zbd_info->zone_size);
1692 if (!zbd_open_zone(td, f, zone_idx_b)) {
1694 zb = zbd_convert_to_open_zone(td, io_u);
1696 dprint(FD_IO, "%s: can't convert to open zone",
1700 zone_idx_b = zbd_zone_nr(f, zb);
1702 /* Check whether the zone reset threshold has been exceeded */
1703 if (td->o.zrf.u.f) {
1704 if (f->zbd_info->wp_sectors_with_data >=
1705 f->io_size * td->o.zrt.u.f &&
1706 zbd_dec_and_reset_write_cnt(td, f)) {
1710 /* Reset the zone pointer if necessary */
1711 if (zb->reset_zone || zbd_zone_full(f, zb, min_bs)) {
1712 assert(td->o.verify == VERIFY_NONE);
1714 * Since previous write requests may have been submitted
1715 * asynchronously and since we will submit the zone
1716 * reset synchronously, wait until previously submitted
1717 * write requests have completed before issuing a
1722 if (zbd_reset_zone(td, f, zb) < 0)
1725 if (zb->capacity < min_bs) {
1726 td_verror(td, EINVAL, "ZCAP is less min_bs");
1727 log_err("zone capacity %llu smaller than minimum block size %d\n",
1728 (unsigned long long)zb->capacity,
1733 /* Make writes occur at the write pointer */
1734 assert(!zbd_zone_full(f, zb, min_bs));
1735 io_u->offset = zb->wp;
1736 if (!is_valid_offset(f, io_u->offset)) {
1737 td_verror(td, EINVAL, "invalid WP value");
1738 dprint(FD_ZBD, "%s: dropped request with offset %llu\n",
1739 f->file_name, io_u->offset);
1743 * Make sure that the buflen is a multiple of the minimal
1744 * block size. Give up if shrinking would make the request too
1747 new_len = min((unsigned long long)io_u->buflen,
1748 zbd_zone_capacity_end(zb) - io_u->offset);
1749 new_len = new_len / min_bs * min_bs;
1750 if (new_len == io_u->buflen)
1752 if (new_len >= min_bs) {
1753 io_u->buflen = new_len;
1754 dprint(FD_IO, "Changed length from %u into %llu\n",
1755 orig_len, io_u->buflen);
1758 td_verror(td, EIO, "zone remainder too small");
1759 log_err("zone remainder %lld smaller than min block size %d\n",
1760 (zbd_zone_capacity_end(zb) - io_u->offset), min_bs);
1766 case DDIR_SYNC_FILE_RANGE:
1777 assert(zb->cond != ZBD_ZONE_COND_OFFLINE);
1778 assert(!io_u->zbd_queue_io);
1779 assert(!io_u->zbd_put_io);
1780 io_u->zbd_queue_io = zbd_queue_io;
1781 io_u->zbd_put_io = zbd_put_io;
1783 * Since we return with the zone lock still held,
1784 * add an annotation to let Coverity know that it
1787 /* coverity[missing_unlock] */
1791 if (zb && zb->has_wp)
1796 /* Return a string with ZBD statistics */
1797 char *zbd_write_status(const struct thread_stat *ts)
1801 if (asprintf(&res, "; %llu zone resets", (unsigned long long) ts->nr_zone_resets) < 0)