aboutsummaryrefslogtreecommitdiffstats
path: root/fs/open.c
diff options
context:
space:
mode:
authorHeinrich Schuchardt <xypron.glpk@gmx.de>2014-12-12 19:58:34 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-13 15:42:53 -0500
commit820c12d5d6c0890bc93dd63893924a13041fdc35 (patch)
tree5ff4b86a17da144d2f99a40bbf5f9737c6cbb88b /fs/open.c
parent620951e2745750de1482128615adc15b74ee37ed (diff)
fallocate: create FAN_MODIFY and IN_MODIFY events
The fanotify and the inotify API can be used to monitor changes of the file system. System call fallocate() modifies files. Hence it should trigger the corresponding fanotify (FAN_MODIFY) and inotify (IN_MODIFY) events. The most interesting case is FALLOC_FL_COLLAPSE_RANGE because this value allows to create arbitrary file content from random data. This patch adds the missing call to fsnotify_modify(). The FAN_MODIFY and IN_MODIFY event will be created when fallocate() succeeds. It will even be created if the file length remains unchanged, e.g. when calling fanotify with flag FALLOC_FL_KEEP_SIZE. This logic was primarily chosen to keep the coding simple. It resembles the logic of the write() system call. When we call write() we always create a FAN_MODIFY event, even in the case of overwriting with identical data. Events FAN_MODIFY and IN_MODIFY do not provide any guarantee that data was actually changed. Furthermore even if if the filesize remains unchanged, fallocate() may influence whether a subsequent write() will succeed and hence the fallocate() call may be considered a modification. The fallocate(2) man page teaches: After a successful call, subsequent writes into the range specified by offset and len are guaranteed not to fail because of lack of disk space. So calling fallocate(fd, FALLOC_FL_KEEP_SIZE, offset, len) may result in different outcomes of a subsequent write depending on the values of offset and len. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Jan Kara <jack@suse.cz> Cc: Jan Kara <jack@suse.cz> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Eric Paris <eparis@parisplace.org> Cc: John McCutchan <john@johnmccutchan.com> Cc: Robert Love <rlove@rlove.org> Cc: Michael Kerrisk <mtk.manpages@gmail.com> Cc: Theodore Ts'o <tytso@mit.edu> Cc: Dave Chinner <david@fromorbit.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/open.c')
-rw-r--r--fs/open.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/fs/open.c b/fs/open.c
index b1bf3d542d5d..d45bd905d418 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -295,6 +295,17 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
295 295
296 sb_start_write(inode->i_sb); 296 sb_start_write(inode->i_sb);
297 ret = file->f_op->fallocate(file, mode, offset, len); 297 ret = file->f_op->fallocate(file, mode, offset, len);
298
299 /*
300 * Create inotify and fanotify events.
301 *
302 * To keep the logic simple always create events if fallocate succeeds.
303 * This implies that events are even created if the file size remains
304 * unchanged, e.g. when using flag FALLOC_FL_KEEP_SIZE.
305 */
306 if (ret == 0)
307 fsnotify_modify(file);
308
298 sb_end_write(inode->i_sb); 309 sb_end_write(inode->i_sb);
299 return ret; 310 return ret;
300} 311}