diff options
author | Jens Axboe <axboe@kernel.dk> | 2024-10-29 09:02:38 -0600 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2024-11-02 15:45:30 -0600 |
commit | 4007c3d8c22a2025367953f4ee36ae106a69d855 (patch) | |
tree | 4180ac98a9b7f3ffbcc3d7a424a06f3147c67750 /io_uring/filetable.c | |
parent | 5f3829fdd69d746f36a5e87df21ce58470b8e9fa (diff) | |
download | lwn-4007c3d8c22a2025367953f4ee36ae106a69d855.tar.gz lwn-4007c3d8c22a2025367953f4ee36ae106a69d855.zip |
io_uring/rsrc: add io_reset_rsrc_node() helper
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>
Diffstat (limited to 'io_uring/filetable.c')
-rw-r--r-- | io_uring/filetable.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/io_uring/filetable.c b/io_uring/filetable.c index 7a9de6718b8a..45f005f5db42 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 (!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; } |