[PATCH 15/20] VFS/namei: enhance follow_link to support RCU-walk.

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

 



If LOOKUP_RCU is set, follow_link will not take/drop reference counts.

Replace cond_resched() with _cond_resched() as the latter
is a no-op if rcu_read_lock() is held while the former will
give a warning in that case.

After taking a copy of dentry->d_inode, check d_seq to ensure this
is still the symlink we were looking for.

Signed-off-by: NeilBrown <neilb@xxxxxxx>
---
 fs/namei.c |   27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 72f5a4f91855..40ff4cb04244 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -897,16 +897,21 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
 	char *s;
 
 	nd->flags &= ~LOOKUP_LINK_RCU;
-	if (nd->flags & LOOKUP_RCU)
+	if (nd->flags & LOOKUP_RCU) {
 		nd->flags |= LOOKUP_LINK_RCU;
-	else if (link->mnt == nd->path.mnt)
+		if (__read_seqcount_retry(&dentry->d_seq, nd->seq)) {
+			error = -ECHILD;
+			goto out_put_nd_path;
+		}
+	} else if (link->mnt == nd->path.mnt)
 		mntget(link->mnt);
 
 	error = -ELOOP;
 	if (unlikely(nd->total_link_count >= 40))
 		goto out_put_nd_path;
 
-	cond_resched();
+	/* If rcu_read_locked(), this will not resched, and will not warn */
+	_cond_resched();
 	nd->total_link_count++;
 
 	if (nd->flags & LOOKUP_RCU) {
@@ -938,11 +943,17 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
 			return PTR_ERR(s);
 		}
 		if (*s == '/') {
-			if (!nd->root.mnt)
-				set_root(nd);
-			path_put(&nd->path);
-			nd->path = nd->root;
-			path_get(&nd->root);
+			if (nd->flags & LOOKUP_RCU) {
+				if (!nd->root.mnt)
+					set_root_rcu(nd);
+				nd->path = nd->root;
+			} else {
+				if (!nd->root.mnt)
+					set_root(nd);
+				path_put(&nd->path);
+				nd->path = nd->root;
+				path_get(&nd->root);
+			}
 			nd->flags |= LOOKUP_JUMPED;
 		}
 		nd->inode = nd->path.dentry->d_inode;


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




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux