diff mbox

[v3,12/13] fsnotify: let connector point to abstract fsnotify_obj

Message ID 1524265861-6316-13-git-send-email-amir73il@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Amir Goldstein April 20, 2018, 11:11 p.m. UTC
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 mbox

Patch

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);
 }
 
 /*