Skip to content

Commit 423d508

Browse files
committed
io_uring/msg_ring: move double lock/unlock helpers higher up
In preparation for needing them somewhere else, move them and get rid of the unused 'issue_flags' for the unlock side. No functional changes in this patch. Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 544d163 commit 423d508

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

io_uring/msg_ring.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@ struct io_msg {
2525
u32 flags;
2626
};
2727

28+
static void io_double_unlock_ctx(struct io_ring_ctx *octx)
29+
{
30+
mutex_unlock(&octx->uring_lock);
31+
}
32+
33+
static int io_double_lock_ctx(struct io_ring_ctx *octx,
34+
unsigned int issue_flags)
35+
{
36+
/*
37+
* To ensure proper ordering between the two ctxs, we can only
38+
* attempt a trylock on the target. If that fails and we already have
39+
* the source ctx lock, punt to io-wq.
40+
*/
41+
if (!(issue_flags & IO_URING_F_UNLOCKED)) {
42+
if (!mutex_trylock(&octx->uring_lock))
43+
return -EAGAIN;
44+
return 0;
45+
}
46+
mutex_lock(&octx->uring_lock);
47+
return 0;
48+
}
49+
2850
void io_msg_ring_cleanup(struct io_kiocb *req)
2951
{
3052
struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg);
@@ -77,29 +99,6 @@ static int io_msg_ring_data(struct io_kiocb *req)
7799
return -EOVERFLOW;
78100
}
79101

80-
static void io_double_unlock_ctx(struct io_ring_ctx *octx,
81-
unsigned int issue_flags)
82-
{
83-
mutex_unlock(&octx->uring_lock);
84-
}
85-
86-
static int io_double_lock_ctx(struct io_ring_ctx *octx,
87-
unsigned int issue_flags)
88-
{
89-
/*
90-
* To ensure proper ordering between the two ctxs, we can only
91-
* attempt a trylock on the target. If that fails and we already have
92-
* the source ctx lock, punt to io-wq.
93-
*/
94-
if (!(issue_flags & IO_URING_F_UNLOCKED)) {
95-
if (!mutex_trylock(&octx->uring_lock))
96-
return -EAGAIN;
97-
return 0;
98-
}
99-
mutex_lock(&octx->uring_lock);
100-
return 0;
101-
}
102-
103102
static struct file *io_msg_grab_file(struct io_kiocb *req, unsigned int issue_flags)
104103
{
105104
struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg);
@@ -148,7 +147,7 @@ static int io_msg_install_complete(struct io_kiocb *req, unsigned int issue_flag
148147
if (!io_post_aux_cqe(target_ctx, msg->user_data, msg->len, 0))
149148
ret = -EOVERFLOW;
150149
out_unlock:
151-
io_double_unlock_ctx(target_ctx, issue_flags);
150+
io_double_unlock_ctx(target_ctx);
152151
return ret;
153152
}
154153

0 commit comments

Comments
 (0)