Commit 4503b767 authored by Jens Axboe's avatar Jens Axboe

io_uring: catch -EIO from buffered issue request failure

-EIO bubbles up like -EAGAIN if we fail to allocate a request at the
lower level. Play it safe and treat it like -EAGAIN in terms of sync
retry, to avoid passing back an errant -EIO.

Catch some of these early for block based file, as non-mq devices
generally do not support NOWAIT. That saves us some overhead by
not first trying, then retrying from async context. We can go straight
to async punt instead.
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent ac8691c4
...@@ -2088,6 +2088,15 @@ static struct file *__io_file_get(struct io_submit_state *state, int fd) ...@@ -2088,6 +2088,15 @@ static struct file *__io_file_get(struct io_submit_state *state, int fd)
return state->file; return state->file;
} }
static bool io_bdev_nowait(struct block_device *bdev)
{
#ifdef CONFIG_BLOCK
return !bdev || queue_is_mq(bdev_get_queue(bdev));
#else
return true;
#endif
}
/* /*
* If we tracked the file through the SCM inflight mechanism, we could support * If we tracked the file through the SCM inflight mechanism, we could support
* any file. For now, just ensure that anything potentially problematic is done * any file. For now, just ensure that anything potentially problematic is done
...@@ -2097,10 +2106,19 @@ static bool io_file_supports_async(struct file *file, int rw) ...@@ -2097,10 +2106,19 @@ static bool io_file_supports_async(struct file *file, int rw)
{ {
umode_t mode = file_inode(file)->i_mode; umode_t mode = file_inode(file)->i_mode;
if (S_ISBLK(mode) || S_ISCHR(mode) || S_ISSOCK(mode)) if (S_ISBLK(mode)) {
if (io_bdev_nowait(file->f_inode->i_bdev))
return true; return true;
if (S_ISREG(mode) && file->f_op != &io_uring_fops) return false;
}
if (S_ISCHR(mode) || S_ISSOCK(mode))
return true;
if (S_ISREG(mode)) {
if (io_bdev_nowait(file->f_inode->i_sb->s_bdev) &&
file->f_op != &io_uring_fops)
return true; return true;
return false;
}
/* any ->read/write should understand O_NONBLOCK */ /* any ->read/write should understand O_NONBLOCK */
if (file->f_flags & O_NONBLOCK) if (file->f_flags & O_NONBLOCK)
...@@ -2650,7 +2668,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock) ...@@ -2650,7 +2668,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock)
iov_count = iov_iter_count(&iter); iov_count = iov_iter_count(&iter);
ret = rw_verify_area(READ, req->file, &kiocb->ki_pos, iov_count); ret = rw_verify_area(READ, req->file, &kiocb->ki_pos, iov_count);
if (!ret) { if (!ret) {
ssize_t ret2; ssize_t ret2 = 0;
if (req->file->f_op->read_iter) if (req->file->f_op->read_iter)
ret2 = call_read_iter(req->file, kiocb, &iter); ret2 = call_read_iter(req->file, kiocb, &iter);
...@@ -2658,7 +2676,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock) ...@@ -2658,7 +2676,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock)
ret2 = loop_rw_iter(READ, req->file, kiocb, &iter); ret2 = loop_rw_iter(READ, req->file, kiocb, &iter);
/* Catch -EAGAIN return for forced non-blocking submission */ /* Catch -EAGAIN return for forced non-blocking submission */
if (!force_nonblock || ret2 != -EAGAIN) { if (!force_nonblock || (ret2 != -EAGAIN && ret2 != -EIO)) {
kiocb_done(kiocb, ret2); kiocb_done(kiocb, ret2);
} else { } else {
copy_iov: copy_iov:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment