Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 86ffe245 authored by Jan Kara's avatar Jan Kara
Browse files

fsnotify: Move object pointer to fsnotify_mark_connector



Move pointer to inode / vfsmount from mark itself to the
fsnotify_mark_connector structure. This is another step on the path
towards decoupling inode / vfsmount lifetime from notification mark
lifetime.

Reviewed-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Reviewed-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent 9dd813c1
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -69,8 +69,8 @@ static void dnotify_recalc_inode_mask(struct fsnotify_mark *fsn_mark)
	if (old_mask == new_mask)
		return;

	if (fsn_mark->inode)
		fsnotify_recalc_inode_mask(fsn_mark->inode);
	if (fsn_mark->connector)
		fsnotify_recalc_inode_mask(fsn_mark->connector->inode);
}

/*
+6 −6
Original line number Diff line number Diff line
@@ -76,11 +76,11 @@ static void inotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark)
	struct inotify_inode_mark *inode_mark;
	struct inode *inode;

	if (!(mark->flags & FSNOTIFY_MARK_FLAG_INODE))
	if (!(mark->connector->flags & FSNOTIFY_OBJ_TYPE_INODE))
		return;

	inode_mark = container_of(mark, struct inotify_inode_mark, fsn_mark);
	inode = igrab(mark->inode);
	inode = igrab(mark->connector->inode);
	if (inode) {
		/*
		 * IN_ALL_EVENTS represents all of the mask bits
@@ -115,8 +115,8 @@ static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark)
	if (mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY)
		mflags |= FAN_MARK_IGNORED_SURV_MODIFY;

	if (mark->flags & FSNOTIFY_MARK_FLAG_INODE) {
		inode = igrab(mark->inode);
	if (mark->connector->flags & FSNOTIFY_OBJ_TYPE_INODE) {
		inode = igrab(mark->connector->inode);
		if (!inode)
			return;
		seq_printf(m, "fanotify ino:%lx sdev:%x mflags:%x mask:%x ignored_mask:%x ",
@@ -125,8 +125,8 @@ static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark)
		show_mark_fhandle(m, inode);
		seq_putc(m, '\n');
		iput(inode);
	} else if (mark->flags & FSNOTIFY_MARK_FLAG_VFSMOUNT) {
		struct mount *mnt = real_mount(mark->mnt);
	} else if (mark->connector->flags & FSNOTIFY_OBJ_TYPE_VFSMOUNT) {
		struct mount *mnt = real_mount(mark->connector->mnt);

		seq_printf(m, "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x\n",
			   mnt->mnt_id, mflags, mark->mask, mark->ignored_mask);
+2 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ extern void fsnotify_set_inode_mark_mask_locked(struct fsnotify_mark *fsn_mark,
/* Add mark to a proper place in mark list */
extern int fsnotify_add_mark_list(struct fsnotify_mark_connector **connp,
				  struct fsnotify_mark *mark,
				  struct inode *inode, struct vfsmount *mnt,
				  int allow_dups);
