Skip to content

Commit 98f0b3b

Browse files
isilenceaxboe
authored andcommitted
io_uring: add generic path for rsrc update
Extract some common parts for rsrc update, will be used reg buffers support dynamic (i.e. quiesce-lee) managing. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/b49c3ff6b9ff0e530295767604fe4de64d349e04.1619356238.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent b60c8dc commit 98f0b3b

File tree

1 file changed

+46
-33
lines changed

1 file changed

+46
-33
lines changed

fs/io_uring.c

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,9 +1035,9 @@ static void io_dismantle_req(struct io_kiocb *req);
10351035
static void io_put_task(struct task_struct *task, int nr);
10361036
static struct io_kiocb *io_prep_linked_timeout(struct io_kiocb *req);
10371037
static void io_queue_linked_timeout(struct io_kiocb *req);
1038-
static int __io_sqe_files_update(struct io_ring_ctx *ctx,
1039-
struct io_uring_rsrc_update *ip,
1040-
unsigned nr_args);
1038+
static int __io_register_rsrc_update(struct io_ring_ctx *ctx, unsigned opcode,
1039+
struct io_uring_rsrc_update *up,
1040+
unsigned nr_args);
10411041
static void io_clean_op(struct io_kiocb *req);
10421042
static struct file *io_file_get(struct io_submit_state *state,
10431043
struct io_kiocb *req, int fd, bool fixed);
@@ -5824,7 +5824,8 @@ static int io_files_update(struct io_kiocb *req, unsigned int issue_flags)
58245824
up.data = req->rsrc_update.arg;
58255825

58265826
mutex_lock(&ctx->uring_lock);
5827-
ret = __io_sqe_files_update(ctx, &up, req->rsrc_update.nr_args);
5827+
ret = __io_register_rsrc_update(ctx, IORING_REGISTER_FILES_UPDATE,
5828+
&up, req->rsrc_update.nr_args);
58285829
mutex_unlock(&ctx->uring_lock);
58295830

58305831
if (ret < 0)
@@ -7726,25 +7727,20 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
77267727
struct io_uring_rsrc_update *up,
77277728
unsigned nr_args)
77287729
{
7730+
__s32 __user *fds = u64_to_user_ptr(up->data);
77297731
struct io_rsrc_data *data = ctx->file_data;
77307732
struct io_fixed_file *file_slot;
77317733
struct file *file;
7732-
__s32 __user *fds;
7733-
int fd, i, err;
7734-
__u32 done;
7734+
int fd, i, err = 0;
7735+
unsigned int done;
77357736
bool needs_switch = false;
77367737

7737-
if (check_add_overflow(up->offset, nr_args, &done))
7738-
return -EOVERFLOW;
7739-
if (done > ctx->nr_user_files)
7738+
if (!ctx->file_data)
7739+
return -ENXIO;
7740+
if (up->offset + nr_args > ctx->nr_user_files)
77407741
return -EINVAL;
7741-
err = io_rsrc_node_switch_start(ctx);
7742-
if (err)
7743-
return err;
77447742

7745-
fds = u64_to_user_ptr(up->data);
77467743
for (done = 0; done < nr_args; done++) {
7747-
err = 0;
77487744
if (copy_from_user(&fd, &fds[done], sizeof(fd))) {
77497745
err = -EFAULT;
77507746
break;
@@ -7798,23 +7794,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
77987794
return done ? done : err;
77997795
}
78007796

7801-
static int io_sqe_files_update(struct io_ring_ctx *ctx, void __user *arg,
7802-
unsigned nr_args)
7803-
{
7804-
struct io_uring_rsrc_update up;
7805-
7806-
if (!ctx->file_data)
7807-
return -ENXIO;
7808-
if (!nr_args)
7809-
return -EINVAL;
7810-
if (copy_from_user(&up, arg, sizeof(up)))
7811-
return -EFAULT;
7812-
if (up.resv)
7813-
return -EINVAL;
7814-
7815-
return __io_sqe_files_update(ctx, &up, nr_args);
7816-
}
7817-
78187797
static struct io_wq_work *io_free_work(struct io_wq_work *work)
78197798
{
78207799
struct io_kiocb *req = container_of(work, struct io_kiocb, work);
@@ -9730,6 +9709,40 @@ static int io_register_enable_rings(struct io_ring_ctx *ctx)
97309709
return 0;
97319710
}
97329711

9712+
static int __io_register_rsrc_update(struct io_ring_ctx *ctx, unsigned opcode,
9713+
struct io_uring_rsrc_update *up,
9714+
unsigned nr_args)
9715+
{
9716+
__u32 tmp;
9717+
int err;
9718+
9719+
if (check_add_overflow(up->offset, nr_args, &tmp))
9720+
return -EOVERFLOW;
9721+
err = io_rsrc_node_switch_start(ctx);
9722+
if (err)
9723+
return err;
9724+
9725+
switch (opcode) {
9726+
case IORING_REGISTER_FILES_UPDATE:
9727+
return __io_sqe_files_update(ctx, up, nr_args);
9728+
}
9729+
return -EINVAL;
9730+
}
9731+
9732+
static int io_register_rsrc_update(struct io_ring_ctx *ctx, unsigned opcode,
9733+
void __user *arg, unsigned nr_args)
9734+
{
9735+
struct io_uring_rsrc_update up;
9736+
9737+
if (!nr_args)
9738+
return -EINVAL;
9739+
if (copy_from_user(&up, arg, sizeof(up)))
9740+
return -EFAULT;
9741+
if (up.resv)
9742+
return -EINVAL;
9743+
return __io_register_rsrc_update(ctx, opcode, &up, nr_args);
9744+
}
9745+
97339746
static bool io_register_op_must_quiesce(int op)
97349747
{
97359748
switch (op) {
@@ -9816,7 +9829,7 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
98169829
ret = io_sqe_files_unregister(ctx);
98179830
break;
98189831
case IORING_REGISTER_FILES_UPDATE:
9819-
ret = io_sqe_files_update(ctx, arg, nr_args);
9832+
ret = io_register_rsrc_update(ctx, opcode, arg, nr_args);
98209833
break;
98219834
case IORING_REGISTER_EVENTFD:
98229835
case IORING_REGISTER_EVENTFD_ASYNC:

0 commit comments

Comments
 (0)