From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kara Subject: Re: [PATCH 1/1] ftruncate: create FAN_MODIFY and IN_MODIFY events Date: Tue, 7 Oct 2014 21:23:30 +0200 Message-ID: <20141007192330.GE30038@quack.suse.cz> References: <1412360190-1507-1-git-send-email-xypron.glpk@gmx.de> <20141006132449.GD7526@quack.suse.cz> <5432F6E8.7010607@gmx.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Jan Kara , Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Paris , Michael Kerrisk , John McCutchan , Robert Love To: Heinrich Schuchardt Return-path: Content-Disposition: inline In-Reply-To: <5432F6E8.7010607@gmx.de> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Mon 06-10-14 22:09:12, Heinrich Schuchardt wrote: > On 06.10.2014 15:24, Jan Kara wrote: > >On Fri 03-10-14 20:16:30, Heinrich Schuchardt wrote: > >>The fanotify and the inotify API can be used to monitor changes of the file > >>system. > >> > >>System call ftruncate modifies files. Hence it should trigger the corresponding > >>fanotify (FAN_MODIFY) and inotify (IN_MODIFY) events. > > Hum, I would think that the appropriate event gets generated by > >fsnotify_change() called from notify_change()? > > > > Honza > > Hello Jan, > > thank you for reviewing. > > fsnotify_change() calls > fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); > > fsnotify_modify() calls > fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); > > Only with FSNOTIFY_EVENT_PATH a mount is determined in fsnotify(). > > So a FAN_MODIFY event for a mount cannot occur. But I also did not > see a FAN_MODIFY event when watching a file either. Yeah, fanotify processes only FSNOTIFY_EVENT_PATH events (without a path it cannot create an fd to pass to userspace). > IN_MODIFY events are actually created. > > So would it be better to do the change in do_truncate and replace > the call to notify_change by a call to fsnotify_modify? > > I just had a look at > http://lxr.free-electrons.com/ident?i=notify_change > > There seem to be some other usages of notify_change that deserve > consideration, e.g. in ecryptfs_truncate(). Yeah, so the reason why we don't generate FSNOTIFY_EVENT_PATH in notify_change() is because we have only dentry available there. OTOH from a quick look it doesn't look impossible to pass path there from the callers. So I'd rather propagate path to notify_change() and generate also fanotify events there than generating truncate events for fanotify separately somewhere else... Honza > >>Signed-off-by: Heinrich Schuchardt > >>--- > >> fs/open.c | 2 ++ > >> 1 file changed, 2 insertions(+) > >> > >>diff --git a/fs/open.c b/fs/open.c > >>index d6fd3ac..e36f26e 100644 > >>--- a/fs/open.c > >>+++ b/fs/open.c > >>@@ -189,6 +189,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small) > >> error = security_path_truncate(&f.file->f_path); > >> if (!error) > >> error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file); > >>+ if (!error) > >>+ fsnotify_modify(f.file); > >> sb_end_write(inode->i_sb); > >> out_putf: > >> fdput(f); > >>-- > >>2.1.0 > >> > -- Jan Kara SUSE Labs, CR