From: Dave Hansen <dave.han...@linux.intel.com>

Both inodes and vfsmounts have fsnotify data embedded in them.
The data is always a "mask" and a "mark".  Take those two
fields and move them in to a new structure: struct fsnotify_head.

We will shortly be adding a new field to this.

This also lets us get rid of the ugly #ifdef in 'struct inode'.

In searching for i_fsnotify_mark, my regex found the fsnotify_mark
comment about g_list.  I think the comment was wrong and corrected
it.

Cc: Jan Kara <j...@suse.cz>
Cc: Alexander Viro <v...@zeniv.linux.org.uk>
Cc: linux-fsde...@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Paul E. McKenney <paul...@linux.vnet.ibm.com>
Cc: Tim Chen <tim.c.c...@linux.intel.com>
Cc: Andi Kleen <a...@linux.intel.com>
Signed-off-by: Dave Hansen <dave.han...@linux.intel.com>
---

 b/fs/inode.c                         |    4 ++--
 b/fs/notify/fanotify/fanotify_user.c |    4 ++--
 b/fs/notify/fsnotify.c               |   12 ++++++------
 b/fs/notify/inode_mark.c             |   18 +++++++++---------
 b/fs/notify/inotify/inotify_user.c   |    2 +-
 b/include/linux/fs.h                 |    6 ++----
 b/include/linux/fsnotify_backend.h   |    8 ++++----
 b/include/linux/fsnotify_head.h      |   17 +++++++++++++++++
 b/kernel/auditsc.c                   |    4 ++--
 9 files changed, 45 insertions(+), 30 deletions(-)

