diff mbox series

[2/6] iomap: IOMAP_DIOF_PGINVALID_FAIL return if page invalidation fails

Message ID 20200622152457.7118-3-rgoldwyn@suse.de (mailing list archive)
State New, archived
Headers show
Series btrfs direct-io using iomap | expand

Commit Message

Goldwyn Rodrigues June 22, 2020, 3:24 p.m. UTC
From: Goldwyn Rodrigues <rgoldwyn@suse.com>

The flag indicates that if the page invalidation fails, it should return
back control to the filesystem so it may fallback to buffered mode.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
 fs/iomap/direct-io.c  | 8 +++++++-
 include/linux/iomap.h | 5 +++++
 2 files changed, 12 insertions(+), 1 deletion(-)

Comments

Darrick J. Wong June 22, 2020, 5:33 p.m. UTC | #1
On Mon, Jun 22, 2020 at 10:24:53AM -0500, Goldwyn Rodrigues wrote:
> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
> 
> The flag indicates that if the page invalidation fails, it should return
> back control to the filesystem so it may fallback to buffered mode.
> 
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>

Looks reasonable enough, I suppose...

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  fs/iomap/direct-io.c  | 8 +++++++-
>  include/linux/iomap.h | 5 +++++
>  2 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index 7ed857196a39..20c4370e6b1b 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -484,8 +484,14 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>  	 */
>  	ret = invalidate_inode_pages2_range(mapping,
>  			pos >> PAGE_SHIFT, end >> PAGE_SHIFT);
> -	if (ret)
> +	if (ret) {
> +		if (dio_flags & IOMAP_DIOF_PGINVALID_FAIL) {
> +			if (ret == -EBUSY)
> +				ret = 0;
> +			goto out_free_dio;
> +		}
>  		dio_warn_stale_pagecache(iocb->ki_filp);
> +	}
>  	ret = 0;
>  
>  	if (iov_iter_rw(iter) == WRITE && !wait_for_completion &&
> diff --git a/include/linux/iomap.h b/include/linux/iomap.h
> index f6230446b08d..95024e28dec5 100644
> --- a/include/linux/iomap.h
> +++ b/include/linux/iomap.h
> @@ -261,6 +261,11 @@ struct iomap_dio_ops {
>  
>  /* Wait for completion of DIO */
>  #define IOMAP_DIOF_WAIT_FOR_COMPLETION 		0x1
> +/*
> + * Return zero if page invalidation fails, so caller filesystem may fallback
> + * to buffered I/O
> + */
> +#define IOMAP_DIOF_PGINVALID_FAIL		0x2
>  
>  ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>  		const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
> -- 
> 2.25.0
>
Dave Chinner June 23, 2020, 6:15 a.m. UTC | #2
On Mon, Jun 22, 2020 at 10:33:30AM -0700, Darrick J. Wong wrote:
> On Mon, Jun 22, 2020 at 10:24:53AM -0500, Goldwyn Rodrigues wrote:
> > From: Goldwyn Rodrigues <rgoldwyn@suse.com>
> > 
> > The flag indicates that if the page invalidation fails, it should return
> > back control to the filesystem so it may fallback to buffered mode.
> > 
> > Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
> 
> Looks reasonable enough, I suppose...
> 
> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
> 
> --D
> 
> > ---
> >  fs/iomap/direct-io.c  | 8 +++++++-
> >  include/linux/iomap.h | 5 +++++
> >  2 files changed, 12 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> > index 7ed857196a39..20c4370e6b1b 100644
> > --- a/fs/iomap/direct-io.c
> > +++ b/fs/iomap/direct-io.c
> > @@ -484,8 +484,14 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
> >  	 */
> >  	ret = invalidate_inode_pages2_range(mapping,
> >  			pos >> PAGE_SHIFT, end >> PAGE_SHIFT);
> > -	if (ret)
> > +	if (ret) {
> > +		if (dio_flags & IOMAP_DIOF_PGINVALID_FAIL) {
> > +			if (ret == -EBUSY)
> > +				ret = 0;
> > +			goto out_free_dio;
> > +		}
> >  		dio_warn_stale_pagecache(iocb->ki_filp);
> > +	}
> >  	ret = 0;
> >  
> >  	if (iov_iter_rw(iter) == WRITE && !wait_for_completion &&
> > diff --git a/include/linux/iomap.h b/include/linux/iomap.h
> > index f6230446b08d..95024e28dec5 100644
> > --- a/include/linux/iomap.h
> > +++ b/include/linux/iomap.h
> > @@ -261,6 +261,11 @@ struct iomap_dio_ops {
> >  
> >  /* Wait for completion of DIO */
> >  #define IOMAP_DIOF_WAIT_FOR_COMPLETION 		0x1
> > +/*
> > + * Return zero if page invalidation fails, so caller filesystem may fallback
> > + * to buffered I/O
> > + */
> > +#define IOMAP_DIOF_PGINVALID_FAIL		0x2

That's a mouthful of letter salad. :(

Basically, you want the DIO to return a short IO if there is a busy
page cache on the inode?

IOWs, you don't want the page cache to become stale as a result of
the DIO being executed? So what the caller is actually asking for is
that the dio avoids creating stale page cache pages? Hence:

/*
 * Direct IO will attempt to keep the page cache coherent by
 * invalidating the inode's page cache over the range of the DIO.
 * That can fail if something else is actively using the page cache.
 * If this happens and the DIO continues, the data in the page
 * cache will become stale.
 *
 * Set this flag if you want the DIO to abort without issuing any IO
 * or error if it fails to invalidate the page cache successfully.
 * This allows the IO submitter to resubmit the entire IO as a
 * buffered IO through the page cache.
 */
#define IOMAP_DIO_RWF_NO_STALE_PAGECACHE	(1 << 1)

Cheers,

Dave.
diff mbox series

Patch

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 7ed857196a39..20c4370e6b1b 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -484,8 +484,14 @@  iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
 	 */
 	ret = invalidate_inode_pages2_range(mapping,
 			pos >> PAGE_SHIFT, end >> PAGE_SHIFT);
-	if (ret)
+	if (ret) {
+		if (dio_flags & IOMAP_DIOF_PGINVALID_FAIL) {
+			if (ret == -EBUSY)
+				ret = 0;
+			goto out_free_dio;
+		}
 		dio_warn_stale_pagecache(iocb->ki_filp);
+	}
 	ret = 0;
 
 	if (iov_iter_rw(iter) == WRITE && !wait_for_completion &&
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index f6230446b08d..95024e28dec5 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -261,6 +261,11 @@  struct iomap_dio_ops {
 
 /* Wait for completion of DIO */
 #define IOMAP_DIOF_WAIT_FOR_COMPLETION 		0x1
+/*
+ * Return zero if page invalidation fails, so caller filesystem may fallback
+ * to buffered I/O
+ */
+#define IOMAP_DIOF_PGINVALID_FAIL		0x2
 
 ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
 		const struct iomap_ops *ops, const struct iomap_dio_ops *dops,