fanotify: store fanotify_init() flags in group's fanotify_data
authorAmir Goldstein <amir73il@gmail.com>
Fri, 21 Sep 2018 18:20:30 +0000 (21:20 +0300)
committerJan Kara <jack@suse.cz>
Thu, 27 Sep 2018 13:29:00 +0000 (15:29 +0200)
This averts the need to re-generate flags in fanotify_show_fdinfo()
and sets the scene for addition of more upcoming flags without growing
new members to the fanotify_data struct.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
fs/notify/fanotify/fanotify_user.c
fs/notify/fdinfo.c
include/linux/fanotify.h
include/linux/fsnotify_backend.h

index 1347c588f778ab3545735d136206841b41067007..15719d4aa4b56432f0a51e28803d3eb681f3447c 100644 (file)
@@ -191,7 +191,7 @@ static int process_access_response(struct fsnotify_group *group,
        if (fd < 0)
                return -EINVAL;
 
-       if ((response & FAN_AUDIT) && !group->fanotify_data.audit)
+       if ((response & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT))
                return -EINVAL;
 
        event = dequeue_event(group, fd);
@@ -701,8 +701,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
        struct user_struct *user;
        struct fanotify_event_info *oevent;
 
-       pr_debug("%s: flags=%d event_f_flags=%d\n",
-               __func__, flags, event_f_flags);
+       pr_debug("%s: flags=%x event_f_flags=%x\n",
+                __func__, flags, event_f_flags);
 
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
@@ -746,6 +746,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
        }
 
        group->fanotify_data.user = user;
+       group->fanotify_data.flags = flags;
        atomic_inc(&user->fanotify_listeners);
        group->memcg = get_mem_cgroup_from_mm(current->mm);
 
@@ -798,7 +799,6 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
                fd = -EPERM;
                if (!capable(CAP_AUDIT_WRITE))
                        goto out_destroy_group;
-               group->fanotify_data.audit = true;
        }
 
        fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags);
index 25385e336ac7bd8a81d2b4ab15b3fc2c7328a2f6..348a184bcdda3483256e74b6f192e9dd7d339220 100644 (file)
@@ -142,31 +142,9 @@ static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark)
 void fanotify_show_fdinfo(struct seq_file *m, struct file *f)
 {
        struct fsnotify_group *group = f->private_data;
-       unsigned int flags = 0;
-
-       switch (group->priority) {
-       case FS_PRIO_0:
-               flags |= FAN_CLASS_NOTIF;
-               break;
-       case FS_PRIO_1:
-               flags |= FAN_CLASS_CONTENT;
-               break;
-       case FS_PRIO_2:
-               flags |= FAN_CLASS_PRE_CONTENT;
-               break;
-       }
-
-       if (group->max_events == UINT_MAX)
-               flags |= FAN_UNLIMITED_QUEUE;
-
-       if (group->fanotify_data.max_marks == UINT_MAX)
-               flags |= FAN_UNLIMITED_MARKS;
-
-       if (group->fanotify_data.audit)
-               flags |= FAN_ENABLE_AUDIT;
 
        seq_printf(m, "fanotify flags:%x event-flags:%x\n",
-                  flags, group->fanotify_data.f_flags);
+                  group->fanotify_data.flags, group->fanotify_data.f_flags);
 
        show_fdinfo(m, f, fanotify_fdinfo);
 }
index 096c96f4f16af0f94a54e5e237e3f36fe9883778..9c5ea3bdfaa07d0ab6566e3553d1a9910afcc27d 100644 (file)
@@ -6,4 +6,8 @@
 
 /* not valid from userspace, only kernel internal */
 #define FAN_MARK_ONDIR         0x00000100
+
+#define FAN_GROUP_FLAG(group, flag) \
+       ((group)->fanotify_data.flags & (flag))
+
 #endif /* _LINUX_FANOTIFY_H */
index 81b88fc9df31fbcfb5b948b0f74794dc3061677b..8e91341cbd8af8ded94a0910b2232a7e2a70e56a 100644 (file)
@@ -189,10 +189,10 @@ struct fsnotify_group {
                        /* allows a group to block waiting for a userspace response */
                        struct list_head access_list;
                        wait_queue_head_t access_waitq;
-                       int f_flags;
+                       int flags;           /* flags from fanotify_init() */
+                       int f_flags; /* event_f_flags from fanotify_init() */
                        unsigned int max_marks;
                        struct user_struct *user;
-                       bool audit;
                } fanotify_data;
 #endif /* CONFIG_FANOTIFY */
        };