Skip to content

Commit 9bf7933

Browse files
Roman Penyaevaxboe
authored andcommitted
io_uring: offload write to async worker in case of -EAGAIN
In case of direct write -EAGAIN will be returned if page cache was previously populated. To avoid immediate completion of a request with -EAGAIN error write has to be offloaded to the async worker, like io_read() does. Signed-off-by: Roman Penyaev <rpenyaev@suse.de> Cc: Jens Axboe <axboe@kernel.dk> Cc: linux-block@vger.kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e6d1fa5 commit 9bf7933

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

fs/io_uring.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,8 @@ static int io_write(struct io_kiocb *req, const struct sqe_submit *s,
10221022

10231023
ret = rw_verify_area(WRITE, file, &kiocb->ki_pos, iov_count);
10241024
if (!ret) {
1025+
ssize_t ret2;
1026+
10251027
/*
10261028
* Open-code file_start_write here to grab freeze protection,
10271029
* which will be released by another thread in
@@ -1036,7 +1038,19 @@ static int io_write(struct io_kiocb *req, const struct sqe_submit *s,
10361038
SB_FREEZE_WRITE);
10371039
}
10381040
kiocb->ki_flags |= IOCB_WRITE;
1039-
io_rw_done(kiocb, call_write_iter(file, kiocb, &iter));
1041+
1042+
ret2 = call_write_iter(file, kiocb, &iter);
1043+
if (!force_nonblock || ret2 != -EAGAIN) {
1044+
io_rw_done(kiocb, ret2);
1045+
} else {
1046+
/*
1047+
* If ->needs_lock is true, we're already in async
1048+
* context.
1049+
*/
1050+
if (!s->needs_lock)
1051+
io_async_list_note(WRITE, req, iov_count);
1052+
ret = -EAGAIN;
1053+
}
10401054
}
10411055
out_free:
10421056
kfree(iovec);

0 commit comments

Comments
 (0)