All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] io_uring: don't set REQ_F_NOWAIT for regular files opend O_NONBLOCK
@ 2020-05-29  7:18 Jiufei Xue
  2020-05-29 14:20 ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Jiufei Xue @ 2020-05-29  7:18 UTC (permalink / raw)
  To: io-uring; +Cc: axboe, joseph.qi

When read from a regular file that was opened O_NONBLOCK, it will
return EAGAIN if the page is not cached, which is not expected and
fails the application.

Applications written before expect that the open flag O_NONBLOCK has
no effect on a regular file.

Fix this by not setting REQ_F_NOWAIT for regular files.

Signed-off-by: Jiufei Xue <jiufei.xue@linux.alibaba.com>
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 95df63b..69db8bb 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2107,7 +2107,7 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
 
 	/* don't allow async punt if RWF_NOWAIT was requested */
 	if ((kiocb->ki_flags & IOCB_NOWAIT) ||
-	    (req->file->f_flags & O_NONBLOCK))
+	    (!(req->flags & REQ_F_ISREG) && (req->file->f_flags & O_NONBLOCK)))
 		req->flags |= REQ_F_NOWAIT;
 
 	if (force_nonblock)
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] io_uring: don't set REQ_F_NOWAIT for regular files opend O_NONBLOCK
  2020-05-29  7:18 [PATCH] io_uring: don't set REQ_F_NOWAIT for regular files opend O_NONBLOCK Jiufei Xue
@ 2020-05-29 14:20 ` Jens Axboe
  2020-06-01  3:26   ` Jiufei Xue
  0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2020-05-29 14:20 UTC (permalink / raw)
  To: Jiufei Xue, io-uring; +Cc: joseph.qi

On 5/29/20 1:18 AM, Jiufei Xue wrote:
> When read from a regular file that was opened O_NONBLOCK, it will
> return EAGAIN if the page is not cached, which is not expected and
> fails the application.
> 
> Applications written before expect that the open flag O_NONBLOCK has
> no effect on a regular file.
> 
> Fix this by not setting REQ_F_NOWAIT for regular files.

Agree, this also matches what we do for sockets. You need to update
the comment as well, though.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] io_uring: don't set REQ_F_NOWAIT for regular files opend O_NONBLOCK
  2020-05-29 14:20 ` Jens Axboe
@ 2020-06-01  3:26   ` Jiufei Xue
  2020-06-10  6:16     ` Jiufei Xue
  0 siblings, 1 reply; 4+ messages in thread
From: Jiufei Xue @ 2020-06-01  3:26 UTC (permalink / raw)
  To: Jens Axboe, io-uring; +Cc: joseph.qi

Hi Jens,

On 2020/5/29 下午10:20, Jens Axboe wrote:
> On 5/29/20 1:18 AM, Jiufei Xue wrote:
>> When read from a regular file that was opened O_NONBLOCK, it will
>> return EAGAIN if the page is not cached, which is not expected and
>> fails the application.
>>
>> Applications written before expect that the open flag O_NONBLOCK has
>> no effect on a regular file.
>>
>> Fix this by not setting REQ_F_NOWAIT for regular files.
> 
> Agree, this also matches what we do for sockets. You need to update
> the comment as well, though.
> 
Reading from an O_NONBLOCK socket will return EAGAIN if there isn't any
unread data in the buffer which is expected.So I don't know what is your
meaning about that. Do you mean the recv() interface? 

Regards,
Jiufei



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] io_uring: don't set REQ_F_NOWAIT for regular files opend O_NONBLOCK
  2020-06-01  3:26   ` Jiufei Xue
@ 2020-06-10  6:16     ` Jiufei Xue
  0 siblings, 0 replies; 4+ messages in thread
From: Jiufei Xue @ 2020-06-10  6:16 UTC (permalink / raw)
  To: Jens Axboe, io-uring; +Cc: joseph.qi

Hi Jens,

Could you please spent some time to look at this? 

Thanks,
Jiufei

On 2020/6/1 上午11:26, Jiufei Xue wrote:
> Hi Jens,
> 
> On 2020/5/29 下午10:20, Jens Axboe wrote:
>> On 5/29/20 1:18 AM, Jiufei Xue wrote:
>>> When read from a regular file that was opened O_NONBLOCK, it will
>>> return EAGAIN if the page is not cached, which is not expected and
>>> fails the application.
>>>
>>> Applications written before expect that the open flag O_NONBLOCK has
>>> no effect on a regular file.
>>>
>>> Fix this by not setting REQ_F_NOWAIT for regular files.
>>
>> Agree, this also matches what we do for sockets. You need to update
>> the comment as well, though.
>>
> Reading from an O_NONBLOCK socket will return EAGAIN if there isn't any
> unread data in the buffer which is expected.So I don't know what is your
> meaning about that. Do you mean the recv() interface? 
> 
> Regards,
> Jiufei
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-06-10  6:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-29  7:18 [PATCH] io_uring: don't set REQ_F_NOWAIT for regular files opend O_NONBLOCK Jiufei Xue
2020-05-29 14:20 ` Jens Axboe
2020-06-01  3:26   ` Jiufei Xue
2020-06-10  6:16     ` Jiufei Xue

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.