diff mbox series

[RFC,v4,11/17] fs: Add async write file modification handling.

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

Commit Message

Stefan Roesch May 20, 2022, 6:36 p.m. UTC
This adds a file_modified_async() function to return -EAGAIN if the
request either requires to remove privileges or needs to update the file
modification time. This is required for async buffered writes, so the
request gets handled in the io worker of io-uring.

Signed-off-by: Stefan Roesch <shr@fb.com>
---
 fs/inode.c         | 25 ++++++++++++++++++++++++-
 fs/xfs/xfs_file.c  |  2 +-
 include/linux/fs.h |  1 +
 3 files changed, 26 insertions(+), 2 deletions(-)

Comments

Christoph Hellwig May 22, 2022, 7:24 a.m. UTC | #1
> +int file_modified_async(struct file *file, int flags)

file_modified_flags?  Or even bette kiocb_modified and pass the
kiocb as that makes is very clear which flags we use by making that
implicit.

> +EXPORT_SYMBOL(file_modified_async);

EXPORT_SYMBOL_GPL, please.

> -	return file_modified(file);
> +	return file_modified_async(file, iocb->ki_flags);

And this should go into the XFS enablemnt patch.

>  extern int file_modified(struct file *file);
> +extern int file_modified_async(struct file *file, int flags);

No need for the extern here, or any function declarations for that
matter.
Stefan Roesch May 25, 2022, 9:39 p.m. UTC | #2
On 5/22/22 12:24 AM, Christoph Hellwig wrote:
>> +int file_modified_async(struct file *file, int flags)
> 
> file_modified_flags?  Or even bette kiocb_modified and pass the
> kiocb as that makes is very clear which flags we use by making that
> implicit.
> 

  - Renamed file_modified_async() to file_modified_flags()
  - Made file_modified_flags() an internal function
  - Add kiocb_modified function.

>> +EXPORT_SYMBOL(file_modified_async);
> 
> EXPORT_SYMBOL_GPL, please.

Done.
> 
>> -	return file_modified(file);
>> +	return file_modified_async(file, iocb->ki_flags);
> 
> And this should go into the XFS enablemnt patch.
> 
>>  extern int file_modified(struct file *file);
>> +extern int file_modified_async(struct file *file, int flags);
> 
> No need for the extern here, or any function declarations for that
> matter.
  - Removed extern keyword in file_modified_async definition
diff mbox series

Patch

diff --git a/fs/inode.c b/fs/inode.c
index 4bb7f583cc6b..3a5d0fa468ab 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2137,6 +2137,27 @@  EXPORT_SYMBOL(file_update_time);
  * Return: 0 on success, negative errno on failure.
  */
 int file_modified(struct file *file)
+{
+	return file_modified_async(file, 0);
+}
+EXPORT_SYMBOL(file_modified);
+
+/**
+ * file_modified_async - handle mandated vfs changes when modifying a file
+ * @file: file that was modified
+ * @flags: kiocb flags
+ *
+ * When file has been modified ensure that special
+ * file privileges are removed and time settings are updated.
+ *
+ * If IOCB_NOWAIT is set, special file privileges will not be removed and
+ * time settings will not be updated. It will return -EAGAIN.
+ *
+ * Context: Caller must hold the file's inode lock.
+ *
+ * Return: 0 on success, negative errno on failure.
+ */
+int file_modified_async(struct file *file, int flags)
 {
 	int ret;
 	struct dentry *dentry = file_dentry(file);
@@ -2163,10 +2184,12 @@  int file_modified(struct file *file)
 	ret = file_needs_update_time(inode, file, &now);
 	if (ret <= 0)
 		return ret;
+	if (flags & IOCB_NOWAIT)
+		return -EAGAIN;
 
 	return __file_update_time(inode, file, &now, ret);
 }
-EXPORT_SYMBOL(file_modified);
+EXPORT_SYMBOL(file_modified_async);
 
 int inode_needs_sync(struct inode *inode)
 {
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 5bddb1e9e0b3..793918c83755 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -410,7 +410,7 @@  xfs_file_write_checks(
 		spin_unlock(&ip->i_flags_lock);
 
 out:
-	return file_modified(file);
+	return file_modified_async(file, iocb->ki_flags);
 }
 
 static int
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 3b479d02e210..9760283af7dc 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2382,6 +2382,7 @@  static inline void file_accessed(struct file *file)
 }
 
 extern int file_modified(struct file *file);
+extern int file_modified_async(struct file *file, int flags);
 
 int sync_inode_metadata(struct inode *inode, int wait);