io_uring: set/clear IOCB_NOWAIT into io_read/write
Move setting IOCB_NOWAIT from io_prep_rw() into io_read()/io_write(), so it's set/cleared in a single place. Also remove @force_nonblock parameter from io_prep_rw(). Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
2d199895d2
commit
a88fc40021
@ -2633,8 +2633,7 @@ static bool io_file_supports_async(struct file *file, int rw)
|
|||||||
return file->f_op->write_iter != NULL;
|
return file->f_op->write_iter != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
|
static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||||
bool force_nonblock)
|
|
||||||
{
|
{
|
||||||
struct io_ring_ctx *ctx = req->ctx;
|
struct io_ring_ctx *ctx = req->ctx;
|
||||||
struct kiocb *kiocb = &req->rw.kiocb;
|
struct kiocb *kiocb = &req->rw.kiocb;
|
||||||
@ -2669,9 +2668,6 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
|
|||||||
if (kiocb->ki_flags & IOCB_NOWAIT)
|
if (kiocb->ki_flags & IOCB_NOWAIT)
|
||||||
req->flags |= REQ_F_NOWAIT;
|
req->flags |= REQ_F_NOWAIT;
|
||||||
|
|
||||||
if (force_nonblock)
|
|
||||||
kiocb->ki_flags |= IOCB_NOWAIT;
|
|
||||||
|
|
||||||
if (ctx->flags & IORING_SETUP_IOPOLL) {
|
if (ctx->flags & IORING_SETUP_IOPOLL) {
|
||||||
if (!(kiocb->ki_flags & IOCB_DIRECT) ||
|
if (!(kiocb->ki_flags & IOCB_DIRECT) ||
|
||||||
!kiocb->ki_filp->f_op->iopoll)
|
!kiocb->ki_filp->f_op->iopoll)
|
||||||
@ -3149,7 +3145,7 @@ static int io_read_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe,
|
|||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
ret = io_prep_rw(req, sqe, force_nonblock);
|
ret = io_prep_rw(req, sqe);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -3284,6 +3280,9 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
|
|||||||
/* Ensure we clear previously set non-block flag */
|
/* Ensure we clear previously set non-block flag */
|
||||||
if (!force_nonblock)
|
if (!force_nonblock)
|
||||||
kiocb->ki_flags &= ~IOCB_NOWAIT;
|
kiocb->ki_flags &= ~IOCB_NOWAIT;
|
||||||
|
else
|
||||||
|
kiocb->ki_flags |= IOCB_NOWAIT;
|
||||||
|
|
||||||
|
|
||||||
/* If the file doesn't support async, just async punt */
|
/* If the file doesn't support async, just async punt */
|
||||||
no_async = force_nonblock && !io_file_supports_async(req->file, READ);
|
no_async = force_nonblock && !io_file_supports_async(req->file, READ);
|
||||||
@ -3373,7 +3372,7 @@ static int io_write_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe,
|
|||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
ret = io_prep_rw(req, sqe, force_nonblock);
|
ret = io_prep_rw(req, sqe);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -3408,7 +3407,9 @@ static int io_write(struct io_kiocb *req, bool force_nonblock,
|
|||||||
|
|
||||||
/* Ensure we clear previously set non-block flag */
|
/* Ensure we clear previously set non-block flag */
|
||||||
if (!force_nonblock)
|
if (!force_nonblock)
|
||||||
req->rw.kiocb.ki_flags &= ~IOCB_NOWAIT;
|
kiocb->ki_flags &= ~IOCB_NOWAIT;
|
||||||
|
else
|
||||||
|
kiocb->ki_flags |= IOCB_NOWAIT;
|
||||||
|
|
||||||
/* If the file doesn't support async, just async punt */
|
/* If the file doesn't support async, just async punt */
|
||||||
if (force_nonblock && !io_file_supports_async(req->file, WRITE))
|
if (force_nonblock && !io_file_supports_async(req->file, WRITE))
|
||||||
|
Loading…
Reference in New Issue
Block a user