t/io_uring: abstract out init_new_io() helper
authorJens Axboe <axboe@kernel.dk>
Tue, 14 Mar 2023 20:03:32 +0000 (14:03 -0600)
committerJens Axboe <axboe@kernel.dk>
Tue, 14 Mar 2023 20:03:32 +0000 (14:03 -0600)
We do this in 4 different spots, put it in a helper.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
t/io_uring.c

index 17d1d2635677a7c2255d41342fb71af428102e56..504f8ce9f1b14a40bc37e19cd0f318e956708913 100644 (file)
@@ -545,16 +545,10 @@ static unsigned long long get_offset(struct submitter *s, struct file *f)
        return offset;
 }
 
-static void init_io(struct submitter *s, unsigned index)
+static struct file *init_new_io(struct submitter *s)
 {
-       struct io_uring_sqe *sqe = &s->sqes[index];
        struct file *f;
 
-       if (do_nop) {
-               sqe->opcode = IORING_OP_NOP;
-               return;
-       }
-
        if (s->nr_files == 1) {
                f = &s->files[0];
        } else {
@@ -566,7 +560,22 @@ static void init_io(struct submitter *s, unsigned index)
                        f = &s->files[s->cur_file];
                }
        }
+
        f->pending_ios++;
+       return f;
+}
+
+static void init_io(struct submitter *s, unsigned index)
+{
+       struct io_uring_sqe *sqe = &s->sqes[index];
+       struct file *f;
+
+       if (do_nop) {
+               sqe->opcode = IORING_OP_NOP;
+               return;
+       }
+
+       f = init_new_io(s);
 
        if (register_files) {
                sqe->flags = IOSQE_FIXED_FILE;
@@ -607,18 +616,7 @@ static void init_io_pt(struct submitter *s, unsigned index)
        unsigned long long slba;
        unsigned long long nlb;
 
-       if (s->nr_files == 1) {
-               f = &s->files[0];
-       } else {
-               f = &s->files[s->cur_file];
-               if (f->pending_ios >= file_depth(s)) {
-                       s->cur_file++;
-                       if (s->cur_file == s->nr_files)
-                               s->cur_file = 0;
-                       f = &s->files[s->cur_file];
-               }
-       }
-       f->pending_ios++;
+       f = init_new_io(s);
 
        offset = get_offset(s, f);
 
@@ -1115,18 +1113,7 @@ static int prep_more_ios_aio(struct submitter *s, int max_ios, struct iocb *iocb
        while (index < max_ios) {
                struct iocb *iocb = &iocbs[index];
 
-               if (s->nr_files == 1) {
-                       f = &s->files[0];
-               } else {
-                       f = &s->files[s->cur_file];
-                       if (f->pending_ios >= file_depth(s)) {
-                               s->cur_file++;
-                               if (s->cur_file == s->nr_files)
-                                       s->cur_file = 0;
-                               f = &s->files[s->cur_file];
-                       }
-               }
-               f->pending_ios++;
+               f = init_new_io(s);
 
                io_prep_pread(iocb, f->real_fd, s->iovecs[index].iov_base,
                                s->iovecs[index].iov_len, get_offset(s, f));
@@ -1413,18 +1400,7 @@ static void *submitter_sync_fn(void *data)
                uint64_t offset;
                struct file *f;
 
-               if (s->nr_files == 1) {
-                       f = &s->files[0];
-               } else {
-                       f = &s->files[s->cur_file];
-                       if (f->pending_ios >= file_depth(s)) {
-                               s->cur_file++;
-                               if (s->cur_file == s->nr_files)
-                                       s->cur_file = 0;
-                               f = &s->files[s->cur_file];
-                       }
-               }
-               f->pending_ios++;
+               f = init_new_io(s);
 
 #ifdef ARCH_HAVE_CPU_CLOCK
                if (stats)