Skip to content

Commit 1721131

Browse files
isilenceaxboe
authored andcommitted
io_uring: extract a io_msg_install_complete helper
Extract a helper called io_msg_install_complete() from io_msg_send_fd(), will be used later. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/1500ca1054cc4286a3ee1c60aacead57fcdfa02a.1670384893.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 1137302 commit 1721131

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

io_uring/msg_ring.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,36 +92,25 @@ static struct file *io_msg_grab_file(struct io_kiocb *req, unsigned int issue_fl
9292
return file;
9393
}
9494

95-
static int io_msg_send_fd(struct io_kiocb *req, unsigned int issue_flags)
95+
static int io_msg_install_complete(struct io_kiocb *req, unsigned int issue_flags)
9696
{
9797
struct io_ring_ctx *target_ctx = req->file->private_data;
9898
struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg);
99-
struct io_ring_ctx *ctx = req->ctx;
10099
struct file *src_file = msg->src_file;
101100
int ret;
102101

103-
if (target_ctx == ctx)
104-
return -EINVAL;
105-
if (!src_file) {
106-
src_file = io_msg_grab_file(req, issue_flags);
107-
if (!src_file)
108-
return -EBADF;
109-
msg->src_file = src_file;
110-
req->flags |= REQ_F_NEED_CLEANUP;
111-
}
112-
113102
if (unlikely(io_double_lock_ctx(target_ctx, issue_flags)))
114103
return -EAGAIN;
115104

116105
ret = __io_fixed_fd_install(target_ctx, src_file, msg->dst_fd);
117106
if (ret < 0)
118107
goto out_unlock;
108+
119109
msg->src_file = NULL;
120110
req->flags &= ~REQ_F_NEED_CLEANUP;
121111

122112
if (msg->flags & IORING_MSG_RING_CQE_SKIP)
123113
goto out_unlock;
124-
125114
/*
126115
* If this fails, the target still received the file descriptor but
127116
* wasn't notified of the fact. This means that if this request
@@ -135,6 +124,25 @@ static int io_msg_send_fd(struct io_kiocb *req, unsigned int issue_flags)
135124
return ret;
136125
}
137126

127+
static int io_msg_send_fd(struct io_kiocb *req, unsigned int issue_flags)
128+
{
129+
struct io_ring_ctx *target_ctx = req->file->private_data;
130+
struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg);
131+
struct io_ring_ctx *ctx = req->ctx;
132+
struct file *src_file = msg->src_file;
133+
134+
if (target_ctx == ctx)
135+
return -EINVAL;
136+
if (!src_file) {
137+
src_file = io_msg_grab_file(req, issue_flags);
138+
if (!src_file)
139+
return -EBADF;
140+
msg->src_file = src_file;
141+
req->flags |= REQ_F_NEED_CLEANUP;
142+
}
143+
return io_msg_install_complete(req, issue_flags);
144+
}
145+
138146
int io_msg_ring_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
139147
{
140148
struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg);

0 commit comments

Comments
 (0)