diff mbox series

[3/6] io_uring: add io_op_defs 'def' pointer in req init and issue

Message ID 20220524213727.409630-4-axboe@kernel.dk (mailing list archive)
State New
Headers show
Series Misc cleanups | expand

Commit Message

Jens Axboe May 24, 2022, 9:37 p.m. UTC
Define and set it when appropriate, and use it consistently in the
function rather than using io_op_defs[opcode].

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 fs/io_uring.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Comments

Kanchan Joshi May 25, 2022, 6:41 a.m. UTC | #1
On Tue, May 24, 2022 at 03:37:24PM -0600, Jens Axboe wrote:
>Define and set it when appropriate, and use it consistently in the
>function rather than using io_op_defs[opcode].

seems you skipped doing this inside io_alloc_async_data() because
access is not that repetitive.

Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>
Jens Axboe May 25, 2022, 11:37 a.m. UTC | #2
On 5/25/22 12:41 AM, Kanchan Joshi wrote:
> On Tue, May 24, 2022 at 03:37:24PM -0600, Jens Axboe wrote:
>> Define and set it when appropriate, and use it consistently in the
>> function rather than using io_op_defs[opcode].
> 
> seems you skipped doing this inside io_alloc_async_data() because
> access is not that repetitive.

Right, and because it won't get impacted by abstracting out opcode
handlers.
diff mbox series

Patch

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 01a96fcdb7c6..d2c99176b11a 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8301,6 +8301,7 @@  static bool io_assign_file(struct io_kiocb *req, unsigned int issue_flags)
 
 static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
 {
+	const struct io_op_def *def = &io_op_defs[req->opcode];
 	const struct cred *creds = NULL;
 	int ret;
 
@@ -8310,7 +8311,7 @@  static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
 	if (unlikely((req->flags & REQ_F_CREDS) && req->creds != current_cred()))
 		creds = override_creds(req->creds);
 
-	if (!io_op_defs[req->opcode].audit_skip)
+	if (!def->audit_skip)
 		audit_uring_entry(req->opcode);
 
 	switch (req->opcode) {
@@ -8449,7 +8450,7 @@  static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
 		break;
 	}
 
-	if (!io_op_defs[req->opcode].audit_skip)
+	if (!def->audit_skip)
 		audit_uring_exit(!ret, ret);
 
 	if (creds)
@@ -8801,12 +8802,14 @@  static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 		       const struct io_uring_sqe *sqe)
 	__must_hold(&ctx->uring_lock)
 {
+	const struct io_op_def *def;
 	unsigned int sqe_flags;
 	int personality;
 	u8 opcode;
 
 	/* req is partially pre-initialised, see io_preinit_req() */
 	req->opcode = opcode = READ_ONCE(sqe->opcode);
+	def = &io_op_defs[opcode];
 	/* same numerical values with corresponding REQ_F_*, safe to copy */
 	req->flags = sqe_flags = READ_ONCE(sqe->flags);
 	req->cqe.user_data = READ_ONCE(sqe->user_data);
@@ -8823,7 +8826,7 @@  static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 		if (sqe_flags & ~SQE_VALID_FLAGS)
 			return -EINVAL;
 		if (sqe_flags & IOSQE_BUFFER_SELECT) {
-			if (!io_op_defs[opcode].buffer_select)
+			if (!def->buffer_select)
 				return -EOPNOTSUPP;
 			req->buf_index = READ_ONCE(sqe->buf_group);
 		}
@@ -8849,12 +8852,12 @@  static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 		}
 	}
 
-	if (!io_op_defs[opcode].ioprio && sqe->ioprio)
+	if (!def->ioprio && sqe->ioprio)
 		return -EINVAL;
-	if (!io_op_defs[opcode].iopoll && (ctx->flags & IORING_SETUP_IOPOLL))
+	if (!def->iopoll && (ctx->flags & IORING_SETUP_IOPOLL))
 		return -EINVAL;
 
-	if (io_op_defs[opcode].needs_file) {
+	if (def->needs_file) {
 		struct io_submit_state *state = &ctx->submit_state;
 
 		req->cqe.fd = READ_ONCE(sqe->fd);
@@ -8863,7 +8866,7 @@  static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 		 * Plug now if we have more than 2 IO left after this, and the
 		 * target is potentially a read/write to block based storage.
 		 */
-		if (state->need_plug && io_op_defs[opcode].plug) {
+		if (state->need_plug && def->plug) {
 			state->plug_started = true;
 			state->need_plug = false;
 			blk_start_plug_nr_ios(&state->plug, state->submit_nr);