From: Al Viro <v...@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 <v...@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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to