]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: ublk: pass 'ublk_thread *' to more common helpers
authorMing Lei <ming.lei@redhat.com>
Sun, 13 Jul 2025 14:34:08 +0000 (22:34 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 15 Jul 2025 14:04:17 +0000 (08:04 -0600)
Pass 'ublk_thread *' to more common helpers, then we can avoid to store
this reference into 'struct ublk_io'.

Prepare for supporting to handle IO via different task context.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20250713143415.2857561-14-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
tools/testing/selftests/ublk/fault_inject.c
tools/testing/selftests/ublk/file_backed.c
tools/testing/selftests/ublk/kublk.c
tools/testing/selftests/ublk/kublk.h
tools/testing/selftests/ublk/null.c
tools/testing/selftests/ublk/stripe.c

index b4e9355e0eabfcbb54a40267d3d88b805c108ca2..b227bd78b25281f27a6f9bcbbc6260df13cdba78 100644 (file)
@@ -51,7 +51,7 @@ static int ublk_fault_inject_queue_io(struct ublk_thread *t,
        io_uring_prep_timeout(sqe, &ts, 1, 0);
        sqe->user_data = build_user_data(tag, ublksrv_get_op(iod), 0, q->q_id, 1);
 
-       ublk_queued_tgt_io(q, tag, 1);
+       ublk_queued_tgt_io(t, q, tag, 1);
 
        return 0;
 }
@@ -66,8 +66,8 @@ static void ublk_fault_inject_tgt_io_done(struct ublk_thread *t,
        if (cqe->res != -ETIME)
                ublk_err("%s: unexpected cqe res %d\n", __func__, cqe->res);
 
-       if (ublk_completed_tgt_io(q, tag))
-               ublk_complete_io(q, tag, iod->nr_sectors << 9);
+       if (ublk_completed_tgt_io(t, q, tag))
+               ublk_complete_io(t, q, tag, iod->nr_sectors << 9);
        else
                ublk_err("%s: io not complete after 1 cqe\n", __func__);
 }
index eeac7af2230f0b9a855b199cbd0353dad999ae39..2d93ac860bd59036bcdcfb623f98d7f7f5b150ec 100644 (file)
@@ -107,7 +107,7 @@ static int ublk_loop_queue_io(struct ublk_thread *t, struct ublk_queue *q,
 {
        int queued = loop_queue_tgt_io(t, q, tag);
 
-       ublk_queued_tgt_io(q, tag, queued);
+       ublk_queued_tgt_io(t, q, tag, queued);
        return 0;
 }
 
@@ -130,8 +130,8 @@ static void ublk_loop_io_done(struct ublk_thread *t, struct ublk_queue *q,
        if (op == ublk_cmd_op_nr(UBLK_U_IO_REGISTER_IO_BUF))
                io->tgt_ios += 1;
 
-       if (ublk_completed_tgt_io(q, tag))
-               ublk_complete_io(q, tag, io->result);
+       if (ublk_completed_tgt_io(t, q, tag))
+               ublk_complete_io(t, q, tag, io->result);
 }
 
 static int ublk_loop_tgt_init(const struct dev_ctx *ctx, struct ublk_dev *dev)
index 180b6da08eab4a9f3715564a83f9e00b3c31b224..944e0806ba05be2872175b0f6c2e2e0154c26e18 100644 (file)
@@ -589,9 +589,8 @@ static void ublk_set_auto_buf_reg(const struct ublk_queue *q,
        sqe->addr = ublk_auto_buf_reg_to_sqe_addr(&buf);
 }
 
-int ublk_queue_io_cmd(struct ublk_io *io)
+int ublk_queue_io_cmd(struct ublk_thread *t, struct ublk_io *io)
 {
-       struct ublk_thread *t = io->t;
        struct ublk_queue *q = ublk_io_to_queue(io);
        struct ublksrv_io_cmd *cmd;
        struct io_uring_sqe *sqe[1];
@@ -685,9 +684,8 @@ static void ublk_submit_fetch_commands(struct ublk_thread *t)
                        int tag = i % dinfo->queue_depth;
                        q = &t->dev->q[q_id];
                        io = &q->ios[tag];
-                       io->t = t;
                        io->buf_index = j++;
-                       ublk_queue_io_cmd(io);
+                       ublk_queue_io_cmd(t, io);
                }
        } else {
                /*
@@ -697,9 +695,8 @@ static void ublk_submit_fetch_commands(struct ublk_thread *t)
                struct ublk_queue *q = &t->dev->q[t->idx];
                for (i = 0; i < q->q_depth; i++) {
                        io = &q->ios[i];
-                       io->t = t;
                        io->buf_index = i;
-                       ublk_queue_io_cmd(io);
+                       ublk_queue_io_cmd(t, io);
                }
        }
 }
@@ -770,7 +767,7 @@ static void ublk_handle_cqe(struct ublk_thread *t,
                        q->tgt_ops->queue_io(t, q, tag);
        } else if (cqe->res == UBLK_IO_RES_NEED_GET_DATA) {
                io->flags |= UBLKSRV_NEED_GET_DATA | UBLKSRV_IO_FREE;
-               ublk_queue_io_cmd(io);
+               ublk_queue_io_cmd(t, io);
        } else {
                /*
                 * COMMIT_REQ will be completed immediately since no fetching
index 91e0286c5ca6edd1179cbfc6a9eeea7d395e2b33..a4049984b0551984acc61c79c69c20350a0fe3c2 100644 (file)
@@ -136,7 +136,6 @@ struct ublk_io {
        unsigned short buf_index;
        unsigned short tgt_ios;
        void *private_data;
-       struct ublk_thread *t;
 };
 
 struct ublk_tgt_ops {
@@ -232,7 +231,7 @@ struct ublk_dev {
 
 
 extern unsigned int ublk_dbg_mask;
-extern int ublk_queue_io_cmd(struct ublk_io *io);
+extern int ublk_queue_io_cmd(struct ublk_thread *t, struct ublk_io *io);
 
 
 static inline int ublk_io_auto_zc_fallback(const struct ublksrv_io_desc *iod)
@@ -402,33 +401,36 @@ static inline struct ublk_io *ublk_get_io(struct ublk_queue *q, unsigned tag)
        return &q->ios[tag];
 }
 
-static inline int ublk_complete_io(struct ublk_queue *q, unsigned tag, int res)
+static inline int ublk_complete_io(struct ublk_thread *t, struct ublk_queue *q,
+                                  unsigned tag, int res)
 {
        struct ublk_io *io = &q->ios[tag];
 
        ublk_mark_io_done(io, res);
 
-       return ublk_queue_io_cmd(io);
+       return ublk_queue_io_cmd(t, io);
 }
 
-static inline void ublk_queued_tgt_io(struct ublk_queue *q, unsigned tag, int queued)
+static inline void ublk_queued_tgt_io(struct ublk_thread *t, struct ublk_queue *q,
+                                     unsigned tag, int queued)
 {
        if (queued < 0)
-               ublk_complete_io(q, tag, queued);
+               ublk_complete_io(t, q, tag, queued);
        else {
                struct ublk_io *io = ublk_get_io(q, tag);
 
-               io->t->io_inflight += queued;
+               t->io_inflight += queued;
                io->tgt_ios = queued;
                io->result = 0;
        }
 }
 
-static inline int ublk_completed_tgt_io(struct ublk_queue *q, unsigned tag)
+static inline int ublk_completed_tgt_io(struct ublk_thread *t,
+                                       struct ublk_queue *q, unsigned tag)
 {
        struct ublk_io *io = ublk_get_io(q, tag);
 
-       io->t->io_inflight--;
+       t->io_inflight--;
 
        return --io->tgt_ios == 0;
 }
index e29a005fc1ccb540d1a43becbc27b656eb6e0a69..452dcc369c8b519c76925c5587c03f30983733ae 100644 (file)
@@ -108,8 +108,8 @@ static void ublk_null_io_done(struct ublk_thread *t, struct ublk_queue *q,
        if (op == ublk_cmd_op_nr(UBLK_U_IO_REGISTER_IO_BUF))
                io->tgt_ios += 1;
 
-       if (ublk_completed_tgt_io(q, tag))
-               ublk_complete_io(q, tag, io->result);
+       if (ublk_completed_tgt_io(t, q, tag))
+               ublk_complete_io(t, q, tag, io->result);
 }
 
 static int ublk_null_queue_io(struct ublk_thread *t, struct ublk_queue *q,
@@ -125,10 +125,10 @@ static int ublk_null_queue_io(struct ublk_thread *t, struct ublk_queue *q,
        else if (zc)
                queued = null_queue_zc_io(t, q, tag);
        else {
-               ublk_complete_io(q, tag, iod->nr_sectors << 9);
+               ublk_complete_io(t, q, tag, iod->nr_sectors << 9);
                return 0;
        }
-       ublk_queued_tgt_io(q, tag, queued);
+       ublk_queued_tgt_io(t, q, tag, queued);
        return 0;
 }
 
index 462fab7492ce1f40bfb871a33900d27016f6be02..1fb9b7cc281b0baa747f8d6d9a4a833834a58f26 100644 (file)
@@ -226,7 +226,7 @@ static int ublk_stripe_queue_io(struct ublk_thread *t, struct ublk_queue *q,
 {
        int queued = stripe_queue_tgt_io(t, q, tag);
 
-       ublk_queued_tgt_io(q, tag, queued);
+       ublk_queued_tgt_io(t, q, tag, queued);
        return 0;
 }
 
@@ -262,13 +262,13 @@ static void ublk_stripe_io_done(struct ublk_thread *t, struct ublk_queue *q,
                }
        }
 
-       if (ublk_completed_tgt_io(q, tag)) {
+       if (ublk_completed_tgt_io(t, q, tag)) {
                int res = io->result;
 
                if (!res)
                        res = iod->nr_sectors << 9;
 
-               ublk_complete_io(q, tag, res);
+               ublk_complete_io(t, q, tag, res);
 
                free_stripe_array(io->private_data);
                io->private_data = NULL;