From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f196.google.com ([209.85.192.196]:46618 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752245AbeDTXJw (ORCPT ); Fri, 20 Apr 2018 19:09:52 -0400 Received: by mail-pf0-f196.google.com with SMTP id h69so4898261pfe.13 for ; Fri, 20 Apr 2018 16:09:52 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 09/13] fsnotify: pass fsnotify_obj instead of **connp argument Date: Fri, 20 Apr 2018 16:10:57 -0700 Message-Id: <1524265861-6316-10-git-send-email-amir73il@gmail.com> In-Reply-To: <1524265861-6316-1-git-send-email-amir73il@gmail.com> References: <1524265861-6316-1-git-send-email-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: The object marks manipulation functions fsnotify_destroy_marks() fsnotify_find_mark() and their helpers take a **connp argument to dereference the connector pointer. Pass the container fsnotify_obj pointer argument instead to prepare for more cleanups. Signed-off-by: Amir Goldstein --- fs/notify/dnotify/dnotify.c | 4 ++-- fs/notify/fanotify/fanotify_user.c | 10 ++++----- fs/notify/fsnotify.h | 8 ++++---- fs/notify/inotify/inotify_user.c | 2 +- fs/notify/mark.c | 42 ++++++++++++++++++-------------------- include/linux/fsnotify_backend.h | 7 +++---- kernel/audit_tree.c | 3 +-- kernel/audit_watch.c | 2 +- 8 files changed, 36 insertions(+), 42 deletions(-) diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c index d46167c69c99..c7a74ee4b7a3 100644 --- a/fs/notify/dnotify/dnotify.c +++ b/fs/notify/dnotify/dnotify.c @@ -158,7 +158,7 @@ void dnotify_flush(struct file *filp, fl_owner_t id) if (!S_ISDIR(inode->i_mode)) return; - fsn_mark = fsnotify_find_mark(&inode->i_fsnotify.marks, dnotify_group); + fsn_mark = fsnotify_find_mark(&inode->i_fsnotify, dnotify_group); if (!fsn_mark) return; dn_mark = container_of(fsn_mark, struct dnotify_mark, fsn_mark); @@ -314,7 +314,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg) mutex_lock(&dnotify_group->mark_mutex); /* add the new_fsn_mark or find an old one. */ - fsn_mark = fsnotify_find_mark(&inode->i_fsnotify.marks, dnotify_group); + fsn_mark = fsnotify_find_mark(&inode->i_fsnotify, dnotify_group); if (fsn_mark) { dn_mark = container_of(fsn_mark, struct dnotify_mark, fsn_mark); spin_lock(&fsn_mark->lock); diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index ed87880c42f0..c15de35c3ebc 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -533,8 +533,7 @@ static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group, int destroy_mark; mutex_lock(&group->mark_mutex); - fsn_mark = fsnotify_find_mark(&real_mount(mnt)->mnt_fsnotify.marks, - group); + fsn_mark = fsnotify_find_mark(&real_mount(mnt)->mnt_fsnotify, group); if (!fsn_mark) { mutex_unlock(&group->mark_mutex); return -ENOENT; @@ -563,7 +562,7 @@ static int fanotify_remove_inode_mark(struct fsnotify_group *group, int destroy_mark; mutex_lock(&group->mark_mutex); - fsn_mark = fsnotify_find_mark(&inode->i_fsnotify.marks, group); + fsn_mark = fsnotify_find_mark(&inode->i_fsnotify, group); if (!fsn_mark) { mutex_unlock(&group->mark_mutex); return -ENOENT; @@ -647,8 +646,7 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group, __u32 added; mutex_lock(&group->mark_mutex); - fsn_mark = fsnotify_find_mark(&real_mount(mnt)->mnt_fsnotify.marks, - group); + fsn_mark = fsnotify_find_mark(&real_mount(mnt)->mnt_fsnotify, group); if (!fsn_mark) { fsn_mark = fanotify_add_new_mark(group, NULL, mnt); if (IS_ERR(fsn_mark)) { @@ -685,7 +683,7 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group, return 0; mutex_lock(&group->mark_mutex); - fsn_mark = fsnotify_find_mark(&inode->i_fsnotify.marks, group); + fsn_mark = fsnotify_find_mark(&inode->i_fsnotify, group); if (!fsn_mark) { fsn_mark = fanotify_add_new_mark(group, inode, NULL); if (IS_ERR(fsn_mark)) { diff --git a/fs/notify/fsnotify.h b/fs/notify/fsnotify.h index 8f4d3e43b5b5..6459481c964f 100644 --- a/fs/notify/fsnotify.h +++ b/fs/notify/fsnotify.h @@ -19,17 +19,17 @@ extern struct srcu_struct fsnotify_mark_srcu; extern int fsnotify_compare_groups(struct fsnotify_group *a, struct fsnotify_group *b); -/* Destroy all marks connected via given connector */ -extern void fsnotify_destroy_marks(struct fsnotify_mark_connector __rcu **connp); +/* Destroy all marks connected to a given object */ +extern void fsnotify_destroy_marks(struct fsnotify_obj *obj); /* run the list of all marks associated with inode and destroy them */ static inline void fsnotify_clear_marks_by_inode(struct inode *inode) { - fsnotify_destroy_marks(&inode->i_fsnotify.marks); + fsnotify_destroy_marks(&inode->i_fsnotify); } /* run the list of all marks associated with vfsmount and destroy them */ static inline void fsnotify_clear_marks_by_mount(struct vfsmount *mnt) { - fsnotify_destroy_marks(&real_mount(mnt)->mnt_fsnotify.marks); + fsnotify_destroy_marks(&real_mount(mnt)->mnt_fsnotify); } /* Wait until all marks queued for destruction are destroyed */ extern void fsnotify_wait_marks_destroyed(void); diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c index 8eaa3b468b5c..0ef8e2be7ee5 100644 --- a/fs/notify/inotify/inotify_user.c +++ b/fs/notify/inotify/inotify_user.c @@ -514,7 +514,7 @@ static int inotify_update_existing_watch(struct fsnotify_group *group, mask = inotify_arg_to_mask(arg); - fsn_mark = fsnotify_find_mark(&inode->i_fsnotify.marks, group); + fsn_mark = fsnotify_find_mark(&inode->i_fsnotify, group); if (!fsn_mark) return -ENOENT; diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 4f0c17e5db53..2cd2a872bd66 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -436,10 +436,9 @@ int fsnotify_compare_groups(struct fsnotify_group *a, struct fsnotify_group *b) return -1; } -static int fsnotify_attach_connector_to_object( - struct fsnotify_mark_connector __rcu **connp, - struct inode *inode, - struct vfsmount *mnt) +static int fsnotify_attach_connector_to_object(struct fsnotify_obj *obj, + struct inode *inode, + struct vfsmount *mnt) { struct fsnotify_mark_connector *conn; @@ -456,10 +455,10 @@ static int fsnotify_attach_connector_to_object( conn->mnt = mnt; } /* - * cmpxchg() provides the barrier so that readers of *connp can see + * cmpxchg() provides the barrier so that readers of obj->marks can see * only initialized structure */ - if (cmpxchg(connp, NULL, conn)) { + if (cmpxchg(&obj->marks, NULL, conn)) { /* Someone else created list structure for us */ if (inode) iput(inode); @@ -476,13 +475,13 @@ static int fsnotify_attach_connector_to_object( * they are sure list cannot go away under them. */ static struct fsnotify_mark_connector *fsnotify_grab_connector( - struct fsnotify_mark_connector __rcu **connp) + struct fsnotify_obj *obj) { struct fsnotify_mark_connector *conn; int idx; idx = srcu_read_lock(&fsnotify_mark_srcu); - conn = srcu_dereference(*connp, &fsnotify_mark_srcu); + conn = srcu_dereference(obj->marks, &fsnotify_mark_srcu); if (!conn) goto out; spin_lock(&conn->lock); @@ -508,22 +507,22 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark, { struct fsnotify_mark *lmark, *last = NULL; struct fsnotify_mark_connector *conn; - struct fsnotify_mark_connector __rcu **connp; + struct fsnotify_obj *obj; int cmp; int err = 0; if (WARN_ON(!inode && !mnt)) return -EINVAL; if (inode) - connp = &inode->i_fsnotify.marks; + obj = &inode->i_fsnotify; else - connp = &real_mount(mnt)->mnt_fsnotify.marks; + obj = &real_mount(mnt)->mnt_fsnotify; restart: spin_lock(&mark->lock); - conn = fsnotify_grab_connector(connp); + conn = fsnotify_grab_connector(obj); if (!conn) { spin_unlock(&mark->lock); - err = fsnotify_attach_connector_to_object(connp, inode, mnt); + err = fsnotify_attach_connector_to_object(obj, inode, mnt); if (err) return err; goto restart; @@ -626,17 +625,16 @@ int fsnotify_add_mark(struct fsnotify_mark *mark, struct inode *inode, } /* - * Given a list of marks, find the mark associated with given group. If found - * take a reference to that mark and return it, else return NULL. + * Given a list of object marks, find the mark associated with given group. + * If found take a reference to that mark and return it, else return NULL. */ -struct fsnotify_mark *fsnotify_find_mark( - struct fsnotify_mark_connector __rcu **connp, - struct fsnotify_group *group) +struct fsnotify_mark *fsnotify_find_mark(struct fsnotify_obj *obj, + struct fsnotify_group *group) { struct fsnotify_mark_connector *conn; struct fsnotify_mark *mark; - conn = fsnotify_grab_connector(connp); + conn = fsnotify_grab_connector(obj); if (!conn) return NULL; @@ -697,14 +695,14 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group, } } -/* Destroy all marks attached to inode / vfsmount */ -void fsnotify_destroy_marks(struct fsnotify_mark_connector __rcu **connp) +/* Destroy all marks attached to an object */ +void fsnotify_destroy_marks(struct fsnotify_obj *obj) { struct fsnotify_mark_connector *conn; struct fsnotify_mark *mark, *old_mark = NULL; struct inode *inode; - conn = fsnotify_grab_connector(connp); + conn = fsnotify_grab_connector(obj); if (!conn) return; /* diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index a2cd8c51860e..15ea4661995d 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -399,10 +399,9 @@ extern struct fsnotify_event *fsnotify_remove_first_event(struct fsnotify_group extern void fsnotify_recalc_mask(struct fsnotify_mark_connector *conn); extern void fsnotify_init_mark(struct fsnotify_mark *mark, struct fsnotify_group *group); -/* Find mark belonging to given group in the list of marks */ -extern struct fsnotify_mark *fsnotify_find_mark( - struct fsnotify_mark_connector __rcu **connp, - struct fsnotify_group *group); +/* Find mark belonging to given group in the list of object marks */ +extern struct fsnotify_mark *fsnotify_find_mark(struct fsnotify_obj *obj, + struct fsnotify_group *group); /* attach the mark to the inode or vfsmount */ extern int fsnotify_add_mark(struct fsnotify_mark *mark, struct inode *inode, struct vfsmount *mnt, int allow_dups); diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c index 0124eb3999a5..eadee98f5a12 100644 --- a/kernel/audit_tree.c +++ b/kernel/audit_tree.c @@ -393,8 +393,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) struct node *p; int n; - old_entry = fsnotify_find_mark(&inode->i_fsnotify.marks, - audit_tree_group); + old_entry = fsnotify_find_mark(&inode->i_fsnotify, audit_tree_group); if (!old_entry) return create_chunk(inode, tree); diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c index 1b017875b8d2..cafec7b3985f 100644 --- a/kernel/audit_watch.c +++ b/kernel/audit_watch.c @@ -103,7 +103,7 @@ static inline struct audit_parent *audit_find_parent(struct inode *inode) struct audit_parent *parent = NULL; struct fsnotify_mark *entry; - entry = fsnotify_find_mark(&inode->i_fsnotify.marks, audit_watch_group); + entry = fsnotify_find_mark(&inode->i_fsnotify, audit_watch_group); if (entry) parent = container_of(entry, struct audit_parent, mark); -- 2.7.4