Fanotify Ignore mask
A message that is not in the archive (sent off-list or not yet received): TY2P153MB0224EE022C428AA2506AD1879CF30@TY2P153MB0224.APCP153.PROD.OUTLOOK.COM
Jan Kara
reviewerHello Nilesh!
Quoted 7 lines · Nilesh Awate
I'm new to Fanotify. I'm approaching you because I see that you have done great work in Fanotify subsystem.
I've a trivial query. How can we ignore events from a directory, If we have mark "/" as mount.
fd = fanotify_init(FAN_CLOEXEC |
FAN_CLASS_CONTENT|FAN_NONBLOCK,O_RDONLY | O_LARGEFILE);
Quoted 7 lines
ret = fanotify_mark(fd,
FAN_MARK_ADD|FAN_MARK_MOUNT,FAN_OPEN_PERM|FAN_CLOSE_WRITE,AT_FDCWD, "/") ;Now I don't want events from "/opt" directory is it possible to ignore all events from /opt directory.
I see examples from https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/fanotify/fanotify01.c
But they all taking about a file. Could you pls help me here.
There's no way how you could 'ignore' events in the whole directory, let alone even the whole subtree under a directory which you seem to imply. Ignore mask really only work for avoiding generating events from individual files. Any more sophisticated filtering needs to happen in userspace after getting the events from the kernel.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 17 lines · Jan Kara
Hello Nilesh!
Quoted 12 lines · Nilesh Awate
I'm new to Fanotify. I'm approaching you because I see that you have done great work in Fanotify subsystem.
I've a trivial query. How can we ignore events from a directory, If we have mark "/" as mount.
fd = fanotify_init(FAN_CLOEXEC |
FAN_CLASS_CONTENT|FAN_NONBLOCK,O_RDONLY | O_LARGEFILE);ret = fanotify_mark(fd,
FAN_MARK_ADD|FAN_MARK_MOUNT,FAN_OPEN_PERM|FAN_CLOSE_WRITE,AT_FDCWD, "/") ;Now I don't want events from "/opt" directory is it possible to ignore all events from /opt directory.
Quoted 8 lines
Quoted 2 lines
I see examples from https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/fanotify/fanotify01.c
But they all taking about a file. Could you pls help me here.There's no way how you could 'ignore' events in the whole directory, let alone even the whole subtree under a directory which you seem to imply. Ignore mask really only work for avoiding generating events from individual files. Any more sophisticated filtering needs to happen in userspace after getting the events from the kernel.
There is no way so set an 'ignore' mask, but it is possible to use the fact that the mark is a 'mount' mark.
By mounting a bind mount over /opt (mount -o bind /opt /opt) operations within the /opt subtree (if performed from this mount ns and with path lookup done after
mounting the bind mount), will not generate events to the mount mark on /.
Thanks,
Amir.
Hi Jan, Amir -
Thank you for quick respond!
Yes with mount --bind /opt /opt and then adding ignore mask it works as expected.
Regards,
Nilesh
-----Original Message-----
From: Amir Goldstein <[email protected]>
Sent: Monday, March 23, 2020 6:34 PM
To: Jan Kara <[email protected]>
Cc: Nilesh Awate <[email protected]>; linux-fsdevel <[email protected]>
Subject: [EXTERNAL] Re: Fanotify Ignore mask
Quoted 26 lines · Jan Kara
Hello Nilesh!
Quoted 12 lines · Nilesh Awate
I'm new to Fanotify. I'm approaching you because I see that you have done great work in Fanotify subsystem.
I've a trivial query. How can we ignore events from a directory, If we have mark "/" as mount.
fd = fanotify_init(FAN_CLOEXEC |
FAN_CLASS_CONTENT|FAN_NONBLOCK,O_RDONLY | O_LARGEFILE);ret = fanotify_mark(fd,
FAN_MARK_ADD|FAN_MARK_MOUNT,FAN_OPEN_PERM|FAN_CLOSE_WRITE,AT_FDCWD, "/") ;Now I don't want events from "/opt" directory is it possible to ignore all events from /opt directory.
Quoted 8 lines
I see examples from
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgi
thub.com%2Flinux-test-project%2Fltp%2Fblob%2Fmaster%2Ftestcases%2Fke rnel%2Fsyscalls%2Ffanotify%2Ffanotify01.c&data=02%7C01%7CNilesh. Awate%40microsoft.com%7C6393ffac541a4e2ce0db08d7cf2aba87%7C72f988bf8 6f141af91ab2d7cd011db47%7C1%7C0%7C637205655195489406&sdata=z8TmM 5yVBC5hd%2FegNkxu%2FVaTqJ9kTEoflyXdEmFo0nc%3D&reserved=0 But they all taking about a file. Could you pls help me here.
Quoted 5 lines
There's no way how you could 'ignore' events in the whole directory, let alone even the whole subtree under a directory which you seem to imply. Ignore mask really only work for avoiding generating events from individual files. Any more sophisticated filtering needs to happen in userspace after getting the events from the kernel.
There is no way so set an 'ignore' mask, but it is possible to use the fact that the mark is a 'mount' mark.
By mounting a bind mount over /opt (mount -o bind /opt /opt) operations within the /opt subtree (if performed from this mount ns and with path lookup done after mounting the bind mount), will not generate events to the mount mark on /.
Thanks,
Amir.
Quoted 7 lines · Nilesh Awate
Hi Jan, Amir -
Thank you for quick respond!
Yes with mount --bind /opt /opt and then adding ignore mask it works as expected.
You shouldn't need an ignore mask if you did not set a mark on the /opt mount. The mark on / does not 'recursively' apply to sub mounts.
Thanks,
Amir.
Yes makes sense.
Thank You!
-----Original Message-----
From: Amir Goldstein <[email protected]>
Sent: Monday, March 23, 2020 8:57 PM
To: Nilesh Awate <[email protected]>
Cc: Jan Kara <[email protected]>; linux-fsdevel <[email protected]>
Subject: Re: [EXTERNAL] Re: Fanotify Ignore mask
Quoted 7 lines · Nilesh Awate
Hi Jan, Amir -
Thank you for quick respond!
Yes with mount --bind /opt /opt and then adding ignore mask it works as expected.
You shouldn't need an ignore mask if you did not set a mark on the /opt mount. The mark on / does not 'recursively' apply to sub mounts.
Thanks,
Amir.