Skip to content

Commit 66fa3ce

Browse files
Stefan Roeschaxboe
authored andcommitted
fs: Add async write file modification handling.
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> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Link: https://lore.kernel.org/r/20220623175157.1715274-11-shr@fb.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 6a2aa5d commit 66fa3ce

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

fs/inode.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,17 +2116,21 @@ int file_update_time(struct file *file)
21162116
EXPORT_SYMBOL(file_update_time);
21172117

21182118
/**
2119-
* file_modified - handle mandated vfs changes when modifying a file
2119+
* file_modified_flags - handle mandated vfs changes when modifying a file
21202120
* @file: file that was modified
2121+
* @flags: kiocb flags
21212122
*
21222123
* When file has been modified ensure that special
21232124
* file privileges are removed and time settings are updated.
21242125
*
2126+
* If IOCB_NOWAIT is set, special file privileges will not be removed and
2127+
* time settings will not be updated. It will return -EAGAIN.
2128+
*
21252129
* Context: Caller must hold the file's inode lock.
21262130
*
21272131
* Return: 0 on success, negative errno on failure.
21282132
*/
2129-
int file_modified(struct file *file)
2133+
static int file_modified_flags(struct file *file, int flags)
21302134
{
21312135
int ret;
21322136
struct inode *inode = file_inode(file);
@@ -2136,7 +2140,7 @@ int file_modified(struct file *file)
21362140
* Clear the security bits if the process is not being run by root.
21372141
* This keeps people from modifying setuid and setgid binaries.
21382142
*/
2139-
ret = __file_remove_privs(file, 0);
2143+
ret = __file_remove_privs(file, flags);
21402144
if (ret)
21412145
return ret;
21422146

@@ -2146,11 +2150,46 @@ int file_modified(struct file *file)
21462150
ret = inode_needs_update_time(inode, &now);
21472151
if (ret <= 0)
21482152
return ret;
2153+
if (flags & IOCB_NOWAIT)
2154+
return -EAGAIN;
21492155

21502156
return __file_update_time(file, &now, ret);
21512157
}
2158+
2159+
/**
2160+
* file_modified - handle mandated vfs changes when modifying a file
2161+
* @file: file that was modified
2162+
*
2163+
* When file has been modified ensure that special
2164+
* file privileges are removed and time settings are updated.
2165+
*
2166+
* Context: Caller must hold the file's inode lock.
2167+
*
2168+
* Return: 0 on success, negative errno on failure.
2169+
*/
2170+
int file_modified(struct file *file)
2171+
{
2172+
return file_modified_flags(file, 0);
2173+
}
21522174
EXPORT_SYMBOL(file_modified);
21532175

2176+
/**
2177+
* kiocb_modified - handle mandated vfs changes when modifying a file
2178+
* @iocb: iocb that was modified
2179+
*
2180+
* When file has been modified ensure that special
2181+
* file privileges are removed and time settings are updated.
2182+
*
2183+
* Context: Caller must hold the file's inode lock.
2184+
*
2185+
* Return: 0 on success, negative errno on failure.
2186+
*/
2187+
int kiocb_modified(struct kiocb *iocb)
2188+
{
2189+
return file_modified_flags(iocb->ki_filp, iocb->ki_flags);
2190+
}
2191+
EXPORT_SYMBOL_GPL(kiocb_modified);
2192+
21542193
int inode_needs_sync(struct inode *inode)
21552194
{
21562195
if (IS_SYNC(inode))

include/linux/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,6 +2390,7 @@ static inline void file_accessed(struct file *file)
23902390
}
23912391

23922392
extern int file_modified(struct file *file);
2393+
int kiocb_modified(struct kiocb *iocb);
23932394

23942395
int sync_inode_metadata(struct inode *inode, int wait);
23952396

0 commit comments

Comments
 (0)