Commit 2dee55cd authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] removal of LOOKUP_POSITIVE

	LOOKUP_POSITIVE is not needed anymore.  All callers of path_walk()
treat -ENOENT and negative dentry the same way.  If you want a proof of
correctness - I'll send it, but it's a couple of pages of induction, basically
boiling down to "let's show that for any N we can replace the
               if (lookup_flags & (LOOKUP_POSITIVE|LOOKUP_DIRECTORY))
                       break;
in link_path_walk() with
               if ((lookup_flags & (LOOKUP_POSITIVE|LOOKUP_DIRECTORY)) ||
		   current->link_count <= N)
                       break;
without changing behaviour of the system".  Pretty straightforward for
N = 0, then we look for places that can lead to call link_path_walk()
with current->link_count equal to N and show that if result of the test
changes, behaviour of callers doesn't.  Since the depth of recursion is
limited, we had shown that test in question can be replaced with if (1).
And that's the only place in tree the ever checks for LOOKUP_POSITIVE.

	The real reason behind that is very simple - indeed, suppose
we get a negative dentry out of path_walk().  What the hell could we
do with it?  Its parent isn't locked, so both the name and parent can
change at any moment (could have changed already).  There used to be
places that tried to play "let's get a negative dentry, lock its parent
and start doing something".  All of them racy and all of them fixed
in 2.3.  Fixed by switching to LOOKUP_PARENT...
parent e145fcfa
......@@ -347,7 +347,7 @@ struct file *open_exec(const char *name)
struct file *file;
int err = 0;
if (path_init(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd))
if (path_init(name, LOOKUP_FOLLOW, &nd))
err = path_walk(name, &nd);
file = ERR_PTR(err);
if (!err) {
......
......@@ -40,7 +40,7 @@ int presto_walk(const char *name, struct nameidata *nd)
resolved pathname and not the symlink. SHP
XXX: This code implies that direct symlinks do not work. SHP
*/
unsigned int flags = LOOKUP_POSITIVE;
unsigned int flags = 0;
ENTRY;
err = 0;
......
......@@ -538,7 +538,7 @@ int lento_create(const char *name, int mode, struct lento_vfs_context *info)
}
/* this looks up the parent */
// if (path_init(pathname, LOOKUP_FOLLOW | LOOKUP_POSITIVE, &nd))
// if (path_init(pathname, LOOKUP_FOLLOW, &nd))
if (path_init(pathname, LOOKUP_PARENT, &nd))
error = path_walk(pathname, &nd);
if (error) {
......@@ -687,7 +687,7 @@ int lento_link(const char * oldname, const char * newname,
struct nameidata nd, old_nd;
error = 0;
if (path_init(from, LOOKUP_POSITIVE, &old_nd))
if (path_init(from, 0, &old_nd))
error = path_walk(from, &old_nd);
if (error)
goto exit;
......
......@@ -609,18 +609,13 @@ int link_path_walk(const char * name, struct nameidata *nd)
}
err = -ENOENT;
if (!inode)
goto no_inode;
break;
if (lookup_flags & LOOKUP_DIRECTORY) {
err = -ENOTDIR;
if (!inode->i_op || !inode->i_op->lookup)
break;
}
goto return_base;
no_inode:
err = -ENOENT;
if (lookup_flags & (LOOKUP_POSITIVE|LOOKUP_DIRECTORY))
break;
goto return_base;
lookup_parent:
nd->last = this;
nd->last_type = LAST_NORM;
......@@ -691,7 +686,7 @@ void set_fs_altroot(void)
nd.mnt = mntget(current->fs->rootmnt);
nd.dentry = dget(current->fs->root);
read_unlock(&current->fs->lock);
nd.flags = LOOKUP_FOLLOW|LOOKUP_DIRECTORY|LOOKUP_POSITIVE;
nd.flags = LOOKUP_FOLLOW|LOOKUP_DIRECTORY;
if (path_walk(emul,&nd) == 0) {
mnt = nd.mnt;
dentry = nd.dentry;
......@@ -1648,7 +1643,7 @@ asmlinkage long sys_link(const char * oldname, const char * newname)
struct nameidata nd, old_nd;
error = 0;
if (path_init(from, LOOKUP_POSITIVE, &old_nd))
if (path_init(from, 0, &old_nd))
error = path_walk(from, &old_nd);
if (error)
goto exit;
......
......@@ -368,7 +368,7 @@ asmlinkage long sys_umount(char * name, int flags)
if (IS_ERR(kname))
goto out;
retval = 0;
if (path_init(kname, LOOKUP_POSITIVE|LOOKUP_FOLLOW, &nd))
if (path_init(kname, LOOKUP_FOLLOW, &nd))
retval = path_walk(kname, &nd);
putname(kname);
if (retval)
......@@ -497,7 +497,7 @@ static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
return err;
if (!old_name || !*old_name)
return -EINVAL;
if (path_init(old_name, LOOKUP_POSITIVE|LOOKUP_FOLLOW, &old_nd))
if (path_init(old_name, LOOKUP_FOLLOW, &old_nd))
err = path_walk(old_name, &old_nd);
if (err)
return err;
......@@ -564,7 +564,7 @@ static int do_move_mount(struct nameidata *nd, char *old_name)
return -EPERM;
if (!old_name || !*old_name)
return -EINVAL;
if (path_init(old_name, LOOKUP_POSITIVE|LOOKUP_FOLLOW, &old_nd))
if (path_init(old_name, LOOKUP_FOLLOW, &old_nd))
err = path_walk(old_name, &old_nd);
if (err)
return err;
......@@ -731,7 +731,7 @@ long do_mount(char * dev_name, char * dir_name, char *type_page,
flags &= ~(MS_NOSUID|MS_NOEXEC|MS_NODEV);
/* ... and get the mountpoint */
if (path_init(dir_name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd))
if (path_init(dir_name, LOOKUP_FOLLOW, &nd))
retval = path_walk(dir_name, &nd);
if (retval)
return retval;
......@@ -924,7 +924,7 @@ asmlinkage long sys_pivot_root(const char *new_root, const char *put_old)
if (IS_ERR(name))
goto out0;
error = 0;
if (path_init(name, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &new_nd))
if (path_init(name, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &new_nd))
error = path_walk(name, &new_nd);
putname(name);
if (error)
......@@ -938,7 +938,7 @@ asmlinkage long sys_pivot_root(const char *new_root, const char *put_old)
if (IS_ERR(name))
goto out1;
error = 0;
if (path_init(name, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &old_nd))
if (path_init(name, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &old_nd))
error = path_walk(name, &old_nd);
putname(name);
if (error)
......
......@@ -239,7 +239,7 @@ exp_export(struct nfsctl_export *nxp)
/* Look up the dentry */
err = 0;
if (path_init(nxp->ex_path, LOOKUP_POSITIVE, &nd))
if (path_init(nxp->ex_path, 0, &nd))
err = path_walk(nxp->ex_path, &nd);
if (err)
goto out_unlock;
......@@ -408,7 +408,7 @@ exp_rootfh(struct svc_client *clp, char *path, struct knfsd_fh *f, int maxsize)
err = -EPERM;
/* NB: we probably ought to check that it's NUL-terminated */
if (path_init(path, LOOKUP_POSITIVE, &nd) &&
if (path_init(path, 0, &nd) &&
path_walk(path, &nd)) {
printk("nfsd: exp_rootfh path not found %s", path);
return err;
......
......@@ -368,7 +368,7 @@ asmlinkage long sys_chdir(const char * filename)
goto out;
error = 0;
if (path_init(name,LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY,&nd))
if (path_init(name,LOOKUP_FOLLOW|LOOKUP_DIRECTORY,&nd))
error = path_walk(name, &nd);
putname(name);
if (error)
......@@ -427,8 +427,7 @@ asmlinkage long sys_chroot(const char * filename)
if (IS_ERR(name))
goto out;
path_init(name, LOOKUP_POSITIVE | LOOKUP_FOLLOW |
LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd);
path_init(name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd);
error = path_walk(name, &nd);
putname(name);
if (error)
......
......@@ -700,7 +700,7 @@ struct super_block *get_sb_bdev(struct file_system_type *fs_type,
/* What device it is? */
if (!dev_name || !*dev_name)
return ERR_PTR(-EINVAL);
if (path_init(dev_name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd))
if (path_init(dev_name, LOOKUP_FOLLOW, &nd))
error = path_walk(dev_name, &nd);
if (error)
return ERR_PTR(error);
......
......@@ -1273,7 +1273,6 @@ extern ino_t find_inode_number(struct dentry *, struct qstr *);
#define LOOKUP_FOLLOW (1)
#define LOOKUP_DIRECTORY (2)
#define LOOKUP_CONTINUE (4)
#define LOOKUP_POSITIVE (8)
#define LOOKUP_PARENT (16)
#define LOOKUP_NOALT (32)
/*
......@@ -1311,8 +1310,8 @@ extern int follow_down(struct vfsmount **, struct dentry **);
extern int follow_up(struct vfsmount **, struct dentry **);
extern struct dentry * lookup_one_len(const char *, struct dentry *, int);
extern struct dentry * lookup_hash(struct qstr *, struct dentry *);
#define user_path_walk(name,nd) __user_walk(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, nd)
#define user_path_walk_link(name,nd) __user_walk(name, LOOKUP_POSITIVE, nd)
#define user_path_walk(name,nd) __user_walk(name, LOOKUP_FOLLOW, nd)
#define user_path_walk_link(name,nd) __user_walk(name, 0, nd)
extern void inode_init_once(struct inode *);
extern void iput(struct inode *);
......
......@@ -603,8 +603,7 @@ static unix_socket *unix_find_other(struct sockaddr_un *sunname, int len,
int err = 0;
if (sunname->sun_path[0]) {
if (path_init(sunname->sun_path,
LOOKUP_POSITIVE|LOOKUP_FOLLOW, &nd))
if (path_init(sunname->sun_path, LOOKUP_FOLLOW, &nd))
err = path_walk(sunname->sun_path, &nd);
if (err)
goto fail;
......
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