diff -puN fs/inode.c~fsnotify_head fs/inode.c
--- a/fs/inode.c~fsnotify_head  2015-06-24 17:14:35.694159644 -0700
+++ b/fs/inode.c        2015-06-24 17:14:35.711160408 -0700
@@ -181,7 +181,7 @@ int inode_init_always(struct super_block
 #endif
 
 #ifdef CONFIG_FSNOTIFY
-       inode->i_fsnotify_mask = 0;
+       inode->i_fsnotify.mask = 0;
 #endif
        inode->i_flctx = NULL;
        this_cpu_inc(nr_inodes);
@@ -363,7 +363,7 @@ void inode_init_once(struct inode *inode
        address_space_init_once(&inode->i_data);
        i_size_ordered_init(inode);
 #ifdef CONFIG_FSNOTIFY
-       INIT_HLIST_HEAD(&inode->i_fsnotify_marks);
+       INIT_HLIST_HEAD(&inode->i_fsnotify.marks);
 #endif
 }
 EXPORT_SYMBOL(inode_init_once);
diff -puN fs/notify/fanotify/fanotify_user.c~fsnotify_head 
fs/notify/fanotify/fanotify_user.c
--- a/fs/notify/fanotify/fanotify_user.c~fsnotify_head  2015-06-24 
17:14:35.696159734 -0700
+++ b/fs/notify/fanotify/fanotify_user.c        2015-06-24 17:14:35.712160453 
-0700
@@ -562,7 +562,7 @@ static int fanotify_remove_inode_mark(st
 
        /* matches the fsnotify_find_inode_mark() */
        fsnotify_put_mark(fsn_mark);
-       if (removed & inode->i_fsnotify_mask)
+       if (removed & inode->i_fsnotify.mask)
                fsnotify_recalc_inode_mask(inode);
 
        return 0;
@@ -679,7 +679,7 @@ static int fanotify_add_inode_mark(struc
        added = fanotify_mark_add_to_mask(fsn_mark, mask, flags);
        mutex_unlock(&group->mark_mutex);
 
-       if (added & ~inode->i_fsnotify_mask)
+       if (added & ~inode->i_fsnotify.mask)
                fsnotify_recalc_inode_mask(inode);
 
        fsnotify_put_mark(fsn_mark);
diff -puN fs/notify/fsnotify.c~fsnotify_head fs/notify/fsnotify.c
--- a/fs/notify/fsnotify.c~fsnotify_head        2015-06-24 17:14:35.697159779 
-0700
+++ b/fs/notify/fsnotify.c      2015-06-24 17:14:35.712160453 -0700
@@ -104,7 +104,7 @@ int __fsnotify_parent(struct path *path,
 
        if (unlikely(!fsnotify_inode_watches_children(p_inode)))
                __fsnotify_update_child_dentry_flags(p_inode);
-       else if (p_inode->i_fsnotify_mask & mask) {
+       else if (p_inode->i_fsnotify.mask & mask) {
                /* we are notifying a parent so come up with the new mask which
                 * specifies these are events which came from a child. */
                mask |= FS_EVENT_ON_CHILD;
@@ -210,7 +210,7 @@ int fsnotify(struct inode *to_tell, __u3
         * this type of event.
         */
        if (!(mask & FS_MODIFY) &&
-           !(test_mask & to_tell->i_fsnotify_mask) &&
+           !(test_mask & to_tell->i_fsnotify.mask) &&
            !(mnt && test_mask & mnt->mnt_fsnotify_mask))
                return 0;
        /*
@@ -220,22 +220,22 @@ int fsnotify(struct inode *to_tell, __u3
         * SRCU because we have no references to any objects and do not
         * need SRCU to keep them "alive".
         */
-       if (!to_tell->i_fsnotify_marks.first &&
+       if (!to_tell->i_fsnotify.marks.first &&
            (!mnt || !mnt->mnt_fsnotify_marks.first))
                return 0;
 
        idx = srcu_read_lock(&fsnotify_mark_srcu);
 
        if ((mask & FS_MODIFY) ||
-           (test_mask & to_tell->i_fsnotify_mask))
-               inode_node = srcu_dereference(to_tell->i_fsnotify_marks.first,
+           (test_mask & to_tell->i_fsnotify.mask))
+               inode_node = srcu_dereference(to_tell->i_fsnotify.marks.first,
                                              &fsnotify_mark_srcu);
 
        if (mnt && ((mask & FS_MODIFY) ||
                    (test_mask & mnt->mnt_fsnotify_mask))) {
                vfsmount_node = srcu_dereference(mnt->mnt_fsnotify_marks.first,
                                                 &fsnotify_mark_srcu);
-               inode_node = srcu_dereference(to_tell->i_fsnotify_marks.first,
+               inode_node = srcu_dereference(to_tell->i_fsnotify.marks.first,
                                              &fsnotify_mark_srcu);
        }
 
diff -puN fs/notify/inode_mark.c~fsnotify_head fs/notify/inode_mark.c
--- a/fs/notify/inode_mark.c~fsnotify_head      2015-06-24 17:14:35.699159868 
-0700
+++ b/fs/notify/inode_mark.c    2015-06-24 17:14:35.712160453 -0700
@@ -31,13 +31,13 @@
 #include "../internal.h"
 
 /*
- * Recalculate the inode->i_fsnotify_mask, or the mask of all FS_* event types
+ * Recalculate the inode->i_fsnotify.mask, or the mask of all FS_* event types
  * any notifier is interested in hearing for this inode.
  */
 void fsnotify_recalc_inode_mask(struct inode *inode)
 {
        spin_lock(&inode->i_lock);
-       inode->i_fsnotify_mask = fsnotify_recalc_mask(&inode->i_fsnotify_marks);
+       inode->i_fsnotify.mask = fsnotify_recalc_mask(&inode->i_fsnotify.marks);
        spin_unlock(&inode->i_lock);
 
        __fsnotify_update_child_dentry_flags(inode);
@@ -56,11 +56,11 @@ void fsnotify_destroy_inode_mark(struct
        mark->inode = NULL;
 
        /*
-        * this mark is now off the inode->i_fsnotify_marks list and we
+        * this mark is now off the inode->i_fsnotify.marks list and we
         * hold the inode->i_lock, so this is the perfect time to update the
-        * inode->i_fsnotify_mask
+        * inode->i_fsnotify.mask
         */
-       inode->i_fsnotify_mask = fsnotify_recalc_mask(&inode->i_fsnotify_marks);
+       inode->i_fsnotify.mask = fsnotify_recalc_mask(&inode->i_fsnotify.marks);
        spin_unlock(&inode->i_lock);
 }
 
@@ -74,7 +74,7 @@ void fsnotify_clear_marks_by_inode(struc
        LIST_HEAD(free_list);
 
        spin_lock(&inode->i_lock);
-       hlist_for_each_entry_safe(mark, n, &inode->i_fsnotify_marks, obj_list) {
+       hlist_for_each_entry_safe(mark, n, &inode->i_fsnotify.marks, obj_list) {
                list_add(&mark->free_list, &free_list);
                hlist_del_init_rcu(&mark->obj_list);
                fsnotify_get_mark(mark);
@@ -102,7 +102,7 @@ struct fsnotify_mark *fsnotify_find_inod
        struct fsnotify_mark *mark;
 
        spin_lock(&inode->i_lock);
-       mark = fsnotify_find_mark(&inode->i_fsnotify_marks, group);
+       mark = fsnotify_find_mark(&inode->i_fsnotify.marks, group);
        spin_unlock(&inode->i_lock);
 
        return mark;
@@ -153,9 +153,9 @@ int fsnotify_add_inode_mark(struct fsnot
 
        spin_lock(&inode->i_lock);
        mark->inode = inode;
-       ret = fsnotify_add_mark_list(&inode->i_fsnotify_marks, mark,
+       ret = fsnotify_add_mark_list(&inode->i_fsnotify.marks, mark,
                                     allow_dups);
-       inode->i_fsnotify_mask = fsnotify_recalc_mask(&inode->i_fsnotify_marks);
+       inode->i_fsnotify.mask = fsnotify_recalc_mask(&inode->i_fsnotify.marks);
        spin_unlock(&inode->i_lock);
 
        return ret;
diff -puN fs/notify/inotify/inotify_user.c~fsnotify_head 
fs/notify/inotify/inotify_user.c
--- a/fs/notify/inotify/inotify_user.c~fsnotify_head    2015-06-24 
17:14:35.701159959 -0700
+++ b/fs/notify/inotify/inotify_user.c  2015-06-24 17:14:35.713160498 -0700
@@ -547,7 +547,7 @@ static int inotify_update_existing_watch
                /* more bits in old than in new? */
                int dropped = (old_mask & ~new_mask);
                /* more bits in this fsn_mark than the inode's mask? */
-               int do_inode = (new_mask & ~inode->i_fsnotify_mask);
+               int do_inode = (new_mask & ~inode->i_fsnotify.mask);
 
                /* update the inode with this new fsn_mark */
                if (dropped || do_inode)
diff -puN include/linux/fs.h~fsnotify_head include/linux/fs.h
--- a/include/linux/fs.h~fsnotify_head  2015-06-24 17:14:35.702160003 -0700
+++ b/include/linux/fs.h        2015-06-24 17:14:35.710160363 -0700
@@ -30,6 +30,7 @@
 #include <linux/lockdep.h>
 #include <linux/percpu-rwsem.h>
 #include <linux/blk_types.h>
+#include <linux/fsnotify_head.h>
 
 #include <asm/byteorder.h>
 #include <uapi/linux/fs.h>
@@ -660,10 +661,7 @@ struct inode {
 
        __u32                   i_generation;
 
-#ifdef CONFIG_FSNOTIFY
-       __u32                   i_fsnotify_mask; /* all events this inode cares 
about */
-       struct hlist_head       i_fsnotify_marks;
-#endif
+       struct fsnotify_head    i_fsnotify;
 
        void                    *i_private; /* fs or device private pointer */
 };
diff -puN include/linux/fsnotify_backend.h~fsnotify_head 
include/linux/fsnotify_backend.h
--- a/include/linux/fsnotify_backend.h~fsnotify_head    2015-06-24 
17:14:35.704160093 -0700
+++ b/include/linux/fsnotify_backend.h  2015-06-24 17:14:35.709160318 -0700
@@ -212,7 +212,7 @@ struct fsnotify_mark {
         * in kernel that found and may be using this mark. */
        atomic_t refcnt;                /* active things looking at this mark */
        struct fsnotify_group *group;   /* group this mark is for */
-       struct list_head g_list;        /* list of marks by 
group->i_fsnotify_marks
+       struct list_head g_list;        /* list of marks by group->marks_list
                                         * Also reused for queueing mark into
                                         * destroy_list when it's waiting for
                                         * the end of SRCU period before it can
@@ -249,11 +249,11 @@ extern u32 fsnotify_get_cookie(void);
 static inline int fsnotify_inode_watches_children(struct inode *inode)
 {
        /* FS_EVENT_ON_CHILD is set if the inode may care */
-       if (!(inode->i_fsnotify_mask & FS_EVENT_ON_CHILD))
+       if (!(inode->i_fsnotify.mask & FS_EVENT_ON_CHILD))
                return 0;
        /* this inode might care about child events, does it care about the
         * specific set of events that can happen on a child? */
-       return inode->i_fsnotify_mask & FS_EVENTS_POSS_ON_CHILD;
+       return inode->i_fsnotify.mask & FS_EVENTS_POSS_ON_CHILD;
 }
 
 /*
@@ -326,7 +326,7 @@ extern struct fsnotify_event *fsnotify_r
 
 /* run all marks associated with a vfsmount and update mnt->mnt_fsnotify_mask 
*/
 extern void fsnotify_recalc_vfsmount_mask(struct vfsmount *mnt);
-/* run all marks associated with an inode and update inode->i_fsnotify_mask */
+/* run all marks associated with an inode and update inode->i_fsnotify.mask */
 extern void fsnotify_recalc_inode_mask(struct inode *inode);
 extern void fsnotify_init_mark(struct fsnotify_mark *mark, void 
(*free_mark)(struct fsnotify_mark *mark));
 /* find (and take a reference) to a mark associated with group and inode */
diff -puN /dev/null include/linux/fsnotify_head.h
--- /dev/null   2015-06-17 12:44:31.632705131 -0700
+++ b/include/linux/fsnotify_head.h     2015-06-24 17:14:35.711160408 -0700
@@ -0,0 +1,17 @@
+#ifndef __LINUX_FSNOTIFY_HEAD_H
+#define __LINUX_FSNOTIFY_HEAD_H
+
+#include <linux/types.h>
+
+/*
+ * This gets embedded in vfsmounts and inodes.
+ */
+
+struct fsnotify_head {
+#ifdef CONFIG_FSNOTIFY
+       __u32                   mask; /* all events this object cares about */
+       struct hlist_head       marks;
+#endif
+};
+
+#endif /* __LINUX_FSNOTIFY_HEAD_H */
diff -puN kernel/auditsc.c~fsnotify_head kernel/auditsc.c
--- a/kernel/auditsc.c~fsnotify_head    2015-06-24 17:14:35.706160183 -0700
+++ b/kernel/auditsc.c  2015-06-24 17:14:35.714160543 -0700
@@ -1587,7 +1587,7 @@ static inline void handle_one(const stru
        struct audit_tree_refs *p;
        struct audit_chunk *chunk;
        int count;
-       if (likely(hlist_empty(&inode->i_fsnotify_marks)))
+       if (likely(hlist_empty(&inode->i_fsnotify.marks)))
                return;
        context = current->audit_context;
        p = context->trees;
@@ -1630,7 +1630,7 @@ retry:
        seq = read_seqbegin(&rename_lock);
        for(;;) {
                struct inode *inode = d_backing_inode(d);
-               if (inode && unlikely(!hlist_empty(&inode->i_fsnotify_marks))) {
+               if (inode && unlikely(!hlist_empty(&inode->i_fsnotify.marks))) {
                        struct audit_chunk *chunk;
                        chunk = audit_tree_lookup(inode);
                        if (chunk) {
_
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to