/* add a mark to an inode */
extern int fsnotify_add_inode_mark(struct fsnotify_mark *mark,
@@ -44,7 +45,7 @@ extern void fsnotify_destroy_inode_mark(struct fsnotify_mark *mark);
extern struct fsnotify_mark *fsnotify_find_mark(
					struct fsnotify_mark_connector *conn,
					struct fsnotify_group *group);
/* Destroy all marks in the given list protected by 'lock' */
/* Destroy all marks connected via given connector protected by 'lock' */
extern void fsnotify_destroy_marks(struct fsnotify_mark_connector *conn,
				   spinlock_t *lock);
/* run the list of all marks associated with inode and destroy them */
+7 −11
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ void fsnotify_recalc_inode_mask(struct inode *inode)

void fsnotify_destroy_inode_mark(struct fsnotify_mark *mark)
{
	struct inode *inode = mark->inode;
	struct inode *inode = mark->connector->inode;

	BUG_ON(!mutex_is_locked(&mark->group->mark_mutex));
	assert_spin_locked(&mark->lock);
@@ -53,7 +53,7 @@ void fsnotify_destroy_inode_mark(struct fsnotify_mark *mark)
	spin_lock(&inode->i_lock);

	hlist_del_init_rcu(&mark->obj_list);
	mark->inode = NULL;
	mark->connector = NULL;

	/*
	 * this mark is now off the inode->i_fsnotify_marks list and we
@@ -69,7 +69,7 @@ void fsnotify_destroy_inode_mark(struct fsnotify_mark *mark)
 */
void fsnotify_clear_inode_marks_by_group(struct fsnotify_group *group)
{
	fsnotify_clear_marks_by_group_flags(group, FSNOTIFY_MARK_FLAG_INODE);
	fsnotify_clear_marks_by_group_flags(group, FSNOTIFY_OBJ_TYPE_INODE);
}

/*
@@ -99,11 +99,10 @@ void fsnotify_set_inode_mark_mask_locked(struct fsnotify_mark *mark,

	assert_spin_locked(&mark->lock);

	if (mask &&
	    mark->inode &&
	if (mask && mark->connector &&
	    !(mark->flags & FSNOTIFY_MARK_FLAG_OBJECT_PINNED)) {
		mark->flags |= FSNOTIFY_MARK_FLAG_OBJECT_PINNED;
		inode = igrab(mark->inode);
		inode = igrab(mark->connector->inode);
		/*
		 * we shouldn't be able to get here if the inode wasn't
		 * already safely held in memory.  But bug in case it
@@ -126,15 +125,12 @@ int fsnotify_add_inode_mark(struct fsnotify_mark *mark,
{
	int ret;

	mark->flags |= FSNOTIFY_MARK_FLAG_INODE;

	BUG_ON(!mutex_is_locked(&group->mark_mutex));
	assert_spin_locked(&mark->lock);

	spin_lock(&inode->i_lock);
	mark->inode = inode;
	ret = fsnotify_add_mark_list(&inode->i_fsnotify_marks, mark,
				     allow_dups);
	ret = fsnotify_add_mark_list(&inode->i_fsnotify_marks, mark, inode,
				     NULL, allow_dups);
	inode->i_fsnotify_mask = fsnotify_recalc_mask(inode->i_fsnotify_marks);
	spin_unlock(&inode->i_lock);

+22 −10
Original line number Diff line number Diff line
@@ -142,10 +142,10 @@ void fsnotify_detach_mark(struct fsnotify_mark *mark)

	mark->flags &= ~FSNOTIFY_MARK_FLAG_ATTACHED;

	if (mark->flags & FSNOTIFY_MARK_FLAG_INODE) {
		inode = mark->inode;
	if (mark->connector->flags & FSNOTIFY_OBJ_TYPE_INODE) {
		inode = mark->connector->inode;
		fsnotify_destroy_inode_mark(mark);
	} else if (mark->flags & FSNOTIFY_MARK_FLAG_VFSMOUNT)
	} else if (mark->connector->flags & FSNOTIFY_OBJ_TYPE_VFSMOUNT)
		fsnotify_destroy_vfsmount_mark(mark);
	else
		BUG();
@@ -275,7 +275,7 @@ void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)

	mark->mask = mask;

	if (mark->flags & FSNOTIFY_MARK_FLAG_INODE)
	if (mark->connector && mark->connector->flags & FSNOTIFY_OBJ_TYPE_INODE)
		fsnotify_set_inode_mark_mask_locked(mark, mask);
}

@@ -323,7 +323,9 @@ int fsnotify_compare_groups(struct fsnotify_group *a, struct fsnotify_group *b)
}

static int fsnotify_attach_connector_to_object(
					struct fsnotify_mark_connector **connp)
					struct fsnotify_mark_connector **connp,
					struct inode *inode,
					struct vfsmount *mnt)
{
	struct fsnotify_mark_connector *conn;

@@ -331,6 +333,13 @@ static int fsnotify_attach_connector_to_object(
	if (!conn)
		return -ENOMEM;
	INIT_HLIST_HEAD(&conn->list);
	if (inode) {
		conn->flags = FSNOTIFY_OBJ_TYPE_INODE;
		conn->inode = inode;
	} else {
		conn->flags = FSNOTIFY_OBJ_TYPE_VFSMOUNT;
		conn->mnt = mnt;
	}
	/*
	 * Make sure 'conn' initialization is visible. Matches
	 * lockless_dereference() in fsnotify().
@@ -348,7 +357,8 @@ static int fsnotify_attach_connector_to_object(
 * priority, highest number first, and then by the group's location in memory.
 */
int fsnotify_add_mark_list(struct fsnotify_mark_connector **connp,
			   struct fsnotify_mark *mark, int allow_dups)
			   struct fsnotify_mark *mark, struct inode *inode,
			   struct vfsmount *mnt, int allow_dups)
{
	struct fsnotify_mark *lmark, *last = NULL;
	struct fsnotify_mark_connector *conn;
@@ -356,7 +366,7 @@ int fsnotify_add_mark_list(struct fsnotify_mark_connector **connp,
	int err;

	if (!*connp) {
		err = fsnotify_attach_connector_to_object(connp);
		err = fsnotify_attach_connector_to_object(connp, inode, mnt);
		if (err)
			return err;
	}
@@ -365,7 +375,7 @@ int fsnotify_add_mark_list(struct fsnotify_mark_connector **connp,
	/* is mark the first mark? */
	if (hlist_empty(&conn->list)) {
		hlist_add_head_rcu(&mark->obj_list, &conn->list);
		return 0;
		goto added;
	}

	/* should mark be in the middle of the current list? */
@@ -378,13 +388,15 @@ int fsnotify_add_mark_list(struct fsnotify_mark_connector **connp,
		cmp = fsnotify_compare_groups(lmark->group, mark->group);
		if (cmp >= 0) {
			hlist_add_before_rcu(&mark->obj_list, &lmark->obj_list);
			return 0;
			goto added;
		}
	}

	BUG_ON(last == NULL);
	/* mark should be the last entry.  last is the current last entry */
	hlist_add_behind_rcu(&mark->obj_list, &last->obj_list);
added:
	mark->connector = conn;
	return 0;
}

@@ -507,7 +519,7 @@ void fsnotify_clear_marks_by_group_flags(struct fsnotify_group *group,
	 */
	mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING);
	list_for_each_entry_safe(mark, lmark, &group->marks_list, g_list) {
		if (mark->flags & flags)
		if (mark->connector->flags & flags)
			list_move(&mark->g_list, &to_free);
	}
	mutex_unlock(&group->mark_mutex);
Loading