Commit 055d2194 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6:
  get rid of nameidata_dentry_drop_rcu() calling nameidata_drop_rcu()
  drop out of RCU in return_reval
  split do_revalidate() into RCU and non-RCU cases
  in do_lookup() split RCU and non-RCU cases of need_revalidate
  nothing in do_follow_link() is going to see RCU
parents 007a14af 4e924a4f
...@@ -455,14 +455,6 @@ static int nameidata_dentry_drop_rcu(struct nameidata *nd, struct dentry *dentry ...@@ -455,14 +455,6 @@ static int nameidata_dentry_drop_rcu(struct nameidata *nd, struct dentry *dentry
struct fs_struct *fs = current->fs; struct fs_struct *fs = current->fs;
struct dentry *parent = nd->path.dentry; struct dentry *parent = nd->path.dentry;
/*
* It can be possible to revalidate the dentry that we started
* the path walk with. force_reval_path may also revalidate the
* dentry already committed to the nameidata.
*/
if (unlikely(parent == dentry))
return nameidata_drop_rcu(nd);
BUG_ON(!(nd->flags & LOOKUP_RCU)); BUG_ON(!(nd->flags & LOOKUP_RCU));
if (nd->root.mnt) { if (nd->root.mnt) {
spin_lock(&fs->lock); spin_lock(&fs->lock);
...@@ -571,33 +563,15 @@ void release_open_intent(struct nameidata *nd) ...@@ -571,33 +563,15 @@ void release_open_intent(struct nameidata *nd)
} }
} }
/* static inline int d_revalidate(struct dentry *dentry, struct nameidata *nd)
* Call d_revalidate and handle filesystems that request rcu-walk
* to be dropped. This may be called and return in rcu-walk mode,
* regardless of success or error. If -ECHILD is returned, the caller
* must return -ECHILD back up the path walk stack so path walk may
* be restarted in ref-walk mode.
*/
static int d_revalidate(struct dentry *dentry, struct nameidata *nd)
{ {
int status; return dentry->d_op->d_revalidate(dentry, nd);
status = dentry->d_op->d_revalidate(dentry, nd);
if (status == -ECHILD) {
if (nameidata_dentry_drop_rcu(nd, dentry))
return status;
status = dentry->d_op->d_revalidate(dentry, nd);
}
return status;
} }
static inline struct dentry * static struct dentry *
do_revalidate(struct dentry *dentry, struct nameidata *nd) do_revalidate(struct dentry *dentry, struct nameidata *nd)
{ {
int status; int status = d_revalidate(dentry, nd);
status = d_revalidate(dentry, nd);
if (unlikely(status <= 0)) { if (unlikely(status <= 0)) {
/* /*
* The dentry failed validation. * The dentry failed validation.
...@@ -606,24 +580,39 @@ do_revalidate(struct dentry *dentry, struct nameidata *nd) ...@@ -606,24 +580,39 @@ do_revalidate(struct dentry *dentry, struct nameidata *nd)
* to return a fail status. * to return a fail status.
*/ */
if (status < 0) { if (status < 0) {
/* If we're in rcu-walk, we don't have a ref */ dput(dentry);
if (!(nd->flags & LOOKUP_RCU))
dput(dentry);
dentry = ERR_PTR(status); dentry = ERR_PTR(status);
} else if (!d_invalidate(dentry)) {
} else { dput(dentry);
/* Don't d_invalidate in rcu-walk mode */ dentry = NULL;
if (nameidata_dentry_drop_rcu_maybe(nd, dentry))
return ERR_PTR(-ECHILD);
if (!d_invalidate(dentry)) {
dput(dentry);
dentry = NULL;
}
} }
} }
return dentry; return dentry;
} }
static inline struct dentry *
do_revalidate_rcu(struct dentry *dentry, struct nameidata *nd)
{
int status = d_revalidate(dentry, nd);
if (likely(status > 0))
return dentry;
if (status == -ECHILD) {
if (nameidata_dentry_drop_rcu(nd, dentry))
return ERR_PTR(-ECHILD);
return do_revalidate(dentry, nd);
}
if (status < 0)
return ERR_PTR(status);
/* Don't d_invalidate in rcu-walk mode */
if (nameidata_dentry_drop_rcu(nd, dentry))
return ERR_PTR(-ECHILD);
if (!d_invalidate(dentry)) {
dput(dentry);
dentry = NULL;
}
return dentry;
}
static inline int need_reval_dot(struct dentry *dentry) static inline int need_reval_dot(struct dentry *dentry)
{ {
if (likely(!(dentry->d_flags & DCACHE_OP_REVALIDATE))) if (likely(!(dentry->d_flags & DCACHE_OP_REVALIDATE)))
...@@ -668,9 +657,6 @@ force_reval_path(struct path *path, struct nameidata *nd) ...@@ -668,9 +657,6 @@ force_reval_path(struct path *path, struct nameidata *nd)
return 0; return 0;
if (!status) { if (!status) {
/* Don't d_invalidate in rcu-walk mode */
if (nameidata_drop_rcu(nd))
return -ECHILD;
d_invalidate(dentry); d_invalidate(dentry);
status = -ESTALE; status = -ESTALE;
} }
...@@ -777,6 +763,8 @@ __do_follow_link(const struct path *link, struct nameidata *nd, void **p) ...@@ -777,6 +763,8 @@ __do_follow_link(const struct path *link, struct nameidata *nd, void **p)
int error; int error;
struct dentry *dentry = link->dentry; struct dentry *dentry = link->dentry;
BUG_ON(nd->flags & LOOKUP_RCU);
touch_atime(link->mnt, dentry); touch_atime(link->mnt, dentry);
nd_set_link(nd, NULL); nd_set_link(nd, NULL);
...@@ -811,6 +799,11 @@ static inline int do_follow_link(struct path *path, struct nameidata *nd) ...@@ -811,6 +799,11 @@ static inline int do_follow_link(struct path *path, struct nameidata *nd)
{ {
void *cookie; void *cookie;
int err = -ELOOP; int err = -ELOOP;
/* We drop rcu-walk here */
if (nameidata_dentry_drop_rcu_maybe(nd, path->dentry))
return -ECHILD;
if (current->link_count >= MAX_NESTED_LINKS) if (current->link_count >= MAX_NESTED_LINKS)
goto loop; goto loop;
if (current->total_link_count >= 40) if (current->total_link_count >= 40)
...@@ -1255,9 +1248,15 @@ static int do_lookup(struct nameidata *nd, struct qstr *name, ...@@ -1255,9 +1248,15 @@ static int do_lookup(struct nameidata *nd, struct qstr *name,
return -ECHILD; return -ECHILD;
nd->seq = seq; nd->seq = seq;
if (dentry->d_flags & DCACHE_OP_REVALIDATE) if (unlikely(dentry->d_flags & DCACHE_OP_REVALIDATE)) {
goto need_revalidate; dentry = do_revalidate_rcu(dentry, nd);
done2: if (!dentry)
goto need_lookup;
if (IS_ERR(dentry))
goto fail;
if (!(nd->flags & LOOKUP_RCU))
goto done;
}
path->mnt = mnt; path->mnt = mnt;
path->dentry = dentry; path->dentry = dentry;
if (likely(__follow_mount_rcu(nd, path, inode, false))) if (likely(__follow_mount_rcu(nd, path, inode, false)))
...@@ -1270,8 +1269,13 @@ static int do_lookup(struct nameidata *nd, struct qstr *name, ...@@ -1270,8 +1269,13 @@ static int do_lookup(struct nameidata *nd, struct qstr *name,
if (!dentry) if (!dentry)
goto need_lookup; goto need_lookup;
found: found:
if (dentry->d_flags & DCACHE_OP_REVALIDATE) if (unlikely(dentry->d_flags & DCACHE_OP_REVALIDATE)) {
goto need_revalidate; dentry = do_revalidate(dentry, nd);
if (!dentry)
goto need_lookup;
if (IS_ERR(dentry))
goto fail;
}
done: done:
path->mnt = mnt; path->mnt = mnt;
path->dentry = dentry; path->dentry = dentry;
...@@ -1313,16 +1317,6 @@ static int do_lookup(struct nameidata *nd, struct qstr *name, ...@@ -1313,16 +1317,6 @@ static int do_lookup(struct nameidata *nd, struct qstr *name,
mutex_unlock(&dir->i_mutex); mutex_unlock(&dir->i_mutex);
goto found; goto found;
need_revalidate:
dentry = do_revalidate(dentry, nd);
if (!dentry)
goto need_lookup;
if (IS_ERR(dentry))
goto fail;
if (nd->flags & LOOKUP_RCU)
goto done2;
goto done;
fail: fail:
return PTR_ERR(dentry); return PTR_ERR(dentry);
} }
...@@ -1419,9 +1413,6 @@ static int link_path_walk(const char *name, struct nameidata *nd) ...@@ -1419,9 +1413,6 @@ static int link_path_walk(const char *name, struct nameidata *nd)
goto out_dput; goto out_dput;
if (inode->i_op->follow_link) { if (inode->i_op->follow_link) {
/* We commonly drop rcu-walk here */
if (nameidata_dentry_drop_rcu_maybe(nd, next.dentry))
return -ECHILD;
BUG_ON(inode != next.dentry->d_inode); BUG_ON(inode != next.dentry->d_inode);
err = do_follow_link(&next, nd); err = do_follow_link(&next, nd);
if (err) if (err)
...@@ -1467,8 +1458,6 @@ static int link_path_walk(const char *name, struct nameidata *nd) ...@@ -1467,8 +1458,6 @@ static int link_path_walk(const char *name, struct nameidata *nd)
break; break;
if (inode && unlikely(inode->i_op->follow_link) && if (inode && unlikely(inode->i_op->follow_link) &&
(lookup_flags & LOOKUP_FOLLOW)) { (lookup_flags & LOOKUP_FOLLOW)) {
if (nameidata_dentry_drop_rcu_maybe(nd, next.dentry))
return -ECHILD;
BUG_ON(inode != next.dentry->d_inode); BUG_ON(inode != next.dentry->d_inode);
err = do_follow_link(&next, nd); err = do_follow_link(&next, nd);
if (err) if (err)
...@@ -1504,12 +1493,15 @@ static int link_path_walk(const char *name, struct nameidata *nd) ...@@ -1504,12 +1493,15 @@ static int link_path_walk(const char *name, struct nameidata *nd)
* We may need to check the cached dentry for staleness. * We may need to check the cached dentry for staleness.
*/ */
if (need_reval_dot(nd->path.dentry)) { if (need_reval_dot(nd->path.dentry)) {
if (nameidata_drop_rcu_last_maybe(nd))
return -ECHILD;
/* Note: we do not d_invalidate() */ /* Note: we do not d_invalidate() */
err = d_revalidate(nd->path.dentry, nd); err = d_revalidate(nd->path.dentry, nd);
if (!err) if (!err)
err = -ESTALE; err = -ESTALE;
if (err < 0) if (err < 0)
break; break;
return 0;
} }
return_base: return_base:
if (nameidata_drop_rcu_last_maybe(nd)) if (nameidata_drop_rcu_last_maybe(nd))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment