diff mbox series

[10/11] iomap: add a IOMAP_DIO_OVERWRITE_ONLY flag

Message ID 20210121085906.322712-11-hch@lst.de (mailing list archive)
State New
Headers show
Series [01/11] xfs: factor out a xfs_ilock_iocb helper | expand

Commit Message

Christoph Hellwig Jan. 21, 2021, 8:59 a.m. UTC
Add a flag to signal an only pure overwrites are allowed.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/iomap/direct-io.c  | 7 +++++++
 include/linux/iomap.h | 8 ++++++++
 2 files changed, 15 insertions(+)

Comments

Dave Chinner Jan. 21, 2021, 9:32 a.m. UTC | #1
On Thu, Jan 21, 2021 at 09:59:05AM +0100, Christoph Hellwig wrote:
> Add a flag to signal an only pure overwrites are allowed.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/iomap/direct-io.c  | 7 +++++++
>  include/linux/iomap.h | 8 ++++++++
>  2 files changed, 15 insertions(+)

IOMAP_DIO_OVERWRITE_ONLY is a much better name compared to all the
other alternatives that were suggested. :)

> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index 947343730e2c93..65d32364345d22 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -485,6 +485,13 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>  		iomap_flags |= IOMAP_NOWAIT;
>  	}
>  
> +	if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) {
> +		ret = -EAGAIN;
> +		if (pos >= dio->i_size || pos + count > dio->i_size)
> +			goto out_free_dio;
> +		iomap_flags |= IOMAP_OVERWRITE_ONLY;
> +	}
> +
>  	ret = filemap_write_and_wait_range(mapping, pos, end);
>  	if (ret)
>  		goto out_free_dio;
> diff --git a/include/linux/iomap.h b/include/linux/iomap.h
> index be4e1e1e01e801..cfa20afd7d5b87 100644
> --- a/include/linux/iomap.h
> +++ b/include/linux/iomap.h
> @@ -122,6 +122,7 @@ struct iomap_page_ops {
>  #define IOMAP_FAULT		(1 << 3) /* mapping for page fault */
>  #define IOMAP_DIRECT		(1 << 4) /* direct I/O */
>  #define IOMAP_NOWAIT		(1 << 5) /* do not block */
> +#define IOMAP_OVERWRITE_ONLY	(1 << 6) /* purely overwrites allowed */

Nit: s/purely/pure/

But otherwise good.

Reviewed-by: Dave Chinner <dchinner@redhat.com>
Brian Foster Jan. 21, 2021, 1:32 p.m. UTC | #2
On Thu, Jan 21, 2021 at 09:59:05AM +0100, Christoph Hellwig wrote:
> Add a flag to signal an only pure overwrites are allowed.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---

Agreed that the explicit flag name is much more clear:

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  fs/iomap/direct-io.c  | 7 +++++++
>  include/linux/iomap.h | 8 ++++++++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index 947343730e2c93..65d32364345d22 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -485,6 +485,13 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>  		iomap_flags |= IOMAP_NOWAIT;
>  	}
>  
> +	if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) {
> +		ret = -EAGAIN;
> +		if (pos >= dio->i_size || pos + count > dio->i_size)
> +			goto out_free_dio;
> +		iomap_flags |= IOMAP_OVERWRITE_ONLY;
> +	}
> +
>  	ret = filemap_write_and_wait_range(mapping, pos, end);
>  	if (ret)
>  		goto out_free_dio;
> diff --git a/include/linux/iomap.h b/include/linux/iomap.h
> index be4e1e1e01e801..cfa20afd7d5b87 100644
> --- a/include/linux/iomap.h
> +++ b/include/linux/iomap.h
> @@ -122,6 +122,7 @@ struct iomap_page_ops {
>  #define IOMAP_FAULT		(1 << 3) /* mapping for page fault */
>  #define IOMAP_DIRECT		(1 << 4) /* direct I/O */
>  #define IOMAP_NOWAIT		(1 << 5) /* do not block */
> +#define IOMAP_OVERWRITE_ONLY	(1 << 6) /* purely overwrites allowed */
>  
>  struct iomap_ops {
>  	/*
> @@ -262,6 +263,13 @@ struct iomap_dio_ops {
>   */
>  #define IOMAP_DIO_FORCE_WAIT	(1 << 0)
>  
> +/*
> + * Do not allocate blocks or zero partial blocks, but instead fall back to
> + * the caller by returning -EAGAIN.  Used to optimize direct I/O writes that
> + * are not aligned to the file system block size.
> +  */
> +#define IOMAP_DIO_OVERWRITE_ONLY	(1 << 1)
> +
>  ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>  		const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
>  		unsigned int dio_flags);
> -- 
> 2.29.2
>
Darrick J. Wong Jan. 21, 2021, 6:55 p.m. UTC | #3
On Thu, Jan 21, 2021 at 09:59:05AM +0100, Christoph Hellwig wrote:
> Add a flag to signal an only pure overwrites are allowed.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/iomap/direct-io.c  | 7 +++++++
>  include/linux/iomap.h | 8 ++++++++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index 947343730e2c93..65d32364345d22 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -485,6 +485,13 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>  		iomap_flags |= IOMAP_NOWAIT;
>  	}
>  
> +	if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) {
> +		ret = -EAGAIN;
> +		if (pos >= dio->i_size || pos + count > dio->i_size)
> +			goto out_free_dio;
> +		iomap_flags |= IOMAP_OVERWRITE_ONLY;
> +	}
> +
>  	ret = filemap_write_and_wait_range(mapping, pos, end);
>  	if (ret)
>  		goto out_free_dio;
> diff --git a/include/linux/iomap.h b/include/linux/iomap.h
> index be4e1e1e01e801..cfa20afd7d5b87 100644
> --- a/include/linux/iomap.h
> +++ b/include/linux/iomap.h
> @@ -122,6 +122,7 @@ struct iomap_page_ops {
>  #define IOMAP_FAULT		(1 << 3) /* mapping for page fault */
>  #define IOMAP_DIRECT		(1 << 4) /* direct I/O */
>  #define IOMAP_NOWAIT		(1 << 5) /* do not block */
> +#define IOMAP_OVERWRITE_ONLY	(1 << 6) /* purely overwrites allowed */

"only pure overwrites allowed" ?

With that fixed,

Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

>  
>  struct iomap_ops {
>  	/*
> @@ -262,6 +263,13 @@ struct iomap_dio_ops {
>   */
>  #define IOMAP_DIO_FORCE_WAIT	(1 << 0)
>  
> +/*
> + * Do not allocate blocks or zero partial blocks, but instead fall back to
> + * the caller by returning -EAGAIN.  Used to optimize direct I/O writes that
> + * are not aligned to the file system block size.
> +  */
> +#define IOMAP_DIO_OVERWRITE_ONLY	(1 << 1)
> +
>  ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>  		const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
>  		unsigned int dio_flags);
> -- 
> 2.29.2
>
diff mbox series

Patch

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 947343730e2c93..65d32364345d22 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -485,6 +485,13 @@  __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
 		iomap_flags |= IOMAP_NOWAIT;
 	}
 
