Merge branch 'Verify_Bad_Hdr_Rand_Seed_Mult_Workload_Iterations_Non_Repeating_Seed...
authorJens Axboe <axboe@kernel.dk>
Tue, 21 Feb 2023 16:37:09 +0000 (09:37 -0700)
committerJens Axboe <axboe@kernel.dk>
Tue, 21 Feb 2023 16:37:09 +0000 (09:37 -0700)
* 'Verify_Bad_Hdr_Rand_Seed_Mult_Workload_Iterations_Non_Repeating_Seed' of https://github.com/horshack-dpreview/fio:
  Bad header rand_seed with time_based or loops with randrepeat=0 verify

1  2 
backend.c

diff --combined backend.c
index cb1fbf424136d03de69774d0b36112c5789857a7,9ea688fb1f0ca9e7e67cc10479df6d3b9f68e25a..f494c831558cb5054534e2b6b165f5af2ff16f99
+++ b/backend.c
@@@ -637,15 -637,6 +637,6 @@@ static void do_verify(struct thread_dat
        if (td->error)
                return;
  
-       /*
-        * verify_state needs to be reset before verification
-        * proceeds so that expected random seeds match actual
-        * random seeds in headers. The main loop will reset
-        * all random number generators if randrepeat is set.
-        */
-       if (!td->o.rand_repeatable)
-               td_fill_verify_state_seed(td);
        td_set_runstate(td, TD_VERIFYING);
  
        io_u = NULL;
@@@ -866,7 -857,6 +857,7 @@@ static void handle_thinktime(struct thr
                             struct timespec *time)
  {
        unsigned long long b;
 +      unsigned long long runtime_left;
        uint64_t total;
        int left;
        struct timespec now;
        if (td->o.thinktime_iotime) {
                fio_gettime(&now, NULL);
                if (utime_since(&td->last_thinktime, &now)
 -                  >= td->o.thinktime_iotime + td->o.thinktime) {
 +                  >= td->o.thinktime_iotime) {
                        stall = true;
                } else if (!fio_option_is_set(&td->o, thinktime_blocks)) {
                        /*
  
        io_u_quiesce(td);
  
 +      left = td->o.thinktime_spin;
 +      if (td->o.timeout) {
 +              runtime_left = td->o.timeout - utime_since_now(&td->epoch);
 +              if (runtime_left < (unsigned long long)left)
 +                      left = runtime_left;
 +      }
 +
        total = 0;
 -      if (td->o.thinktime_spin)
 -              total = usec_spin(td->o.thinktime_spin);
 +      if (left)
 +              total = usec_spin(left);
  
        left = td->o.thinktime - total;
 +      if (td->o.timeout) {
 +              runtime_left = td->o.timeout - utime_since_now(&td->epoch);
 +              if (runtime_left < (unsigned long long)left)
 +                      left = runtime_left;
 +      }
 +
        if (left)
                total += usec_sleep(td, left);
  
                fio_gettime(time, NULL);
  
        td->last_thinktime_blocks = b;
 -      if (td->o.thinktime_iotime)
 +      if (td->o.thinktime_iotime) {
 +              fio_gettime(&now, NULL);
                td->last_thinktime = now;
 +      }
  }
  
  /*
@@@ -1349,7 -1324,7 +1340,7 @@@ int init_io_u_buffers(struct thread_dat
         * overflow later. this adjustment may be too much if we get
         * lucky and the allocator gives us an aligned address.
         */
 -      if (td->o.odirect || td->o.mem_align || td->o.oatomic ||
 +      if (td->o.odirect || td->o.mem_align ||
            td_ioengine_flagged(td, FIO_RAWIO))
                td->orig_buffer_size += page_mask + td->o.mem_align;
  
        if (data_xfer && allocate_io_mem(td))
                return 1;
  
 -      if (td->o.odirect || td->o.mem_align || td->o.oatomic ||
 +      if (td->o.odirect || td->o.mem_align ||
            td_ioengine_flagged(td, FIO_RAWIO))
                p = PTR_ALIGN(td->orig_buffer, page_mask) + td->o.mem_align;
        else
@@@ -1894,8 -1869,12 +1885,12 @@@ static void *thread_main(void *data
                if (td->o.verify_only && td_write(td))
                        verify_bytes = do_dry_run(td);
                else {
+                       if (!td->o.rand_repeatable)
+                               /* save verify rand state to replay hdr seeds later at verify */
+                               frand_copy(&td->verify_state_last_do_io, &td->verify_state);
                        do_io(td, bytes_done);
+                       if (!td->o.rand_repeatable)
+                               frand_copy(&td->verify_state, &td->verify_state_last_do_io);
                        if (!ddir_rw_sum(bytes_done)) {
                                fio_mark_td_terminate(td);
                                verify_bytes = 0;