diff mbox series

[RFC,v3,01/18] block: Add check for async buffered writes to generic_write_checks

Message ID 20220518233709.1937634-2-shr@fb.com (mailing list archive)
State New
Headers show
Series io-uring/xfs: support async buffered writes | expand

Commit Message

Stefan Roesch May 18, 2022, 11:36 p.m. UTC
This introduces the flag FMODE_BUF_WASYNC. If devices support async
buffered writes, this flag can be set. It also modifies the check in
generic_write_checks to take async buffered writes into consideration.

Signed-off-by: Stefan Roesch <shr@fb.com>
---
 fs/read_write.c    | 4 +++-
 include/linux/fs.h | 3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)

Comments

Christoph Hellwig May 19, 2022, 8:17 a.m. UTC | #1
On Wed, May 18, 2022 at 04:36:52PM -0700, Stefan Roesch wrote:
> @@ -1633,7 +1633,9 @@ int generic_write_checks_count(struct kiocb *iocb, loff_t *count)
>  	if (iocb->ki_flags & IOCB_APPEND)
>  		iocb->ki_pos = i_size_read(inode);
>  
> -	if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT))
> +	if ((iocb->ki_flags & IOCB_NOWAIT) &&
> +		!((iocb->ki_flags & IOCB_DIRECT) ||
> +		  (file->f_mode & FMODE_BUF_WASYNC)))

This is some really odd indentation.  I'd expect something like:

	if ((iocb->ki_flags & IOCB_NOWAIT) &&
	    !((iocb->ki_flags & IOCB_DIRECT) ||
	      (file->f_mode & FMODE_BUF_WASYNC)))

> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index bbde95387a23..3b479d02e210 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -177,6 +177,9 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
>  /* File supports async buffered reads */
>  #define FMODE_BUF_RASYNC	((__force fmode_t)0x40000000)
>  
> +/* File supports async nowait buffered writes */
> +#define FMODE_BUF_WASYNC	((__force fmode_t)0x80000000)

This is the last available flag in fmode_t.

At some point we should probably move the static capabilities to
a member of file_operations.
Stefan Roesch May 20, 2022, 6:23 p.m. UTC | #2
On 5/19/22 1:17 AM, Christoph Hellwig wrote:
> On Wed, May 18, 2022 at 04:36:52PM -0700, Stefan Roesch wrote:
>> @@ -1633,7 +1633,9 @@ int generic_write_checks_count(struct kiocb *iocb, loff_t *count)
>>  	if (iocb->ki_flags & IOCB_APPEND)
>>  		iocb->ki_pos = i_size_read(inode);
>>  
>> -	if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT))
>> +	if ((iocb->ki_flags & IOCB_NOWAIT) &&
>> +		!((iocb->ki_flags & IOCB_DIRECT) ||
>> +		  (file->f_mode & FMODE_BUF_WASYNC)))
> 
> This is some really odd indentation.  I'd expect something like:
> 
> 	if ((iocb->ki_flags & IOCB_NOWAIT) &&
> 	    !((iocb->ki_flags & IOCB_DIRECT) ||
> 	      (file->f_mode & FMODE_BUF_WASYNC)))
> 

I reformatted the above code for the next version.

>> diff --git a/include/linux/fs.h b/include/linux/fs.h
>> index bbde95387a23..3b479d02e210 100644
>> --- a/include/linux/fs.h
>> +++ b/include/linux/fs.h
>> @@ -177,6 +177,9 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
>>  /* File supports async buffered reads */
>>  #define FMODE_BUF_RASYNC	((__force fmode_t)0x40000000)
>>  
>> +/* File supports async nowait buffered writes */
>> +#define FMODE_BUF_WASYNC	((__force fmode_t)0x80000000)
> 
> This is the last available flag in fmode_t.
> 
> At some point we should probably move the static capabilities to
> a member of file_operations.
diff mbox series

Patch

diff --git a/fs/read_write.c b/fs/read_write.c
index e643aec2b0ef..544d4df33f4f 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1633,7 +1633,9 @@  int generic_write_checks_count(struct kiocb *iocb, loff_t *count)
 	if (iocb->ki_flags & IOCB_APPEND)
 		iocb->ki_pos = i_size_read(inode);
 
-	if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT))
+	if ((iocb->ki_flags & IOCB_NOWAIT) &&
+		!((iocb->ki_flags & IOCB_DIRECT) ||
+		  (file->f_mode & FMODE_BUF_WASYNC)))
 		return -EINVAL;
 
 	return generic_write_check_limits(iocb->ki_filp, iocb->ki_pos, count);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index bbde95387a23..3b479d02e210 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -177,6 +177,9 @@  typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
 /* File supports async buffered reads */
 #define FMODE_BUF_RASYNC	((__force fmode_t)0x40000000)
 
+/* File supports async nowait buffered writes */
+#define FMODE_BUF_WASYNC	((__force fmode_t)0x80000000)
+
 /*
  * Attribute flags.  These should be or-ed together to figure out what
  * has been changed!