From: Amir Goldstein <amir73il@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: linux-fsdevel@vger.kernel.org
Subject: [PATCH v3 12/13] fsnotify: let connector point to abstract fsnotify_obj
Date: Fri, 20 Apr 2018 16:11:00 -0700 [thread overview]
Message-ID: <1524265861-6316-13-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1524265861-6316-1-git-send-email-amir73il@gmail.com>
Make the code to attach/detach a connector to object more generic
by letting the fsnotify connector point to the abstract fsnotify_obj.
Code that needs to dereference an inode or mount object now uses the
macros fsnotify_obj_{inode,mount}.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/notify/fdinfo.c | 2 +-
fs/notify/mark.c | 35 ++++++++++++++---------------------
include/linux/fsnotify_backend.h | 8 ++++----
3 files changed, 19 insertions(+), 26 deletions(-)
diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c
index b3cf03e347a8..725c92bf2dc3 100644
--- a/fs/notify/fdinfo.c
+++ b/fs/notify/fdinfo.c
@@ -127,7 +127,7 @@ static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark)
seq_putc(m, '\n');
iput(inode);
} else if (mark->connector->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) {
- struct mount *mnt = real_mount(mark->connector->mnt);
+ struct mount *mnt = fsnotify_obj_mount(mark->connector->obj);
seq_printf(m, "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x\n",
mnt->mnt_id, mflags, mark->mask, mark->ignored_mask);
diff --git a/fs/notify/mark.c b/fs/notify/mark.c
index 7103a0a442e7..9642d6c14bfc 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -119,15 +119,12 @@ static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn)
if (mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED)
new_mask |= mark->mask;
}
- if (conn->type == FSNOTIFY_OBJ_TYPE_INODE)
- conn->inode->i_fsnotify.mask = new_mask;
- else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT)
- real_mount(conn->mnt)->mnt_fsnotify.mask = new_mask;
+ conn->obj->mask = new_mask;
}
/*
* Calculate mask of events for a list of marks. The caller must make sure
- * connector and connector->inode cannot disappear under us. Callers achieve
+ * connector and connector->obj cannot disappear under us. Callers achieve
* this by holding a mark->lock or mark->group->mark_mutex for a mark on this
* list.
*/
@@ -167,19 +164,16 @@ static struct inode *fsnotify_detach_connector_from_object(
{
struct inode *inode = NULL;
- if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) {
- inode = conn->inode;
- rcu_assign_pointer(inode->i_fsnotify.marks, NULL);
- inode->i_fsnotify.mask = 0;
- conn->inode = NULL;
- conn->type = FSNOTIFY_OBJ_TYPE_DETACHED;
- } else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) {
- rcu_assign_pointer(real_mount(conn->mnt)->mnt_fsnotify.marks,
- NULL);
- real_mount(conn->mnt)->mnt_fsnotify.mask = 0;
- conn->mnt = NULL;
- conn->type = FSNOTIFY_OBJ_TYPE_DETACHED;
- }
+ if (conn->type == FSNOTIFY_OBJ_TYPE_DETACHED)
+ return NULL;
+
+ if (conn->type == FSNOTIFY_OBJ_TYPE_INODE)
+ inode = fsnotify_obj_inode(conn->obj);
+
+ rcu_assign_pointer(conn->obj->marks, NULL);
+ conn->obj->mask = 0;
+ conn->obj = NULL;
+ conn->type = FSNOTIFY_OBJ_TYPE_DETACHED;
return inode;
}
@@ -449,10 +443,9 @@ static int fsnotify_attach_connector_to_object(struct fsnotify_obj *obj,
spin_lock_init(&conn->lock);
INIT_HLIST_HEAD(&conn->list);
conn->type = type;
+ conn->obj = obj;
if (conn->type == FSNOTIFY_OBJ_TYPE_INODE)
- inode = conn->inode = igrab(fsnotify_obj_inode(obj));
- else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT)
- conn->mnt = &fsnotify_obj_mount(obj)->mnt;
+ inode = igrab(fsnotify_obj_inode(obj));
/*
* cmpxchg() provides the barrier so that readers of obj->marks can see
* only initialized structure
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 6e9397c16124..b7ba56b9feb8 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -265,9 +265,9 @@ FSNOTIFY_ITER_FUNCS(vfsmount, VFSMOUNT)
struct fsnotify_mark_connector {
spinlock_t lock;
unsigned int type; /* Type of object [lock] */
- union { /* Object pointer [lock] */
- struct inode *inode;
- struct vfsmount *mnt;
+ union {
+ /* Object pointer [lock] */
+ struct fsnotify_obj *obj;
/* Used listing heads to free after srcu period expires */
struct fsnotify_mark_connector *destroy_next;
};
@@ -282,7 +282,7 @@ static inline struct inode *fsnotify_obj_inode(struct fsnotify_obj *obj)
static inline struct inode *fsnotify_connector_inode(
struct fsnotify_mark_connector *conn)
{
- return conn->inode;
+ return fsnotify_obj_inode(conn->obj);
}
/*
--
2.7.4
next prev parent reply other threads:[~2018-04-20 23:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-20 23:10 [PATCH v3 00/13] Preparing for fanotify super block marks Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 01/13] fsnotify: use type id to identify connector object type Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 02/13] fsnotify: remove redundant arguments to handle_event() Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 03/13] fsnotify: introduce marks iteration helpers Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 04/13] fsnotify: generalize iteration of marks by object type Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 05/13] fsnotify: generalize send_to_group() Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 06/13] fanotify: generalize fanotify_should_send_event() Amir Goldstein
2018-05-18 10:47 ` Jan Kara
2018-04-20 23:10 ` [PATCH v3 07/13] fsnotify: add fsnotify_add_inode_mark() wrappers Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 08/13] fsnotify: introduce prototype struct fsnotify_obj Amir Goldstein
2018-05-18 12:02 ` Jan Kara
2018-04-20 23:10 ` [PATCH v3 09/13] fsnotify: pass fsnotify_obj instead of **connp argument Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 10/13] fsnotify: pass object and object type to fsnotify_add_mark() Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 11/13] fsnotify: add fsnotify_connector_inode() wrapper Amir Goldstein
2018-05-18 12:48 ` Jan Kara
2018-04-20 23:11 ` Amir Goldstein [this message]
2018-04-20 23:11 ` [PATCH v3 13/13] fanotify: factor out helpers to add/remove mark Amir Goldstein
2018-05-18 13:09 ` [PATCH v3 00/13] Preparing for fanotify super block marks Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1524265861-6316-13-git-send-email-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).