+	if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) {
+		ret = -EAGAIN;
+		if (pos >= dio->i_size || pos + count > dio->i_size)
+			goto out_free_dio;
+		iomap_flags |= IOMAP_OVERWRITE_ONLY;
+	}
+
 	ret = filemap_write_and_wait_range(mapping, pos, end);
 	if (ret)
 		goto out_free_dio;
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index be4e1e1e01e801..cfa20afd7d5b87 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -122,6 +122,7 @@  struct iomap_page_ops {
 #define IOMAP_FAULT		(1 << 3) /* mapping for page fault */
 #define IOMAP_DIRECT		(1 << 4) /* direct I/O */
 #define IOMAP_NOWAIT		(1 << 5) /* do not block */
+#define IOMAP_OVERWRITE_ONLY	(1 << 6) /* purely overwrites allowed */
 
 struct iomap_ops {
 	/*
@@ -262,6 +263,13 @@  struct iomap_dio_ops {
  */
 #define IOMAP_DIO_FORCE_WAIT	(1 << 0)
 
+/*
+ * Do not allocate blocks or zero partial blocks, but instead fall back to
+ * the caller by returning -EAGAIN.  Used to optimize direct I/O writes that
+ * are not aligned to the file system block size.
+  */
+#define IOMAP_DIO_OVERWRITE_ONLY	(1 << 1)
+
 ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
 		const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
 		unsigned int dio_flags);