On Mon, Jun 19, 2023 at 11:18:55PM -0700, Christoph Hellwig wrote: > So it turns out this gets into the way of my planned cleanup to move > all the tatic FMODE_ flags out of this basically full field into a new > static one in file_operations. Do you think it is ok to go back to > always claiming FMODE_NOWAIT for block devices and then just punt for > the drivers that don't support it like the patch below? Except that the version I posted if of course completly broken as my testing rig told me. This is the version that actually works: --- >From 7916df7434e1570978b9c81c65aa1ec1f3396b13 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig <hch@xxxxxx> Date: Tue, 20 Jun 2023 07:53:13 +0200 Subject: block: always set FMODE_NOWAIT Block devices are the only file_operations that do not set FMODE_NOWAIT unconditionall in ->open and thus get in the way of a planned cleanup to move this flags into a static field in file_operations. Switch to always set FMODE_NOWAIT and just return -EAGAIN if it isn't actually supported. This just affects minor ->submit_bio based drivers as all blk-mq drivers and the important remappers (dm, md, nvme-multipath) support nowait I/O. Signed-off-by: Christoph Hellwig <hch@xxxxxx> --- block/fops.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/block/fops.c b/block/fops.c index 555b1b9ecd2cb9..58c2f65ae4a57e 100644 --- a/block/fops.c +++ b/block/fops.c @@ -505,7 +505,7 @@ static int blkdev_open(struct inode *inode, struct file *filp) * during an unstable branch. */ filp->f_flags |= O_LARGEFILE; - filp->f_mode |= FMODE_BUF_RASYNC; + filp->f_mode |= FMODE_BUF_RASYNC | FMODE_NOWAIT; /* * Use the file private data to store the holder for exclusive openes. @@ -519,9 +519,6 @@ static int blkdev_open(struct inode *inode, struct file *filp) if (IS_ERR(bdev)) return PTR_ERR(bdev); - if (bdev_nowait(bdev)) - filp->f_mode |= FMODE_NOWAIT; - filp->f_mapping = bdev->bd_inode->i_mapping; filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping); return 0; @@ -563,6 +560,9 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) if ((iocb->ki_flags & (IOCB_NOWAIT | IOCB_DIRECT)) == IOCB_NOWAIT) return -EOPNOTSUPP; + if ((iocb->ki_flags & IOCB_NOWAIT) && !bdev_nowait(bdev)) + return -EAGAIN; + size -= iocb->ki_pos; if (iov_iter_count(from) > size) { shorted = iov_iter_count(from) - size; @@ -585,6 +585,9 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) ssize_t ret = 0; size_t count; + if ((iocb->ki_flags & IOCB_NOWAIT) && !bdev_nowait(bdev)) + return -EAGAIN; + if (unlikely(pos + iov_iter_count(to) > size)) { if (pos >= size) return 0; -- 2.39.2