namei: Standardize callers of filename_lookup()
filename_lookup() has two variants, one which drops the caller's reference to filename (filename_lookup), and one which does not (__filename_lookup). This can be confusing as it's unusual to drop a caller's reference. Remove filename_lookup, rename __filename_lookup to filename_lookup, and convert all callers. The cost is a few slightly longer functions, but the clarity is greater. [AV: consuming a reference is not at all unusual, actually; look at e.g. do_mkdirat(), for example. It's more that we want non-consuming variant for close relative of that function...] Link: https://lore.kernel.org/linux-fsdevel/YS+dstZ3xfcLxhoB@zeniv-ca.linux.org.uk/ Cc: Christoph Hellwig <hch@infradead.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
c5f563f9e9
commit
794ebcea86
|
@ -165,7 +165,6 @@ int fs_lookup_param(struct fs_context *fc,
|
||||||
return invalf(fc, "%s: not usable as path", param->key);
|
return invalf(fc, "%s: not usable as path", param->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
f->refcnt++; /* filename_lookup() drops our ref. */
|
|
||||||
ret = filename_lookup(param->dirfd, f, flags, _path, NULL);
|
ret = filename_lookup(param->dirfd, f, flags, _path, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
errorf(fc, "%s: Lookup failure for '%s'", param->key, f->name);
|
errorf(fc, "%s: Lookup failure for '%s'", param->key, f->name);
|
||||||
|
|
37
fs/namei.c
37
fs/namei.c
|
@ -2467,7 +2467,7 @@ static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __filename_lookup(int dfd, struct filename *name, unsigned flags,
|
int filename_lookup(int dfd, struct filename *name, unsigned flags,
|
||||||
struct path *path, struct path *root)
|
struct path *path, struct path *root)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
|
@ -2488,15 +2488,6 @@ static int __filename_lookup(int dfd, struct filename *name, unsigned flags,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int filename_lookup(int dfd, struct filename *name, unsigned flags,
|
|
||||||
struct path *path, struct path *root)
|
|
||||||
{
|
|
||||||
int retval = __filename_lookup(dfd, name, flags, path, root);
|
|
||||||
|
|
||||||
putname(name);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
|
/* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
|
||||||
static int path_parentat(struct nameidata *nd, unsigned flags,
|
static int path_parentat(struct nameidata *nd, unsigned flags,
|
||||||
struct path *parent)
|
struct path *parent)
|
||||||
|
@ -2573,8 +2564,12 @@ struct dentry *kern_path_locked(const char *name, struct path *path)
|
||||||
|
|
||||||
int kern_path(const char *name, unsigned int flags, struct path *path)
|
int kern_path(const char *name, unsigned int flags, struct path *path)
|
||||||
{
|
{
|
||||||
return filename_lookup(AT_FDCWD, getname_kernel(name),
|
struct filename *filename = getname_kernel(name);
|
||||||
flags, path, NULL);
|
int ret = filename_lookup(AT_FDCWD, filename, flags, path, NULL);
|
||||||
|
|
||||||
|
putname(filename);
|
||||||
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(kern_path);
|
EXPORT_SYMBOL(kern_path);
|
||||||
|
|
||||||
|
@ -2590,10 +2585,15 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt,
|
||||||
const char *name, unsigned int flags,
|
const char *name, unsigned int flags,
|
||||||
struct path *path)
|
struct path *path)
|
||||||
{
|
{
|
||||||
|
struct filename *filename;
|
||||||
struct path root = {.mnt = mnt, .dentry = dentry};
|
struct path root = {.mnt = mnt, .dentry = dentry};
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
filename = getname_kernel(name);
|
||||||
/* the first argument of filename_lookup() is ignored with root */
|
/* the first argument of filename_lookup() is ignored with root */
|
||||||
return filename_lookup(AT_FDCWD, getname_kernel(name),
|
ret = filename_lookup(AT_FDCWD, filename, flags, path, &root);
|
||||||
flags , path, &root);
|
putname(filename);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(vfs_path_lookup);
|
EXPORT_SYMBOL(vfs_path_lookup);
|
||||||
|
|
||||||
|
@ -2797,8 +2797,11 @@ int path_pts(struct path *path)
|
||||||
int user_path_at_empty(int dfd, const char __user *name, unsigned flags,
|
int user_path_at_empty(int dfd, const char __user *name, unsigned flags,
|
||||||
struct path *path, int *empty)
|
struct path *path, int *empty)
|
||||||
{
|
{
|
||||||
return filename_lookup(dfd, getname_flags(name, flags, empty),
|
struct filename *filename = getname_flags(name, flags, empty);
|
||||||
flags, path, NULL);
|
int ret = filename_lookup(dfd, filename, flags, path, NULL);
|
||||||
|
|
||||||
|
putname(filename);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(user_path_at_empty);
|
EXPORT_SYMBOL(user_path_at_empty);
|
||||||
|
|
||||||
|
@ -4425,7 +4428,7 @@ int do_linkat(int olddfd, struct filename *old, int newdfd,
|
||||||
if (flags & AT_SYMLINK_FOLLOW)
|
if (flags & AT_SYMLINK_FOLLOW)
|
||||||
how |= LOOKUP_FOLLOW;
|
how |= LOOKUP_FOLLOW;
|
||||||
retry:
|
retry:
|
||||||
error = __filename_lookup(olddfd, old, how, &old_path, NULL);
|
error = filename_lookup(olddfd, old, how, &old_path, NULL);
|
||||||
if (error)
|
if (error)
|
||||||
goto out_putnames;
|
goto out_putnames;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue