All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 14/14] io_uring/rsrc: add io_reset_rsrc_node() helper
Date: Tue, 29 Oct 2024 09:16:43 -0600	[thread overview]
Message-ID: <20241029152249.667290-15-axboe@kernel.dk> (raw)
In-Reply-To: <20241029152249.667290-1-axboe@kernel.dk>

Puts and reset an existing node in a slot, if one exists. Returns true
if a node was there, false if not. This helps cleanup some of the code
that does a lookup just to clear an existing node.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/filetable.c | 10 +++-------
 io_uring/rsrc.c      | 12 +++---------
 io_uring/rsrc.h      | 11 +++++++++++
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/io_uring/filetable.c b/io_uring/filetable.c
index 1f22f183cdeb..717d5b806781 100644
--- a/io_uring/filetable.c
+++ b/io_uring/filetable.c
@@ -58,7 +58,7 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,
 				 u32 slot_index)
 	__must_hold(&req->ctx->uring_lock)
 {
-	struct io_rsrc_node *node, *old_node;
+	struct io_rsrc_node *node;
 
 	if (io_is_uring_fops(file))
 		return -EBADF;
@@ -71,10 +71,7 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,
 	if (IS_ERR(node))
 		return -ENOMEM;
 
-	old_node = io_rsrc_node_lookup(&ctx->file_table.data, slot_index);
-	if (old_node)
-		io_put_rsrc_node(old_node);
-	else
+	if (!io_reset_rsrc_node(&ctx->file_table.data, slot_index))
 		io_file_bitmap_set(&ctx->file_table, slot_index);
 
 	ctx->file_table.data.nodes[slot_index] = node;
@@ -133,8 +130,7 @@ int io_fixed_fd_remove(struct io_ring_ctx *ctx, unsigned int offset)
 	node = io_rsrc_node_lookup(&ctx->file_table.data, offset);
 	if (!node)
 		return -EBADF;
-	io_put_rsrc_node(node);
-	ctx->file_table.data.nodes[offset] = NULL;
+	io_reset_rsrc_node(&ctx->file_table.data, offset);
 	io_file_bitmap_clear(&ctx->file_table, offset);
 	return 0;
 }
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 0924c53dd954..97673771a0fb 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -182,7 +182,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
 		return -EINVAL;
 
 	for (done = 0; done < nr_args; done++) {
-		struct io_rsrc_node *node;
 		u64 tag = 0;
 
 		if ((tags && copy_from_user(&tag, &tags[done], sizeof(tag))) ||
@@ -198,12 +197,9 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
 			continue;
 
 		i = up->offset + done;
-		node = io_rsrc_node_lookup(&ctx->file_table.data, i);
-		if (node) {
-			io_put_rsrc_node(node);
-			ctx->file_table.data.nodes[i] = NULL;
+		if (io_reset_rsrc_node(&ctx->file_table.data, i))
 			io_file_bitmap_clear(&ctx->file_table, i);
-		}
+
 		if (fd != -1) {
 			struct file *file = fget(fd);
 			struct io_rsrc_node *node;
@@ -281,9 +277,7 @@ static int __io_sqe_buffers_update(struct io_ring_ctx *ctx,
 			err = PTR_ERR(node);
 			break;
 		}
-		if (ctx->buf_table.nodes[i])
-			io_put_rsrc_node(ctx->buf_table.nodes[i]);
-
+		io_reset_rsrc_node(&ctx->buf_table, i);
 		ctx->buf_table.nodes[i] = node;
 		if (tag)
 			node->tag = tag;
diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h
index 6952fb45f57a..abd214f303f5 100644
--- a/io_uring/rsrc.h
+++ b/io_uring/rsrc.h
@@ -85,6 +85,17 @@ static inline void io_put_rsrc_node(struct io_rsrc_node *node)
 		io_free_rsrc_node(node);
 }
 
+static inline bool io_reset_rsrc_node(struct io_rsrc_data *data, int index)
+{
+	struct io_rsrc_node *node = data->nodes[index];
+
+	if (!node)
+		return false;
+	io_put_rsrc_node(node);
+	data->nodes[index] = NULL;
+	return true;
+}
+
 static inline void io_req_put_rsrc_nodes(struct io_kiocb *req)
 {
 	if (req->rsrc_nodes[IORING_RSRC_FILE] != rsrc_empty_node) {
-- 
2.45.2


      parent reply	other threads:[~2024-10-29 15:23 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-29 15:16 [PATCHSET v3 0/14] Rewrite rsrc node handling Jens Axboe
2024-10-29 15:16 ` [PATCH 01/14] io_uring/nop: add support for testing registered files and buffers Jens Axboe
2024-10-29 15:16 ` [PATCH 02/14] io_uring/rsrc: move struct io_fixed_file to rsrc.h header Jens Axboe
2024-10-29 15:16 ` [PATCH 03/14] io_uring: specify freeptr usage for SLAB_TYPESAFE_BY_RCU io_kiocb cache Jens Axboe
2024-11-19 15:36   ` Guenter Roeck
2024-11-19 16:02     ` Jens Axboe
2024-11-19 16:21       ` Guenter Roeck
2024-11-19 17:49         ` Geert Uytterhoeven
2024-11-19 19:00           ` Jens Axboe
2024-11-19 19:02             ` Geert Uytterhoeven
2024-11-19 19:10               ` Jens Axboe
2024-11-19 19:25                 ` Geert Uytterhoeven
2024-11-19 19:30                   ` Jens Axboe
2024-11-19 19:41                     ` Geert Uytterhoeven
2024-11-19 19:44                       ` Jens Axboe
2024-11-19 19:49                         ` Jens Axboe
2024-11-19 21:46                           ` Guenter Roeck
2024-11-19 22:30                             ` Jens Axboe
2024-11-20  0:08                               ` Guenter Roeck
2024-11-20  1:58                                 ` Jens Axboe
2024-11-20  8:19                               ` Geert Uytterhoeven
2024-11-20  8:47                                 ` Vlastimil Babka
2024-11-20  9:07                                   ` Geert Uytterhoeven
2024-11-20  9:37                                     ` Vlastimil Babka
2024-11-20 12:48                                       ` Geert Uytterhoeven
2024-11-21 23:04             ` Finn Thain
2024-10-29 15:16 ` [PATCH 04/14] io_uring/splice: open code 2nd direct file assignment Jens Axboe
2024-10-29 15:16 ` [PATCH 05/14] io_uring/rsrc: kill io_charge_rsrc_node() Jens Axboe
2024-10-29 15:16 ` [PATCH 06/14] io_uring/rsrc: get rid of per-ring io_rsrc_node list Jens Axboe
2024-10-29 15:16 ` [PATCH 07/14] io_uring/rsrc: get rid of io_rsrc_node allocation cache Jens Axboe
2024-10-29 15:16 ` [PATCH 08/14] io_uring/rsrc: add an empty io_rsrc_node for sparse buffer entries Jens Axboe
2024-10-29 15:16 ` [PATCH 09/14] io_uring: only initialize io_kiocb rsrc_nodes when needed Jens Axboe
2024-10-29 15:16 ` [PATCH 10/14] io_uring/rsrc: unify file and buffer resource tables Jens Axboe
2024-10-29 15:16 ` [PATCH 11/14] io_uring/rsrc: add io_rsrc_node_lookup() helper Jens Axboe
2024-10-29 15:16 ` [PATCH 12/14] io_uring/filetable: remove io_file_from_index() helper Jens Axboe
2024-10-29 15:16 ` [PATCH 13/14] io_uring/filetable: kill io_reset_alloc_hint() helper Jens Axboe
2024-10-29 15:16 ` Jens Axboe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241029152249.667290-15-axboe@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.