Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: ublk: pass 'ublk_thread *' to more common helpers

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>

authored by

Ming Lei and committed by
Jens Axboe
92dda984 e0054835

+28 -29
+3 -3
tools/testing/selftests/ublk/fault_inject.c
··· 51 51 io_uring_prep_timeout(sqe, &ts, 1, 0); 52 52 sqe->user_data = build_user_data(tag, ublksrv_get_op(iod), 0, q->q_id, 1); 53 53 54 - ublk_queued_tgt_io(q, tag, 1); 54 + ublk_queued_tgt_io(t, q, tag, 1); 55 55 56 56 return 0; 57 57 } ··· 66 66 if (cqe->res != -ETIME) 67 67 ublk_err("%s: unexpected cqe res %d\n", __func__, cqe->res); 68 68 69 - if (ublk_completed_tgt_io(q, tag)) 70 - ublk_complete_io(q, tag, iod->nr_sectors << 9); 69 + if (ublk_completed_tgt_io(t, q, tag)) 70 + ublk_complete_io(t, q, tag, iod->nr_sectors << 9); 71 71 else 72 72 ublk_err("%s: io not complete after 1 cqe\n", __func__); 73 73 }
+3 -3
tools/testing/selftests/ublk/file_backed.c
··· 107 107 { 108 108 int queued = loop_queue_tgt_io(t, q, tag); 109 109 110 - ublk_queued_tgt_io(q, tag, queued); 110 + ublk_queued_tgt_io(t, q, tag, queued); 111 111 return 0; 112 112 } 113 113 ··· 130 130 if (op == ublk_cmd_op_nr(UBLK_U_IO_REGISTER_IO_BUF)) 131 131 io->tgt_ios += 1; 132 132 133 - if (ublk_completed_tgt_io(q, tag)) 134 - ublk_complete_io(q, tag, io->result); 133 + if (ublk_completed_tgt_io(t, q, tag)) 134 + ublk_complete_io(t, q, tag, io->result); 135 135 } 136 136 137 137 static int ublk_loop_tgt_init(const struct dev_ctx *ctx, struct ublk_dev *dev)
+4 -7
tools/testing/selftests/ublk/kublk.c
··· 589 589 sqe->addr = ublk_auto_buf_reg_to_sqe_addr(&buf); 590 590 } 591 591 592 - int ublk_queue_io_cmd(struct ublk_io *io) 592 + int ublk_queue_io_cmd(struct ublk_thread *t, struct ublk_io *io) 593 593 { 594 - struct ublk_thread *t = io->t; 595 594 struct ublk_queue *q = ublk_io_to_queue(io); 596 595 struct ublksrv_io_cmd *cmd; 597 596 struct io_uring_sqe *sqe[1]; ··· 684 685 int tag = i % dinfo->queue_depth; 685 686 q = &t->dev->q[q_id]; 686 687 io = &q->ios[tag]; 687 - io->t = t; 688 688 io->buf_index = j++; 689 - ublk_queue_io_cmd(io); 689 + ublk_queue_io_cmd(t, io); 690 690 } 691 691 } else { 692 692 /* ··· 695 697 struct ublk_queue *q = &t->dev->q[t->idx]; 696 698 for (i = 0; i < q->q_depth; i++) { 697 699 io = &q->ios[i]; 698 - io->t = t; 699 700 io->buf_index = i; 700 - ublk_queue_io_cmd(io); 701 + ublk_queue_io_cmd(t, io); 701 702 } 702 703 } 703 704 } ··· 767 770 q->tgt_ops->queue_io(t, q, tag); 768 771 } else if (cqe->res == UBLK_IO_RES_NEED_GET_DATA) { 769 772 io->flags |= UBLKSRV_NEED_GET_DATA | UBLKSRV_IO_FREE; 770 - ublk_queue_io_cmd(io); 773 + ublk_queue_io_cmd(t, io); 771 774 } else { 772 775 /* 773 776 * COMMIT_REQ will be completed immediately since no fetching
+11 -9
tools/testing/selftests/ublk/kublk.h
··· 136 136 unsigned short buf_index; 137 137 unsigned short tgt_ios; 138 138 void *private_data; 139 - struct ublk_thread *t; 140 139 }; 141 140 142 141 struct ublk_tgt_ops { ··· 231 232 232 233 233 234 extern unsigned int ublk_dbg_mask; 234 - extern int ublk_queue_io_cmd(struct ublk_io *io); 235 + extern int ublk_queue_io_cmd(struct ublk_thread *t, struct ublk_io *io); 235 236 236 237 237 238 static inline int ublk_io_auto_zc_fallback(const struct ublksrv_io_desc *iod) ··· 401 402 return &q->ios[tag]; 402 403 } 403 404 404 - static inline int ublk_complete_io(struct ublk_queue *q, unsigned tag, int res) 405 + static inline int ublk_complete_io(struct ublk_thread *t, struct ublk_queue *q, 406 + unsigned tag, int res) 405 407 { 406 408 struct ublk_io *io = &q->ios[tag]; 407 409 408 410 ublk_mark_io_done(io, res); 409 411 410 - return ublk_queue_io_cmd(io); 412 + return ublk_queue_io_cmd(t, io); 411 413 } 412 414 413 - static inline void ublk_queued_tgt_io(struct ublk_queue *q, unsigned tag, int queued) 415 + static inline void ublk_queued_tgt_io(struct ublk_thread *t, struct ublk_queue *q, 416 + unsigned tag, int queued) 414 417 { 415 418 if (queued < 0) 416 - ublk_complete_io(q, tag, queued); 419 + ublk_complete_io(t, q, tag, queued); 417 420 else { 418 421 struct ublk_io *io = ublk_get_io(q, tag); 419 422 420 - io->t->io_inflight += queued; 423 + t->io_inflight += queued; 421 424 io->tgt_ios = queued; 422 425 io->result = 0; 423 426 } 424 427 } 425 428 426 - static inline int ublk_completed_tgt_io(struct ublk_queue *q, unsigned tag) 429 + static inline int ublk_completed_tgt_io(struct ublk_thread *t, 430 + struct ublk_queue *q, unsigned tag) 427 431 { 428 432 struct ublk_io *io = ublk_get_io(q, tag); 429 433 430 - io->t->io_inflight--; 434 + t->io_inflight--; 431 435 432 436 return --io->tgt_ios == 0; 433 437 }
+4 -4
tools/testing/selftests/ublk/null.c
··· 108 108 if (op == ublk_cmd_op_nr(UBLK_U_IO_REGISTER_IO_BUF)) 109 109 io->tgt_ios += 1; 110 110 111 - if (ublk_completed_tgt_io(q, tag)) 112 - ublk_complete_io(q, tag, io->result); 111 + if (ublk_completed_tgt_io(t, q, tag)) 112 + ublk_complete_io(t, q, tag, io->result); 113 113 } 114 114 115 115 static int ublk_null_queue_io(struct ublk_thread *t, struct ublk_queue *q, ··· 125 125 else if (zc) 126 126 queued = null_queue_zc_io(t, q, tag); 127 127 else { 128 - ublk_complete_io(q, tag, iod->nr_sectors << 9); 128 + ublk_complete_io(t, q, tag, iod->nr_sectors << 9); 129 129 return 0; 130 130 } 131 - ublk_queued_tgt_io(q, tag, queued); 131 + ublk_queued_tgt_io(t, q, tag, queued); 132 132 return 0; 133 133 } 134 134
+3 -3
tools/testing/selftests/ublk/stripe.c
··· 226 226 { 227 227 int queued = stripe_queue_tgt_io(t, q, tag); 228 228 229 - ublk_queued_tgt_io(q, tag, queued); 229 + ublk_queued_tgt_io(t, q, tag, queued); 230 230 return 0; 231 231 } 232 232 ··· 262 262 } 263 263 } 264 264 265 - if (ublk_completed_tgt_io(q, tag)) { 265 + if (ublk_completed_tgt_io(t, q, tag)) { 266 266 int res = io->result; 267 267 268 268 if (!res) 269 269 res = iod->nr_sectors << 9; 270 270 271 - ublk_complete_io(q, tag, res); 271 + ublk_complete_io(t, q, tag, res); 272 272 273 273 free_stripe_array(io->private_data); 274 274 io->private_data = NULL;