Skip to content

Commit fe80eb1

Browse files
committed
io_uring/rw: cleanup io_rw_done()
This originally came from the aio side, and it's laid out rather oddly. The common case here is that we either get -EIOCBQUEUED from submitting an async request, or that we complete the request correctly with the given number of bytes. Handling the odd internal restart error codes is not a common operation. Lay it out a bit more optimally that better explains the normal flow, and switch to avoiding the indirect call completely as this is our kiocb and we know the completion handler can only be one of two possible variants. While at it, move it to where it belongs in the file, with fellow end IO helpers. Outside of being easier to read, this also reduces the text size of the function by 24 bytes for me on arm64. Reviewed-by: Keith Busch <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 6ff1407 commit fe80eb1

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

io_uring/rw.c

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -168,27 +168,6 @@ void io_readv_writev_cleanup(struct io_kiocb *req)
168168
kfree(io->free_iovec);
169169
}
170170

171-
static inline void io_rw_done(struct kiocb *kiocb, ssize_t ret)
172-
{
173-
switch (ret) {
174-
case -EIOCBQUEUED:
175-
break;
176-
case -ERESTARTSYS:
177-
case -ERESTARTNOINTR:
178-
case -ERESTARTNOHAND:
179-
case -ERESTART_RESTARTBLOCK:
180-
/*
181-
* We can't just restart the syscall, since previously
182-
* submitted sqes may already be in progress. Just fail this
183-
* IO with EINTR.
184-
*/
185-
ret = -EINTR;
186-
fallthrough;
187-
default:
188-
kiocb->ki_complete(kiocb, ret);
189-
}
190-
}
191-
192171
static inline loff_t *io_kiocb_update_pos(struct io_kiocb *req)
193172
{
194173
struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);
@@ -371,6 +350,33 @@ static void io_complete_rw_iopoll(struct kiocb *kiocb, long res)
371350
smp_store_release(&req->iopoll_completed, 1);
372351
}
373352

353+
static inline void io_rw_done(struct kiocb *kiocb, ssize_t ret)
354+
{
355+
/* IO was queued async, completion will happen later */
356+
if (ret == -EIOCBQUEUED)
357+
return;
358+
359+
/* transform internal restart error codes */
360+
if (unlikely(ret < 0)) {
361+
switch (ret) {
362+
case -ERESTARTSYS:
363+
case -ERESTARTNOINTR:
364+
case -ERESTARTNOHAND:
365+
case -ERESTART_RESTARTBLOCK:
366+
/*
367+
* We can't just restart the syscall, since previously
368+
* submitted sqes may already be in progress. Just fail
369+
* this IO with EINTR.
370+
*/
371+
ret = -EINTR;
372+
break;
373+
}
374+
}
375+
376+
INDIRECT_CALL_2(kiocb->ki_complete, io_complete_rw_iopoll,
377+
io_complete_rw, kiocb, ret);
378+
}
379+
374380
static int kiocb_done(struct io_kiocb *req, ssize_t ret,
375381
unsigned int issue_flags)
376382
{

0 commit comments

Comments
 (0)