zbd: add zbd_zone_remainder() helper function
[fio.git] / zbd.c
diff --git a/zbd.c b/zbd.c
index b1fd6b4bb0ae23cda7dba13a3c0bf3577139600f..26a6404def08f4788b7a62f7c0ebb3828a8a145b 100644 (file)
--- a/zbd.c
+++ b/zbd.c
@@ -70,6 +70,19 @@ static inline uint64_t zbd_zone_capacity_end(const struct fio_zone_info *z)
        return z->start + z->capacity;
 }
 
+/**
+ * zbd_zone_remainder - Return the number of bytes that are still available for
+ *                      writing before the zone gets full
+ * @z: zone info pointer.
+ */
+static inline uint64_t zbd_zone_remainder(struct fio_zone_info *z)
+{
+       if (z->wp >= zbd_zone_capacity_end(z))
+               return 0;
+
+       return zbd_zone_capacity_end(z) - z->wp;
+}
+
 /**
  * zbd_zone_full - verify whether a minimum number of bytes remain in a zone
  * @f: file pointer.
@@ -83,8 +96,7 @@ static bool zbd_zone_full(const struct fio_file *f, struct fio_zone_info *z,
 {
        assert((required & 511) == 0);
 
-       return z->has_wp &&
-               z->wp + required > zbd_zone_capacity_end(z);
+       return z->has_wp && required > zbd_zone_remainder(z);
 }
 
 static void zone_lock(struct thread_data *td, const struct fio_file *f,
@@ -440,7 +452,7 @@ static bool zbd_open_zone(struct thread_data *td, const struct fio_file *f,
                 * already in-flight, handle it as a full zone instead of an
                 * open zone.
                 */
-               if (z->wp >= zbd_zone_capacity_end(z))
+               if (!zbd_zone_remainder(z))
                        res = false;
                goto out;
        }
@@ -466,7 +478,7 @@ out:
        return res;
 }
 
-/* Verify whether direct I/O is used for all host-managed zoned drives. */
+/* Verify whether direct I/O is used for all host-managed zoned block drives. */
 static bool zbd_using_direct_io(void)
 {
        struct thread_data *td;
@@ -477,7 +489,7 @@ static bool zbd_using_direct_io(void)
                if (td->o.odirect || !(td->o.td_ddir & TD_DDIR_WRITE))
                        continue;
                for_each_file(td, f, j) {
-                       if (f->zbd_info &&
+                       if (f->zbd_info && f->filetype == FIO_TYPE_BLOCK &&
                            f->zbd_info->model == ZBD_HOST_MANAGED)
                                return false;
                }
@@ -1368,7 +1380,7 @@ found_candidate_zone:
        /* Both z->mutex and zbdi->mutex are held. */
 
 examine_zone:
-       if (z->wp + min_bs <= zbd_zone_capacity_end(z)) {
+       if (zbd_zone_remainder(z) >= min_bs) {
                pthread_mutex_unlock(&zbdi->mutex);
                goto out;
        }
@@ -1433,7 +1445,7 @@ retry:
                z = zbd_get_zone(f, zone_idx);
 
                zone_lock(td, f, z);
-               if (z->wp + min_bs <= zbd_zone_capacity_end(z))
+               if (zbd_zone_remainder(z) >= min_bs)
                        goto out;
                pthread_mutex_lock(&zbdi->mutex);
        }