Commit 32a7991b authored by Al Viro's avatar Al Viro

tidy up namei.c a bit

locking/unlocking for rcu walk taken to a couple of inline helpers
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 3c0a6163
...@@ -427,6 +427,18 @@ EXPORT_SYMBOL(path_put); ...@@ -427,6 +427,18 @@ EXPORT_SYMBOL(path_put);
* to restart the path walk from the beginning in ref-walk mode. * to restart the path walk from the beginning in ref-walk mode.
*/ */
static inline void lock_rcu_walk(void)
{
br_read_lock(&vfsmount_lock);
rcu_read_lock();
}
static inline void unlock_rcu_walk(void)
{
rcu_read_unlock();
br_read_unlock(&vfsmount_lock);
}
/** /**
* unlazy_walk - try to switch to ref-walk mode. * unlazy_walk - try to switch to ref-walk mode.
* @nd: nameidata pathwalk data * @nd: nameidata pathwalk data
...@@ -480,8 +492,7 @@ static int unlazy_walk(struct nameidata *nd, struct dentry *dentry) ...@@ -480,8 +492,7 @@ static int unlazy_walk(struct nameidata *nd, struct dentry *dentry)
} }
mntget(nd->path.mnt); mntget(nd->path.mnt);
rcu_read_unlock(); unlock_rcu_walk();
br_read_unlock(&vfsmount_lock);
nd->flags &= ~LOOKUP_RCU; nd->flags &= ~LOOKUP_RCU;
return 0; return 0;
...@@ -522,15 +533,13 @@ static int complete_walk(struct nameidata *nd) ...@@ -522,15 +533,13 @@ static int complete_walk(struct nameidata *nd)
spin_lock(&dentry->d_lock); spin_lock(&dentry->d_lock);
if (unlikely(!__d_rcu_to_refcount(dentry, nd->seq))) { if (unlikely(!__d_rcu_to_refcount(dentry, nd->seq))) {
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
rcu_read_unlock(); unlock_rcu_walk();
br_read_unlock(&vfsmount_lock);
return -ECHILD; return -ECHILD;
} }
BUG_ON(nd->inode != dentry->d_inode); BUG_ON(nd->inode != dentry->d_inode);
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
mntget(nd->path.mnt); mntget(nd->path.mnt);
rcu_read_unlock(); unlock_rcu_walk();
br_read_unlock(&vfsmount_lock);
} }
if (likely(!(nd->flags & LOOKUP_JUMPED))) if (likely(!(nd->flags & LOOKUP_JUMPED)))
...@@ -985,8 +994,7 @@ static int follow_dotdot_rcu(struct nameidata *nd) ...@@ -985,8 +994,7 @@ static int follow_dotdot_rcu(struct nameidata *nd)
nd->flags &= ~LOOKUP_RCU; nd->flags &= ~LOOKUP_RCU;
if (!(nd->flags & LOOKUP_ROOT)) if (!(nd->flags & LOOKUP_ROOT))
nd->root.mnt = NULL; nd->root.mnt = NULL;
rcu_read_unlock(); unlock_rcu_walk();
br_read_unlock(&vfsmount_lock);
return -ECHILD; return -ECHILD;
} }
...@@ -1323,8 +1331,7 @@ static void terminate_walk(struct nameidata *nd) ...@@ -1323,8 +1331,7 @@ static void terminate_walk(struct nameidata *nd)
nd->flags &= ~LOOKUP_RCU; nd->flags &= ~LOOKUP_RCU;
if (!(nd->flags & LOOKUP_ROOT)) if (!(nd->flags & LOOKUP_ROOT))
nd->root.mnt = NULL; nd->root.mnt = NULL;
rcu_read_unlock(); unlock_rcu_walk();
br_read_unlock(&vfsmount_lock);
} }
} }
...@@ -1691,8 +1698,7 @@ static int path_init(int dfd, const char *name, unsigned int flags, ...@@ -1691,8 +1698,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
nd->path = nd->root; nd->path = nd->root;
nd->inode = inode; nd->inode = inode;
if (flags & LOOKUP_RCU) { if (flags & LOOKUP_RCU) {
br_read_lock(&vfsmount_lock); lock_rcu_walk();
rcu_read_lock();
nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq);
} else { } else {
path_get(&nd->path); path_get(&nd->path);
...@@ -1704,8 +1710,7 @@ static int path_init(int dfd, const char *name, unsigned int flags, ...@@ -1704,8 +1710,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
if (*name=='/') { if (*name=='/') {
if (flags & LOOKUP_RCU) { if (flags & LOOKUP_RCU) {
br_read_lock(&vfsmount_lock); lock_rcu_walk();
rcu_read_lock();
set_root_rcu(nd); set_root_rcu(nd);
} else { } else {
set_root(nd); set_root(nd);
...@@ -1717,8 +1722,7 @@ static int path_init(int dfd, const char *name, unsigned int flags, ...@@ -1717,8 +1722,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
struct fs_struct *fs = current->fs; struct fs_struct *fs = current->fs;
unsigned seq; unsigned seq;
br_read_lock(&vfsmount_lock); lock_rcu_walk();
rcu_read_lock();
do { do {
seq = read_seqcount_begin(&fs->seq); seq = read_seqcount_begin(&fs->seq);
...@@ -1753,8 +1757,7 @@ static int path_init(int dfd, const char *name, unsigned int flags, ...@@ -1753,8 +1757,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
if (fput_needed) if (fput_needed)
*fp = file; *fp = file;
nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq);
br_read_lock(&vfsmount_lock); lock_rcu_walk();
rcu_read_lock();
} else { } else {
path_get(&file->f_path); path_get(&file->f_path);
fput_light(file, fput_needed); fput_light(file, fput_needed);
......
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