From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>,
[email protected],
Bijan Mottahedeh <[email protected]>
Subject: [PATCH 8/9] io_uring: create common fixed_rsrc_data allocation routines
Date: Fri, 15 Jan 2021 17:37:51 +0000 [thread overview]
Message-ID: <424704187f56bac1cc2c844be3111815ab9a97e9.1610729503.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
From: Bijan Mottahedeh <[email protected]>
Create common alloc/free fixed_rsrc_data routines for both files and
buffers.
Reviewed-by: Pavel Begunkov <[email protected]>
[remove buffer part]
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 44 +++++++++++++++++++++++++++++---------------
1 file changed, 29 insertions(+), 15 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 44b5472cd425..5b83f689051b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7331,6 +7331,31 @@ static int io_rsrc_ref_quiesce(struct fixed_rsrc_data *data,
return 0;
}
+static struct fixed_rsrc_data *alloc_fixed_rsrc_data(struct io_ring_ctx *ctx)
+{
+ struct fixed_rsrc_data *data;
+
+ data = kzalloc(sizeof(*data), GFP_KERNEL);
+ if (!data)
+ return NULL;
+
+ if (percpu_ref_init(&data->refs, io_rsrc_ref_kill,
+ PERCPU_REF_ALLOW_REINIT, GFP_KERNEL)) {
+ kfree(data);
+ return NULL;
+ }
+ data->ctx = ctx;
+ init_completion(&data->done);
+ return data;
+}
+
+static void free_fixed_rsrc_data(struct fixed_rsrc_data *data)
+{
+ percpu_ref_exit(&data->refs);
+ kfree(data->table);
+ kfree(data);
+}
+
static int io_sqe_files_unregister(struct io_ring_ctx *ctx)
{
struct fixed_rsrc_data *data = ctx->file_data;
@@ -7353,9 +7378,7 @@ static int io_sqe_files_unregister(struct io_ring_ctx *ctx)
nr_tables = DIV_ROUND_UP(ctx->nr_user_files, IORING_MAX_FILES_TABLE);
for (i = 0; i < nr_tables; i++)
kfree(data->table[i].files);
- kfree(data->table);
- percpu_ref_exit(&data->refs);
- kfree(data);
+ free_fixed_rsrc_data(data);
ctx->file_data = NULL;
ctx->nr_user_files = 0;
return 0;
@@ -7790,11 +7813,9 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
if (nr_args > IORING_MAX_FIXED_FILES)
return -EMFILE;
- file_data = kzalloc(sizeof(*ctx->file_data), GFP_KERNEL);
+ file_data = alloc_fixed_rsrc_data(ctx);
if (!file_data)
return -ENOMEM;
- file_data->ctx = ctx;
- init_completion(&file_data->done);
nr_tables = DIV_ROUND_UP(nr_args, IORING_MAX_FILES_TABLE);
file_data->table = kcalloc(nr_tables, sizeof(*file_data->table),
@@ -7802,12 +7823,8 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
if (!file_data->table)
goto out_free;
- if (percpu_ref_init(&file_data->refs, io_rsrc_ref_kill,
- PERCPU_REF_ALLOW_REINIT, GFP_KERNEL))
- goto out_free;
-
if (io_sqe_alloc_file_tables(file_data, nr_tables, nr_args))
- goto out_ref;
+ goto out_free;
ctx->file_data = file_data;
for (i = 0; i < nr_args; i++, ctx->nr_user_files++) {
@@ -7867,11 +7884,8 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
for (i = 0; i < nr_tables; i++)
kfree(file_data->table[i].files);
ctx->nr_user_files = 0;
-out_ref:
- percpu_ref_exit(&file_data->refs);
out_free:
- kfree(file_data->table);
- kfree(file_data);
+ free_fixed_rsrc_data(ctx->file_data);
ctx->file_data = NULL;
return ret;
}
--
2.24.0
next prev parent reply other threads:[~2021-01-15 17:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-15 17:37 [PATCH 0/9] Bijan's rsrc generalisation + prep parts Pavel Begunkov
2021-01-15 17:37 ` [PATCH 1/9] io_uring: rename file related variables to rsrc Pavel Begunkov
2021-01-15 17:37 ` [PATCH 2/9] io_uring: generalize io_queue_rsrc_removal Pavel Begunkov
2021-01-15 17:37 ` [PATCH 3/9] io_uring: separate ref_list from fixed_rsrc_data Pavel Begunkov
2021-01-15 17:37 ` [PATCH 4/9] io_uring: add rsrc_ref locking routines Pavel Begunkov
2021-01-15 17:37 ` [PATCH 5/9] io_uring: split alloc_fixed_file_ref_node Pavel Begunkov
2021-01-15 17:37 ` [PATCH 6/9] io_uring: split ref_node alloc and init Pavel Begunkov
2021-01-15 17:37 ` [PATCH 7/9] io_uring: create common fixed_rsrc_ref_node handling routines Pavel Begunkov
2021-01-15 17:37 ` Pavel Begunkov [this message]
2021-01-15 17:37 ` [PATCH 9/9] io_uring: make percpu_ref_release names consistent Pavel Begunkov
2021-01-15 18:24 ` [PATCH 0/9] Bijan's rsrc generalisation + prep parts Bijan Mottahedeh
2021-01-15 19:08 ` Jens Axboe
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=424704187f56bac1cc2c844be3111815ab9a97e9.1610729503.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox