Skip to content

Commit 3347fa6

Browse files
axboekdave
authored andcommitted
io_uring/cmd: add per-op data to struct io_uring_cmd_data
In case an op handler for ->uring_cmd() needs stable storage for user data, it can allocate io_uring_cmd_data->op_data and use it for the duration of the request. When the request gets cleaned up, uring_cmd will free it automatically. Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent dadf03c commit 3347fa6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

include/linux/io_uring/cmd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct io_uring_cmd {
2020

2121
struct io_uring_cmd_data {
2222
struct io_uring_sqe sqes[2];
23+
void *op_data;
2324
};
2425

2526
static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe)

io_uring/uring_cmd.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ static struct io_uring_cmd_data *io_uring_async_get(struct io_kiocb *req)
2323

2424
cache = io_alloc_cache_get(&ctx->uring_cache);
2525
if (cache) {
26+
cache->op_data = NULL;
2627
req->flags |= REQ_F_ASYNC_DATA;
2728
req->async_data = cache;
2829
return cache;
2930
}
30-
if (!io_alloc_async_data(req))
31-
return req->async_data;
31+
if (!io_alloc_async_data(req)) {
32+
cache = req->async_data;
33+
cache->op_data = NULL;
34+
return cache;
35+
}
3236
return NULL;
3337
}
3438

@@ -37,6 +41,11 @@ static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_flags)
3741
struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
3842
struct io_uring_cmd_data *cache = req->async_data;
3943

44+
if (cache->op_data) {
45+
kfree(cache->op_data);
46+
cache->op_data = NULL;
47+
}
48+
4049
if (issue_flags & IO_URING_F_UNLOCKED)
4150
return;
4251
if (io_alloc_cache_put(&req->ctx->uring_cache, cache)) {

0 commit comments

Comments
 (0)