diff options
author | Eric Paris <eparis@redhat.com> | 2009-12-17 21:24:25 -0500 |
---|---|---|
committer | Eric Paris <eparis@redhat.com> | 2010-07-28 09:58:54 -0400 |
commit | ff0b16a9850e8a240ad59e10b0a1291a8fcf7cbc (patch) | |
tree | fe6fad578cfb2b8528828d4f77e5494542a1fb34 /fs/notify | |
parent | 12ed2e36c98aec6c41559222e311f4aa15d254b6 (diff) |
fanotify: fscking all notification system
fanotify is a novel file notification system which bases notification on
giving userspace both an event type (open, close, read, write) and an open
file descriptor to the object in question. This should address a number of
races and problems with other notification systems like inotify and dnotify
and should allow the future implementation of blocking or access controlled
notification. These are useful for on access scanners or hierachical storage
management schemes.
This patch just implements the basics of the fsnotify functions.
Signed-off-by: Eric Paris <eparis@redhat.com>
Diffstat (limited to 'fs/notify')
-rw-r--r-- | fs/notify/Kconfig | 1 | ||||
-rw-r--r-- | fs/notify/Makefile | 1 | ||||
-rw-r--r-- | fs/notify/fanotify/Kconfig | 11 | ||||
-rw-r--r-- | fs/notify/fanotify/Makefile | 1 | ||||
-rw-r--r-- | fs/notify/fanotify/fanotify.c | 78 | ||||
-rw-r--r-- | fs/notify/fanotify/fanotify.h | 12 |
6 files changed, 104 insertions, 0 deletions
diff --git a/fs/notify/Kconfig b/fs/notify/Kconfig index dffbb0911d02..22c629eedd82 100644 --- a/fs/notify/Kconfig +++ b/fs/notify/Kconfig | |||
@@ -3,3 +3,4 @@ config FSNOTIFY | |||
3 | 3 | ||
4 | source "fs/notify/dnotify/Kconfig" | 4 | source "fs/notify/dnotify/Kconfig" |
5 | source "fs/notify/inotify/Kconfig" | 5 | source "fs/notify/inotify/Kconfig" |
6 | source "fs/notify/fanotify/Kconfig" | ||
diff --git a/fs/notify/Makefile b/fs/notify/Makefile index 0922cc826c46..396a38779371 100644 --- a/fs/notify/Makefile +++ b/fs/notify/Makefile | |||
@@ -2,3 +2,4 @@ obj-$(CONFIG_FSNOTIFY) += fsnotify.o notification.o group.o inode_mark.o | |||
2 | 2 | ||
3 | obj-y += dnotify/ | 3 | obj-y += dnotify/ |
4 | obj-y += inotify/ | 4 | obj-y += inotify/ |
5 | obj-y += fanotify/ | ||
diff --git a/fs/notify/fanotify/Kconfig b/fs/notify/fanotify/Kconfig new file mode 100644 index 000000000000..f9d7ae081f85 --- /dev/null +++ b/fs/notify/fanotify/Kconfig | |||
@@ -0,0 +1,11 @@ | |||
1 | config FANOTIFY | ||
2 | bool "Filesystem wide access notification" | ||
3 | select FSNOTIFY | ||
4 | default y | ||
5 | ---help--- | ||
6 | Say Y here to enable fanotify suport. fanotify is a file access | ||
7 | notification system which differs from inotify in that it sends | ||
8 | and open file descriptor to the userspace listener along with | ||
9 | the event. | ||
10 | |||
11 | If unsure, say Y. | ||
diff --git a/fs/notify/fanotify/Makefile b/fs/notify/fanotify/Makefile new file mode 100644 index 000000000000..e7d39c05b0fe --- /dev/null +++ b/fs/notify/fanotify/Makefile | |||
@@ -0,0 +1 @@ | |||
obj-$(CONFIG_FANOTIFY) += fanotify.o | |||
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c new file mode 100644 index 000000000000..3ffb9dbcab08 --- /dev/null +++ b/fs/notify/fanotify/fanotify.c | |||
@@ -0,0 +1,78 @@ | |||
1 | #include <linux/fdtable.h> | ||
2 | #include <linux/fsnotify_backend.h> | ||
3 | #include <linux/init.h> | ||
4 | #include <linux/kernel.h> /* UINT_MAX */ | ||
5 | #include <linux/types.h> | ||
6 | |||
7 | #include "fanotify.h" | ||
8 | |||
9 | static int fanotify_handle_event(struct fsnotify_group *group, struct fsnotify_event *event) | ||
10 | { | ||
11 | int ret; | ||
12 | |||
13 | |||
14 | BUILD_BUG_ON(FAN_ACCESS != FS_ACCESS); | ||
15 | BUILD_BUG_ON(FAN_MODIFY != FS_MODIFY); | ||
16 | BUILD_BUG_ON(FAN_CLOSE_NOWRITE != FS_CLOSE_NOWRITE); | ||
17 | BUILD_BUG_ON(FAN_CLOSE_WRITE != FS_CLOSE_WRITE); | ||
18 | BUILD_BUG_ON(FAN_OPEN != FS_OPEN); | ||
19 | BUILD_BUG_ON(FAN_EVENT_ON_CHILD != FS_EVENT_ON_CHILD); | ||
20 | BUILD_BUG_ON(FAN_Q_OVERFLOW != FS_Q_OVERFLOW); | ||
21 | |||
22 | pr_debug("%s: group=%p event=%p\n", __func__, group, event); | ||
23 | |||
24 | ret = fsnotify_add_notify_event(group, event, NULL, NULL); | ||
25 | |||
26 | return ret; | ||
27 | } | ||
28 | |||
29 | static bool fanotify_should_send_event(struct fsnotify_group *group, struct inode *inode, | ||
30 | struct vfsmount *mnt, __u32 mask, void *data, | ||
31 | int data_type) | ||
32 | { | ||
33 | struct fsnotify_mark *fsn_mark; | ||
34 | bool send; | ||
35 | |||
36 | pr_debug("%s: group=%p inode=%p mask=%x data=%p data_type=%d\n", | ||
37 | __func__, group, inode, mask, data, data_type); | ||
38 | |||
39 | /* sorry, fanotify only gives a damn about files and dirs */ | ||
40 | if (!S_ISREG(inode->i_mode) && | ||
41 | !S_ISDIR(inode->i_mode)) | ||
42 | return false; | ||
43 | |||
44 | /* if we don't have enough info to send an event to userspace say no */ | ||
45 | if (data_type != FSNOTIFY_EVENT_PATH) | ||
46 | return false; | ||
47 | |||
48 | fsn_mark = fsnotify_find_mark(group, inode); | ||
49 | if (!fsn_mark) | ||
50 | return false; | ||
51 | |||
52 | /* if the event is for a child and this inode doesn't care about | ||
53 | * events on the child, don't send it! */ | ||
54 | if ((mask & FS_EVENT_ON_CHILD) && | ||
55 | !(fsn_mark->mask & FS_EVENT_ON_CHILD)) { | ||
56 | send = false; | ||
57 | } else { | ||
58 | /* | ||
59 | * We care about children, but do we care about this particular | ||
60 | * type of event? | ||
61 | */ | ||
62 | mask = (mask & ~FS_EVENT_ON_CHILD); | ||
63 | send = (fsn_mark->mask & mask); | ||
64 | } | ||
65 | |||
66 | /* find took a reference */ | ||
67 | fsnotify_put_mark(fsn_mark); | ||
68 | |||
69 | return send; | ||
70 | } | ||
71 | |||
72 | const struct fsnotify_ops fanotify_fsnotify_ops = { | ||
73 | .handle_event = fanotify_handle_event, | ||
74 | .should_send_event = fanotify_should_send_event, | ||
75 | .free_group_priv = NULL, | ||
76 | .free_event_priv = NULL, | ||
77 | .freeing_mark = NULL, | ||
78 | }; | ||
diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h new file mode 100644 index 000000000000..50765eb30fe4 --- /dev/null +++ b/fs/notify/fanotify/fanotify.h | |||
@@ -0,0 +1,12 @@ | |||
1 | #include <linux/fanotify.h> | ||
2 | #include <linux/fsnotify_backend.h> | ||
3 | #include <linux/net.h> | ||
4 | #include <linux/kernel.h> | ||
5 | #include <linux/types.h> | ||
6 | |||
7 | static inline bool fanotify_mask_valid(__u32 mask) | ||
8 | { | ||
9 | if (mask & ~((__u32)FAN_ALL_INCOMING_EVENTS)) | ||
10 | return false; | ||
11 | return true; | ||
12 | } | ||