[PATCH 4/6 v10] fs: New helper legitimize_mntget() for getting a legitimize mnt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



New helper legitimize_mntget for getting a mnt without setting
MNT_SYNC_UMOUNT | MNT_UMOUNT | MNT_DOOMED, otherwise return NULL.

v9, Update using read_seqbegin_or_lock instead read_seqlock_excl
v10, fix bad logical of using seqlock

Signed-off-by: Kinglong Mee <kinglongmee@xxxxxxxxx>
---
 fs/namespace.c        | 38 ++++++++++++++++++++++++++++++++++++++
 include/linux/mount.h |  1 +
 2 files changed, 39 insertions(+)

diff --git a/fs/namespace.c b/fs/namespace.c
index 0570729..6377672 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1153,6 +1153,44 @@ struct vfsmount *mntget(struct vfsmount *mnt)
 }
 EXPORT_SYMBOL(mntget);
 
+struct vfsmount *legitimize_mntget(struct vfsmount *vfsmnt)
+{
+	struct mount *mnt;
+	unsigned seq = 0;
+
+	if (vfsmnt == NULL)
+		return NULL;
+
+	rcu_read_lock();
+retry:
+	read_seqbegin_or_lock(&mount_lock, &seq);
+
+	if (vfsmnt->mnt_flags & (MNT_SYNC_UMOUNT | MNT_UMOUNT | MNT_DOOMED))
+		vfsmnt = NULL;
+	else {
+		mnt = real_mount(vfsmnt);
+		mnt_add_count(mnt, 1);
+		if (need_seqretry(&mount_lock, seq)) {
+			/* lost the race, need to try again */
+			if (vfsmnt->mnt_flags & MNT_SYNC_UMOUNT) {
+				/* no point trying... */
+				mnt_add_count(mnt, -1);
+				vfsmnt = NULL;
+			} else {
+				mntput(vfsmnt);
+				seq = 1;
+				goto retry;
+			}
+		}
+	}
+
+	done_seqretry(&mount_lock, seq);
+	rcu_read_unlock();
+
+	return vfsmnt;
+}
+EXPORT_SYMBOL(legitimize_mntget);
+
 struct vfsmount *mnt_clone_internal(struct path *path)
 {
 	struct mount *p;
diff --git a/include/linux/mount.h b/include/linux/mount.h
index f822c3c..8ae9dc0 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -79,6 +79,7 @@ extern void mnt_drop_write(struct vfsmount *mnt);
 extern void mnt_drop_write_file(struct file *file);
 extern void mntput(struct vfsmount *mnt);
 extern struct vfsmount *mntget(struct vfsmount *mnt);
+extern struct vfsmount *legitimize_mntget(struct vfsmount *vfsmnt);
 extern struct vfsmount *mnt_clone_internal(struct path *path);
 extern int __mnt_is_readonly(struct vfsmount *mnt);
 
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux