lkml.org 
[lkml]   [2015]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 78/79] namei: new helper - is_stale()
Date
From: Al Viro <viro@zeniv.linux.org.uk>

we have a lot of places where we open-code the check that dentry->d_seq
matches nameidata...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
fs/namei.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index eb3f7d9..cf8f2de 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -575,6 +575,11 @@ static inline int nd_alloc_stack(struct nameidata *nd)
* to restart the path walk from the beginning in ref-walk mode.
*/

+static inline bool is_stale(struct nameidata *nd, struct dentry *dentry)
+{
+ return read_seqcount_retry(&dentry->d_seq, nd->seq);
+}
+
/**
* unlazy_walk - try to switch to ref-walk mode.
* @nd: nameidata pathwalk data
@@ -621,13 +626,13 @@ static int unlazy_walk(struct nameidata *nd, struct dentry *dentry)
* be valid if the child sequence number is still valid.
*/
if (!dentry) {
- if (read_seqcount_retry(&parent->d_seq, nd->seq))
+ if (is_stale(nd, parent))
goto out;
BUG_ON(nd->inode != parent->d_inode);
} else {
if (!lockref_get_not_dead(&dentry->d_lockref))
goto out;
- if (read_seqcount_retry(&dentry->d_seq, nd->seq))
+ if (is_stale(nd, dentry))
goto drop_dentry;
}

@@ -694,7 +699,7 @@ static int complete_walk(struct nameidata *nd)
mntput(nd->path.mnt);
return -ECHILD;
}
- if (read_seqcount_retry(&dentry->d_seq, nd->seq)) {
+ if (is_stale(nd, dentry)) {
rcu_read_unlock();
dput(dentry);
mntput(nd->path.mnt);
@@ -1218,7 +1223,7 @@ static int follow_dotdot_rcu(struct nameidata *nd)

inode = parent->d_inode;
seq = read_seqcount_begin(&parent->d_seq);
- if (read_seqcount_retry(&old->d_seq, nd->seq))
+ if (is_stale(nd, old))
goto failed;
nd->path.dentry = parent;
nd->seq = seq;
@@ -1980,7 +1985,7 @@ static int path_init(int dfd, const struct filename *name, unsigned int flags,
nd->inode = nd->path.dentry->d_inode;
if (!(flags & LOOKUP_RCU))
goto done;
- if (likely(!read_seqcount_retry(&nd->path.dentry->d_seq, nd->seq)))
+ if (likely(!is_stale(nd, nd->path.dentry)))
goto done;
if (!(nd->flags & LOOKUP_ROOT))
nd->root.mnt = NULL;
--
2.1.4


\
 
 \ /
  Last update: 2015-05-05 07:41    [W:0.567 / U:13.344 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site