- if ((io_u->offset + io_u->buflen) >> 9 > zb->wp) {
- dprint(FD_ZBD, "%s: %lld + %lld > %" PRIu64 "\n",
- f->file_name, io_u->offset, io_u->buflen,
- zb->wp);
- goto eof;
+ /*
+ * Make sure the I/O is within the zone valid data range while
+ * maximizing the I/O size and preserving randomness.
+ */
+ if (range <= io_u->buflen)
+ io_u->offset = zb->start << 9;
+ else if (td_random(td))
+ io_u->offset = (zb->start << 9) +
+ ((io_u->offset - (orig_zb->start << 9)) %
+ (range - io_u->buflen)) / min_bs * min_bs;
+ /*
+ * Make sure the I/O does not cross over the zone wp position.
+ */
+ new_len = min((unsigned long long)io_u->buflen,
+ (unsigned long long)(zb->wp << 9) - io_u->offset);
+ new_len = new_len / min_bs * min_bs;
+ if (new_len < io_u->buflen) {
+ io_u->buflen = new_len;
+ dprint(FD_IO, "Changed length from %u into %llu\n",
+ orig_len, io_u->buflen);