Skip to content

Commit d7f1161

Browse files
krismanaxboe
authored andcommitted
io_uring/rw: Allocate async data through helper
This abstract away the cache details. Signed-off-by: Gabriel Krisman Bertazi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent f49a853 commit d7f1161

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

io_uring/rw.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -208,33 +208,29 @@ static void io_req_rw_cleanup(struct io_kiocb *req, unsigned int issue_flags)
208208
}
209209
}
210210

211+
static void io_rw_async_data_init(void *obj)
212+
{
213+
struct io_async_rw *rw = (struct io_async_rw *)obj;
214+
215+
rw->free_iovec = 0;
216+
rw->bytes_done = 0;
217+
}
218+
211219
static int io_rw_alloc_async(struct io_kiocb *req)
212220
{
213221
struct io_ring_ctx *ctx = req->ctx;
214222
struct io_async_rw *rw;
215223

216-
rw = io_alloc_cache_get(&ctx->rw_cache);
217-
if (rw) {
218-
if (rw->free_iovec) {
219-
kasan_mempool_unpoison_object(rw->free_iovec,
220-
rw->free_iov_nr * sizeof(struct iovec));
221-
req->flags |= REQ_F_NEED_CLEANUP;
222-
}
223-
req->flags |= REQ_F_ASYNC_DATA;
224-
req->async_data = rw;
225-
goto done;
226-
}
227-
228-
if (!io_alloc_async_data(req)) {
229-
rw = req->async_data;
230-
rw->free_iovec = NULL;
231-
rw->free_iov_nr = 0;
232-
done:
224+
rw = io_uring_alloc_async_data(&ctx->rw_cache, req, io_rw_async_data_init);
225+
if (!rw)
226+
return -ENOMEM;
227+
if (rw->free_iovec) {
228+
kasan_mempool_unpoison_object(rw->free_iovec,
229+
rw->free_iov_nr * sizeof(struct iovec));
230+
req->flags |= REQ_F_NEED_CLEANUP;
233231
rw->bytes_done = 0;
234-
return 0;
235232
}
236-
237-
return -ENOMEM;
233+
return 0;
238234
}
239235

240236
static int io_prep_rw_setup(struct io_kiocb *req, int ddir, bool do_import)

0 commit comments

Comments
 (0)