io_uring: extract io_put_kbuf() helper
Extract a common helper for cleaning up a selected buffer, this will be used shortly. By the way, correct cflags types to unsigned and, as kbufs are anyway tracked by a flag, remove useless zeroing req->rw.addr. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
bc02ef3325
commit
8ff069bf2e
|
@ -1922,20 +1922,25 @@ static inline unsigned int io_sqring_entries(struct io_ring_ctx *ctx)
|
||||||
return smp_load_acquire(&rings->sq.tail) - ctx->cached_sq_head;
|
return smp_load_acquire(&rings->sq.tail) - ctx->cached_sq_head;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int io_put_kbuf(struct io_kiocb *req)
|
static unsigned int io_put_kbuf(struct io_kiocb *req, struct io_buffer *kbuf)
|
||||||
{
|
{
|
||||||
struct io_buffer *kbuf;
|
unsigned int cflags;
|
||||||
int cflags;
|
|
||||||
|
|
||||||
kbuf = (struct io_buffer *) (unsigned long) req->rw.addr;
|
|
||||||
cflags = kbuf->bid << IORING_CQE_BUFFER_SHIFT;
|
cflags = kbuf->bid << IORING_CQE_BUFFER_SHIFT;
|
||||||
cflags |= IORING_CQE_F_BUFFER;
|
cflags |= IORING_CQE_F_BUFFER;
|
||||||
req->rw.addr = 0;
|
|
||||||
req->flags &= ~REQ_F_BUFFER_SELECTED;
|
req->flags &= ~REQ_F_BUFFER_SELECTED;
|
||||||
kfree(kbuf);
|
kfree(kbuf);
|
||||||
return cflags;
|
return cflags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline unsigned int io_put_rw_kbuf(struct io_kiocb *req)
|
||||||
|
{
|
||||||
|
struct io_buffer *kbuf;
|
||||||
|
|
||||||
|
kbuf = (struct io_buffer *) (unsigned long) req->rw.addr;
|
||||||
|
return io_put_kbuf(req, kbuf);
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool io_run_task_work(void)
|
static inline bool io_run_task_work(void)
|
||||||
{
|
{
|
||||||
if (current->task_works) {
|
if (current->task_works) {
|
||||||
|
@ -1985,7 +1990,7 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
|
||||||
list_del(&req->inflight_entry);
|
list_del(&req->inflight_entry);
|
||||||
|
|
||||||
if (req->flags & REQ_F_BUFFER_SELECTED)
|
if (req->flags & REQ_F_BUFFER_SELECTED)
|
||||||
cflags = io_put_kbuf(req);
|
cflags = io_put_rw_kbuf(req);
|
||||||
|
|
||||||
__io_cqring_fill_event(req, req->result, cflags);
|
__io_cqring_fill_event(req, req->result, cflags);
|
||||||
(*nr_events)++;
|
(*nr_events)++;
|
||||||
|
@ -2177,7 +2182,7 @@ static void io_complete_rw_common(struct kiocb *kiocb, long res,
|
||||||
if (res != req->result)
|
if (res != req->result)
|
||||||
req_set_fail_links(req);
|
req_set_fail_links(req);
|
||||||
if (req->flags & REQ_F_BUFFER_SELECTED)
|
if (req->flags & REQ_F_BUFFER_SELECTED)
|
||||||
cflags = io_put_kbuf(req);
|
cflags = io_put_rw_kbuf(req);
|
||||||
__io_req_complete(req, res, cflags, cs);
|
__io_req_complete(req, res, cflags, cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue