Add exceeds_number_ios() helper
authorJens Axboe <axboe@fb.com>
Wed, 12 Mar 2014 02:16:38 +0000 (20:16 -0600)
committerJens Axboe <axboe@fb.com>
Wed, 12 Mar 2014 02:16:38 +0000 (20:16 -0600)
Commit 26251d8d open-coded the logic in two places, collapse
that into one function.

Signed-off-by: Jens Axboe <axboe@fb.com>
backend.c

index bab202662ca5356ec3b6993ee2af76922565d95d..1ff8b3f6e298adfa7f756453edf2cff1656b91f8 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -623,9 +623,21 @@ reap:
        dprint(FD_VERIFY, "exiting loop\n");
 }
 
+static unsigned int exceeds_number_ios(struct thread_data *td)
+{
+       unsigned long long number_ios;
+
+       if (!td->o.number_ios)
+               return 0;
+
+       number_ios = ddir_rw_sum(td->this_io_blocks);
+       number_ios += td->io_u_queued + td->io_u_in_flight;
+
+       return number_ios >= td->o.number_ios;
+}
+
 static int io_bytes_exceeded(struct thread_data *td)
 {
-       unsigned long long number_ios = 0;
        unsigned long long bytes;
 
        if (td_rw(td))
@@ -637,13 +649,7 @@ static int io_bytes_exceeded(struct thread_data *td)
        else
                bytes = td->this_io_bytes[DDIR_TRIM];
 
-       if (td->o.number_ios) {
-               number_ios = ddir_rw_sum(td->this_io_blocks);
-               number_ios += td->io_u_queued + td->io_u_in_flight;
-       }
-
-       return bytes >= td->o.size ||
-               (number_ios && number_ios >= td->o.number_ios);
+       return bytes >= td->o.size || exceeds_number_ios(td);
 }
 
 /*
@@ -1134,14 +1140,8 @@ static int keep_running(struct thread_data *td)
                td->o.loops--;
                return 1;
        }
-
-       if (td->o.number_ios) {
-               unsigned long long number_ios = ddir_rw_sum(td->this_io_blocks);
-
-               number_ios += td->io_u_queued + td->io_u_in_flight;
-               if (number_ios >= td->o.number_ios)
-                       return 0;
-       }
+       if (exceeds_number_ios(td))
+               return 0;
 
        if (td->o.size != -1ULL && ddir_rw_sum(td->io_bytes) < td->o.size) {
                uint64_t diff;