zbd: initialize min_zone and max_zone for all zone types
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Wed, 27 Jan 2021 04:19:20 +0000 (13:19 +0900)
committerJens Axboe <axboe@kernel.dk>
Fri, 29 Jan 2021 15:14:00 +0000 (08:14 -0700)
The function zbd_verify_sizes() checks if the given I/O range includes
write pointer zones. When all zones in the I/O range are conventional,
it skips checks for size options and leaves min_zone and max_zone in
struct fio_file with zero values. These uninitialized min_zone and
max_zone fields trigger unexpected behaviors such as unset
sectors_with_data.

Fix this by moving min_zone and max_zone set up from zbd_verify_sizes()
to zbd_setup_files(). This allows for setting up the values regardless
of zone types in I/O range.

Bypass the assertion to ensure that max_zone is larger than min_zone if
all zones in the I/O range are conventional. In this case, io_size
can be smaller than zone size and, consequently, min_zone may become
the same as max_zone.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Signed-off-by: Dmitry Fomichev <dmitry.fomichev@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
zbd.c

diff --git a/zbd.c b/zbd.c
index e3ad11249ce7e4239c92d92242d2994e242b2405..cf2abc3e2361ad7c0e168a08f7b73b2655d9e7f7 100644 (file)
--- a/zbd.c
+++ b/zbd.c
@@ -324,10 +324,6 @@ static bool zbd_verify_sizes(void)
                                         (unsigned long long) new_end - f->file_offset);
                                f->io_size = new_end - f->file_offset;
                        }
-
-                       f->min_zone = zbd_zone_idx(f, f->file_offset);
-                       f->max_zone = zbd_zone_idx(f, f->file_offset + f->io_size);
-                       assert(f->min_zone < f->max_zone);
                }
        }
 
@@ -680,6 +676,18 @@ int zbd_setup_files(struct thread_data *td)
                if (!zbd)
                        continue;
 
+               f->min_zone = zbd_zone_idx(f, f->file_offset);
+               f->max_zone = zbd_zone_idx(f, f->file_offset + f->io_size);
+
+               /*
+                * When all zones in the I/O range are conventional, io_size
+                * can be smaller than zone size, making min_zone the same
+                * as max_zone. This is why the assert below needs to be made
+                * conditional.
+                */
+               if (zbd_is_seq_job(f))
+                       assert(f->min_zone < f->max_zone);
+
                zbd->max_open_zones = zbd->max_open_zones ?: ZBD_MAX_OPEN_ZONES;
 
                if (td->o.max_open_zones > 0 &&