From: Amir Goldstein <amir73il@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: Eric Paris <eparis@redhat.com>,
Marko Rauhamaa <marko.rauhamaa@f-secure.com>,
linux-fsdevel@vger.kernel.org
Subject: [RFC][PATCH 1/6] fanotify: add a super block root watch
Date: Mon, 13 Mar 2017 15:20:18 +0200 [thread overview]
Message-ID: <1489411223-12081-2-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1489411223-12081-1-git-send-email-amir73il@gmail.com>
Set a watch on the super block's root inode including the
mask bit FAN_EVENT_ON_SB to get notified on the events
of all the inodes on the same super block.
When requesting to add a super block root watch, any
file on the file system can be passed as input argument
for fanotify_mark(). The mark will be added to the root
inode of the file system that file belongs to.
The super block watch cannot be set with FAN_MARK_MOUNT flag,
because a super block watch is an inode mark, not a mount mark.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/notify/fanotify/fanotify.c | 1 +
fs/notify/fanotify/fanotify_user.c | 15 ++++++++++++---
include/uapi/linux/fanotify.h | 3 +++
3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index a647e7b..67feeb6 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -237,6 +237,7 @@ static int fanotify_handle_event(struct fsnotify_group *group,
BUILD_BUG_ON(FAN_DELETE_SELF != FS_DELETE_SELF);
BUILD_BUG_ON(FAN_MOVE_SELF != FS_MOVE_SELF);
BUILD_BUG_ON(FAN_EVENT_ON_CHILD != FS_EVENT_ON_CHILD);
+ BUILD_BUG_ON(FAN_EVENT_ON_SB != FS_EVENT_ON_SB);
BUILD_BUG_ON(FAN_Q_OVERFLOW != FS_Q_OVERFLOW);
BUILD_BUG_ON(FAN_OPEN_PERM != FS_OPEN_PERM);
BUILD_BUG_ON(FAN_ACCESS_PERM != FS_ACCESS_PERM);
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 13015ee..e57c82a 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -902,9 +902,9 @@ SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags,
}
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
- if (mask & ~(FAN_ALL_EVENTS | FAN_ALL_PERM_EVENTS | FAN_EVENT_ON_CHILD))
+ if (mask & ~(FAN_ALL_EVENTS | FAN_ALL_PERM_EVENTS | FAN_EVENT_ON_DESCENDANT))
#else
- if (mask & ~(FAN_ALL_EVENTS | FAN_EVENT_ON_CHILD))
+ if (mask & ~(FAN_ALL_EVENTS | FAN_EVENT_ON_DESCENDANT))
#endif
return -EINVAL;
@@ -927,6 +927,12 @@ SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags,
group->priority == FS_PRIO_0)
goto fput_and_out;
+ /* Super block root watch is not a mount watch */
+ ret = -EINVAL;
+ if ((mask & FAN_EVENT_ON_SB) &&
+ (flags & FAN_MARK_MOUNT))
+ goto fput_and_out;
+
if (flags & FAN_MARK_FLUSH) {
ret = 0;
if (flags & FAN_MARK_MOUNT)
@@ -941,7 +947,9 @@ SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags,
goto fput_and_out;
/* inode held in place by reference to path; group by fget on fd */
- if (!(flags & FAN_MARK_MOUNT))
+ if (mask & FAN_EVENT_ON_SB)
+ inode = path.dentry->d_sb->s_root->d_inode;
+ else if (!(flags & FAN_MARK_MOUNT))
inode = path.dentry->d_inode;
/*
@@ -950,6 +958,7 @@ SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags,
* even if the events happened on another mount point.
*/
if ((flags & FAN_MARK_MOUNT) ||
+ (mask & FAN_EVENT_ON_SB) ||
group->fanotify_data.flags & FAN_EVENT_INFO_PARENT)
mnt = path.mnt;
diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h
index 95b8335..b202e09 100644
--- a/include/uapi/linux/fanotify.h
+++ b/include/uapi/linux/fanotify.h
@@ -25,8 +25,11 @@
#define FAN_ONDIR 0x40000000 /* event occurred against dir */
+#define FAN_EVENT_ON_SB 0x01000000 /* interested in all sb inodes */
#define FAN_EVENT_ON_CHILD 0x08000000 /* interested in child events */
+#define FAN_EVENT_ON_DESCENDANT (FAN_EVENT_ON_CHILD | FAN_EVENT_ON_SB)
+
/* helper events */
#define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */
#define FAN_MOVE (FAN_MOVED_FROM | FAN_MOVED_TO) /* moves */
--
2.7.4
next prev parent reply other threads:[~2017-03-13 13:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-13 13:20 [RFC][PATCH 0/6] fanotify: super block root watch Amir Goldstein
2017-03-13 13:20 ` Amir Goldstein [this message]
2017-03-13 13:20 ` [RFC][PATCH 2/6] fanotify: report events to sb root with fanotify_file_event_info Amir Goldstein
2017-03-13 13:20 ` [RFC][PATCH 3/6] fanotify: pass file handle on sb root watcher events Amir Goldstein
2017-03-13 13:20 ` [RFC][PATCH 4/6] fanotify: report file name to root inode watch with FS_EVENT_ON_CHILD Amir Goldstein
2017-03-13 13:20 ` [RFC][PATCH 5/6] fanotify: export FAN_ONDIR to user Amir Goldstein
2017-03-13 13:20 ` [RFC][PATCH 6/6] fanotify: filter events by root mark mount point Amir Goldstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1489411223-12081-2-git-send-email-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=eparis@redhat.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=marko.rauhamaa@f-secure.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).