fsnotify: separate mark iterator type from object type enum
authorAmir Goldstein <amir73il@gmail.com>
Mon, 29 Nov 2021 20:15:28 +0000 (22:15 +0200)
committerJan Kara <jack@suse.cz>
Wed, 15 Dec 2021 13:04:06 +0000 (14:04 +0100)
They are two different types that use the same enum, so this confusing.

Use the object type to indicate the type of object mark is attached to
and the iter type to indicate the type of watch.

A group can have two different watches of the same object type (parent
and child watches) that match the same event.

Link: https://lore.kernel.org/r/20211129201537.1932819-3-amir73il@gmail.com
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
fs/notify/fanotify/fanotify.c
fs/notify/fsnotify.c
fs/notify/mark.c
include/linux/fsnotify_backend.h

index b6091775aa6efe3677e9e83e50cc664dfa15a0df..652fe84cb8acd53337f81f6c4c9f8e4c8e2dd79f 100644 (file)
@@ -299,7 +299,7 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
                        return 0;
        }
 
-       fsnotify_foreach_obj_type(type) {
+       fsnotify_foreach_iter_type(type) {
                if (!fsnotify_iter_should_report_type(iter_info, type))
                        continue;
                mark = iter_info->marks[type];
@@ -318,7 +318,7 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
                 * If the event is on a child and this mark is on a parent not
                 * watching children, don't send it!
                 */
-               if (type == FSNOTIFY_OBJ_TYPE_PARENT &&
+               if (type == FSNOTIFY_ITER_TYPE_PARENT &&
                    !(mark->mask & FS_EVENT_ON_CHILD))
                        continue;
 
@@ -746,7 +746,7 @@ static __kernel_fsid_t fanotify_get_fsid(struct fsnotify_iter_info *iter_info)
        int type;
        __kernel_fsid_t fsid = {};
 
-       fsnotify_foreach_obj_type(type) {
+       fsnotify_foreach_iter_type(type) {
                struct fsnotify_mark_connector *conn;
 
                if (!fsnotify_iter_should_report_type(iter_info, type))
index 4034ca566f95cedcb01480b0640be4b770539eec..0c94457c625e29275d33524b5a0d9e10f5e33f70 100644 (file)
@@ -330,7 +330,7 @@ static int send_to_group(__u32 mask, const void *data, int data_type,
 
        /* clear ignored on inode modification */
        if (mask & FS_MODIFY) {
-               fsnotify_foreach_obj_type(type) {
+               fsnotify_foreach_iter_type(type) {
                        if (!fsnotify_iter_should_report_type(iter_info, type))
                                continue;
                        mark = iter_info->marks[type];
@@ -340,7 +340,7 @@ static int send_to_group(__u32 mask, const void *data, int data_type,
                }
        }
 
-       fsnotify_foreach_obj_type(type) {
+       fsnotify_foreach_iter_type(type) {
                if (!fsnotify_iter_should_report_type(iter_info, type))
                        continue;
                mark = iter_info->marks[type];
@@ -405,7 +405,7 @@ static unsigned int fsnotify_iter_select_report_types(
        int type;
 
        /* Choose max prio group among groups of all queue heads */
-       fsnotify_foreach_obj_type(type) {
+       fsnotify_foreach_iter_type(type) {
                mark = iter_info->marks[type];
                if (mark &&
                    fsnotify_compare_groups(max_prio_group, mark->group) > 0)
@@ -417,7 +417,7 @@ static unsigned int fsnotify_iter_select_report_types(
 
        /* Set the report mask for marks from same group as max prio group */
        iter_info->report_mask = 0;
-       fsnotify_foreach_obj_type(type) {
+       fsnotify_foreach_iter_type(type) {
                mark = iter_info->marks[type];
                if (mark &&
                    fsnotify_compare_groups(max_prio_group, mark->group) == 0)
@@ -435,7 +435,7 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info)
 {
        int type;
 
-       fsnotify_foreach_obj_type(type) {
+       fsnotify_foreach_iter_type(type) {
                if (fsnotify_iter_should_report_type(iter_info, type))
                        iter_info->marks[type] =
                                fsnotify_next_mark(iter_info->marks[type]);
@@ -519,18 +519,18 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,
 
        iter_info.srcu_idx = srcu_read_lock(&fsnotify_mark_srcu);
 
-       iter_info.marks[FSNOTIFY_OBJ_TYPE_SB] =
+       iter_info.marks[FSNOTIFY_ITER_TYPE_SB] =
                fsnotify_first_mark(&sb->s_fsnotify_marks);
        if (mnt) {
-               iter_info.marks[FSNOTIFY_OBJ_TYPE_VFSMOUNT] =
+               iter_info.marks[FSNOTIFY_ITER_TYPE_VFSMOUNT] =
                        fsnotify_first_mark(&mnt->mnt_fsnotify_marks);
        }
        if (inode) {
-               iter_info.marks[FSNOTIFY_OBJ_TYPE_INODE] =
+               iter_info.marks[FSNOTIFY_ITER_TYPE_INODE] =
                        fsnotify_first_mark(&inode->i_fsnotify_marks);
        }
        if (parent) {
-               iter_info.marks[FSNOTIFY_OBJ_TYPE_PARENT] =
+               iter_info.marks[FSNOTIFY_ITER_TYPE_PARENT] =
                        fsnotify_first_mark(&parent->i_fsnotify_marks);
        }
 
index 52af2e9dadc00b95431822f57a71419ace7a8bbe..9007d6affff359a1c8a74ee1755ab294b220f89d 100644 (file)
@@ -353,7 +353,7 @@ bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info)
 {
        int type;
 
-       fsnotify_foreach_obj_type(type) {
+       fsnotify_foreach_iter_type(type) {
                /* This can fail if mark is being removed */
                if (!fsnotify_get_mark_safe(iter_info->marks[type])) {
                        __release(&fsnotify_mark_srcu);
@@ -382,7 +382,7 @@ void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info)
        int type;
 
        iter_info->srcu_idx = srcu_read_lock(&fsnotify_mark_srcu);
-       fsnotify_foreach_obj_type(type)
+       fsnotify_foreach_iter_type(type)
                fsnotify_put_mark_wake(iter_info->marks[type]);
 }
 
index b9c84b1dbcc8fa19b19c5a4ca8e4b8f16dec695d..73739fee1710f05b56e805d2f2652b20e9f9b1a8 100644 (file)
@@ -337,10 +337,25 @@ static inline struct fs_error_report *fsnotify_data_error_report(
        }
 }
 
+/*
+ * Index to merged marks iterator array that correlates to a type of watch.
+ * The type of watched object can be deduced from the iterator type, but not
+ * the other way around, because an event can match different watched objects
+ * of the same object type.
+ * For example, both parent and child are watching an object of type inode.
+ */
+enum fsnotify_iter_type {
+       FSNOTIFY_ITER_TYPE_INODE,
+       FSNOTIFY_ITER_TYPE_VFSMOUNT,
+       FSNOTIFY_ITER_TYPE_SB,
+       FSNOTIFY_ITER_TYPE_PARENT,
+       FSNOTIFY_ITER_TYPE_COUNT
+};
+
+/* The type of object that a mark is attached to */
 enum fsnotify_obj_type {
        FSNOTIFY_OBJ_TYPE_ANY = -1,
        FSNOTIFY_OBJ_TYPE_INODE,
-       FSNOTIFY_OBJ_TYPE_PARENT,
        FSNOTIFY_OBJ_TYPE_VFSMOUNT,
        FSNOTIFY_OBJ_TYPE_SB,
        FSNOTIFY_OBJ_TYPE_COUNT,
@@ -353,37 +368,37 @@ static inline bool fsnotify_valid_obj_type(unsigned int obj_type)
 }
 
 struct fsnotify_iter_info {
-       struct fsnotify_mark *marks[FSNOTIFY_OBJ_TYPE_COUNT];
+       struct fsnotify_mark *marks[FSNOTIFY_ITER_TYPE_COUNT];
        unsigned int report_mask;
        int srcu_idx;
 };
 
 static inline bool fsnotify_iter_should_report_type(
-               struct fsnotify_iter_info *iter_info, int type)
+               struct fsnotify_iter_info *iter_info, int iter_type)
 {
-       return (iter_info->report_mask & (1U << type));
+       return (iter_info->report_mask & (1U << iter_type));
 }
 
 static inline void fsnotify_iter_set_report_type(
-               struct fsnotify_iter_info *iter_info, int type)
+               struct fsnotify_iter_info *iter_info, int iter_type)
 {
-       iter_info->report_mask |= (1U << type);
+       iter_info->report_mask |= (1U << iter_type);
 }
 
 static inline void fsnotify_iter_set_report_type_mark(
-               struct fsnotify_iter_info *iter_info, int type,
+               struct fsnotify_iter_info *iter_info, int iter_type,
                struct fsnotify_mark *mark)
 {
-       iter_info->marks[type] = mark;
-       iter_info->report_mask |= (1U << type);
+       iter_info->marks[iter_type] = mark;
+       iter_info->report_mask |= (1U << iter_type);
 }
 
 #define FSNOTIFY_ITER_FUNCS(name, NAME) \
 static inline struct fsnotify_mark *fsnotify_iter_##name##_mark( \
                struct fsnotify_iter_info *iter_info) \
 { \
-       return (iter_info->report_mask & (1U << FSNOTIFY_OBJ_TYPE_##NAME)) ? \
-               iter_info->marks[FSNOTIFY_OBJ_TYPE_##NAME] : NULL; \
+       return (iter_info->report_mask & (1U << FSNOTIFY_ITER_TYPE_##NAME)) ? \
+               iter_info->marks[FSNOTIFY_ITER_TYPE_##NAME] : NULL; \
 }
 
 FSNOTIFY_ITER_FUNCS(inode, INODE)
@@ -391,8 +406,8 @@ FSNOTIFY_ITER_FUNCS(parent, PARENT)
 FSNOTIFY_ITER_FUNCS(vfsmount, VFSMOUNT)
 FSNOTIFY_ITER_FUNCS(sb, SB)
 
-#define fsnotify_foreach_obj_type(type) \
-       for (type = 0; type < FSNOTIFY_OBJ_TYPE_COUNT; type++)
+#define fsnotify_foreach_iter_type(type) \
+       for (type = 0; type < FSNOTIFY_ITER_TYPE_COUNT; type++)
 
 /*
  * fsnotify_connp_t is what we embed in objects which connector can be attached