mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-03-28 10:04:14 +00:00
namei: stash dfd and name into nameidata
fewer arguments to pass around... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
102b8af266
commit
c8a53ee5ee
1 changed files with 46 additions and 50 deletions
96
fs/namei.c
96
fs/namei.c
|
@ -498,6 +498,8 @@ struct nameidata {
|
||||||
struct qstr last;
|
struct qstr last;
|
||||||
struct path root;
|
struct path root;
|
||||||
struct inode *inode; /* path.dentry.d_inode */
|
struct inode *inode; /* path.dentry.d_inode */
|
||||||
|
struct filename *name;
|
||||||
|
int dfd;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
unsigned seq, m_seq, root_seq;
|
unsigned seq, m_seq, root_seq;
|
||||||
int last_type;
|
int last_type;
|
||||||
|
@ -512,10 +514,13 @@ struct nameidata {
|
||||||
} *stack, internal[EMBEDDED_LEVELS];
|
} *stack, internal[EMBEDDED_LEVELS];
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct nameidata *set_nameidata(struct nameidata *p)
|
static struct nameidata *set_nameidata(struct nameidata *p, int dfd,
|
||||||
|
struct filename *name)
|
||||||
{
|
{
|
||||||
struct nameidata *old = current->nameidata;
|
struct nameidata *old = current->nameidata;
|
||||||
p->stack = p->internal;
|
p->stack = p->internal;
|
||||||
|
p->dfd = dfd;
|
||||||
|
p->name = name;
|
||||||
p->total_link_count = old ? old->total_link_count : 0;
|
p->total_link_count = old ? old->total_link_count : 0;
|
||||||
current->nameidata = p;
|
current->nameidata = p;
|
||||||
return old;
|
return old;
|
||||||
|
@ -1954,11 +1959,10 @@ OK:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *path_init(int dfd, const struct filename *name,
|
static const char *path_init(struct nameidata *nd, unsigned flags)
|
||||||
unsigned int flags, struct nameidata *nd)
|
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
const char *s = name->name;
|
const char *s = nd->name->name;
|
||||||
|
|
||||||
nd->last_type = LAST_ROOT; /* if there are only slashes... */
|
nd->last_type = LAST_ROOT; /* if there are only slashes... */
|
||||||
nd->flags = flags | LOOKUP_JUMPED | LOOKUP_PARENT;
|
nd->flags = flags | LOOKUP_JUMPED | LOOKUP_PARENT;
|
||||||
|
@ -1999,7 +2003,7 @@ static const char *path_init(int dfd, const struct filename *name,
|
||||||
path_get(&nd->root);
|
path_get(&nd->root);
|
||||||
}
|
}
|
||||||
nd->path = nd->root;
|
nd->path = nd->root;
|
||||||
} else if (dfd == AT_FDCWD) {
|
} else if (nd->dfd == AT_FDCWD) {
|
||||||
if (flags & LOOKUP_RCU) {
|
if (flags & LOOKUP_RCU) {
|
||||||
struct fs_struct *fs = current->fs;
|
struct fs_struct *fs = current->fs;
|
||||||
unsigned seq;
|
unsigned seq;
|
||||||
|
@ -2016,7 +2020,7 @@ static const char *path_init(int dfd, const struct filename *name,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Caller must check execute permissions on the starting path component */
|
/* Caller must check execute permissions on the starting path component */
|
||||||
struct fd f = fdget_raw(dfd);
|
struct fd f = fdget_raw(nd->dfd);
|
||||||
struct dentry *dentry;
|
struct dentry *dentry;
|
||||||
|
|
||||||
if (!f.file)
|
if (!f.file)
|
||||||
|
@ -2082,10 +2086,9 @@ static inline int lookup_last(struct nameidata *nd)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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_lookupat(int dfd, const struct filename *name, unsigned flags,
|
static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path)
|
||||||
struct nameidata *nd, struct path *path)
|
|
||||||
{
|
{
|
||||||
const char *s = path_init(dfd, name, flags, nd);
|
const char *s = path_init(nd, flags);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (IS_ERR(s))
|
if (IS_ERR(s))
|
||||||
|
@ -2120,17 +2123,16 @@ static int filename_lookup(int dfd, struct filename *name, unsigned flags,
|
||||||
struct nameidata nd, *saved_nd;
|
struct nameidata nd, *saved_nd;
|
||||||
if (IS_ERR(name))
|
if (IS_ERR(name))
|
||||||
return PTR_ERR(name);
|
return PTR_ERR(name);
|
||||||
saved_nd = set_nameidata(&nd);
|
saved_nd = set_nameidata(&nd, dfd, name);
|
||||||
if (unlikely(root)) {
|
if (unlikely(root)) {
|
||||||
nd.root = *root;
|
nd.root = *root;
|
||||||
flags |= LOOKUP_ROOT;
|
flags |= LOOKUP_ROOT;
|
||||||
}
|
}
|
||||||
retval = path_lookupat(dfd, name, flags | LOOKUP_RCU, &nd, path);
|
retval = path_lookupat(&nd, flags | LOOKUP_RCU, path);
|
||||||
if (unlikely(retval == -ECHILD))
|
if (unlikely(retval == -ECHILD))
|
||||||
retval = path_lookupat(dfd, name, flags, &nd, path);
|
retval = path_lookupat(&nd, flags, path);
|
||||||
if (unlikely(retval == -ESTALE))
|
if (unlikely(retval == -ESTALE))
|
||||||
retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL,
|
retval = path_lookupat(&nd, flags | LOOKUP_REVAL, path);
|
||||||
&nd, path);
|
|
||||||
|
|
||||||
if (likely(!retval))
|
if (likely(!retval))
|
||||||
audit_inode(name, path->dentry, flags & LOOKUP_PARENT);
|
audit_inode(name, path->dentry, flags & LOOKUP_PARENT);
|
||||||
|
@ -2140,11 +2142,10 @@ static int filename_lookup(int dfd, struct filename *name, unsigned flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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(int dfd, const struct filename *name,
|
static int path_parentat(struct nameidata *nd, unsigned flags,
|
||||||
unsigned int flags, struct nameidata *nd,
|
|
||||||
struct path *parent)
|
struct path *parent)
|
||||||
{
|
{
|
||||||
const char *s = path_init(dfd, name, flags, nd);
|
const char *s = path_init(nd, flags);
|
||||||
int err;
|
int err;
|
||||||
if (IS_ERR(s))
|
if (IS_ERR(s))
|
||||||
return PTR_ERR(s);
|
return PTR_ERR(s);
|
||||||
|
@ -2169,13 +2170,12 @@ static struct filename *filename_parentat(int dfd, struct filename *name,
|
||||||
|
|
||||||
if (IS_ERR(name))
|
if (IS_ERR(name))
|
||||||
return name;
|
return name;
|
||||||
saved_nd = set_nameidata(&nd);
|
saved_nd = set_nameidata(&nd, dfd, name);
|
||||||
retval = path_parentat(dfd, name, flags | LOOKUP_RCU, &nd, parent);
|
retval = path_parentat(&nd, flags | LOOKUP_RCU, parent);
|
||||||
if (unlikely(retval == -ECHILD))
|
if (unlikely(retval == -ECHILD))
|
||||||
retval = path_parentat(dfd, name, flags, &nd, parent);
|
retval = path_parentat(&nd, flags, parent);
|
||||||
if (unlikely(retval == -ESTALE))
|
if (unlikely(retval == -ESTALE))
|
||||||
retval = path_parentat(dfd, name, flags | LOOKUP_REVAL,
|
retval = path_parentat(&nd, flags | LOOKUP_REVAL, parent);
|
||||||
&nd, parent);
|
|
||||||
if (likely(!retval)) {
|
if (likely(!retval)) {
|
||||||
*last = nd.last;
|
*last = nd.last;
|
||||||
*type = nd.last_type;
|
*type = nd.last_type;
|
||||||
|
@ -2415,19 +2415,17 @@ done:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* path_mountpoint - look up a path to be umounted
|
* path_mountpoint - look up a path to be umounted
|
||||||
* @dfd: directory file descriptor to start walk from
|
* @nameidata: lookup context
|
||||||
* @name: full pathname to walk
|
|
||||||
* @path: pointer to container for result
|
|
||||||
* @flags: lookup flags
|
* @flags: lookup flags
|
||||||
|
* @path: pointer to container for result
|
||||||
*
|
*
|
||||||
* Look up the given name, but don't attempt to revalidate the last component.
|
* Look up the given name, but don't attempt to revalidate the last component.
|
||||||
* Returns 0 and "path" will be valid on success; Returns error otherwise.
|
* Returns 0 and "path" will be valid on success; Returns error otherwise.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
path_mountpoint(int dfd, const struct filename *name, struct path *path,
|
path_mountpoint(struct nameidata *nd, unsigned flags, struct path *path)
|
||||||
struct nameidata *nd, unsigned int flags)
|
|
||||||
{
|
{
|
||||||
const char *s = path_init(dfd, name, flags, nd);
|
const char *s = path_init(nd, flags);
|
||||||
int err;
|
int err;
|
||||||
if (IS_ERR(s))
|
if (IS_ERR(s))
|
||||||
return PTR_ERR(s);
|
return PTR_ERR(s);
|
||||||
|
@ -2451,12 +2449,12 @@ filename_mountpoint(int dfd, struct filename *name, struct path *path,
|
||||||
int error;
|
int error;
|
||||||
if (IS_ERR(name))
|
if (IS_ERR(name))
|
||||||
return PTR_ERR(name);
|
return PTR_ERR(name);
|
||||||
saved = set_nameidata(&nd);
|
saved = set_nameidata(&nd, dfd, name);
|
||||||
error = path_mountpoint(dfd, name, path, &nd, flags | LOOKUP_RCU);
|
error = path_mountpoint(&nd, flags | LOOKUP_RCU, path);
|
||||||
if (unlikely(error == -ECHILD))
|
if (unlikely(error == -ECHILD))
|
||||||
error = path_mountpoint(dfd, name, path, &nd, flags);
|
error = path_mountpoint(&nd, flags, path);
|
||||||
if (unlikely(error == -ESTALE))
|
if (unlikely(error == -ESTALE))
|
||||||
error = path_mountpoint(dfd, name, path, &nd, flags | LOOKUP_REVAL);
|
error = path_mountpoint(&nd, flags | LOOKUP_REVAL, path);
|
||||||
if (likely(!error))
|
if (likely(!error))
|
||||||
audit_inode(name, path->dentry, 0);
|
audit_inode(name, path->dentry, 0);
|
||||||
restore_nameidata(saved);
|
restore_nameidata(saved);
|
||||||
|
@ -3217,8 +3215,7 @@ stale_open:
|
||||||
goto retry_lookup;
|
goto retry_lookup;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_tmpfile(int dfd, struct filename *pathname,
|
static int do_tmpfile(struct nameidata *nd, unsigned flags,
|
||||||
struct nameidata *nd, int flags,
|
|
||||||
const struct open_flags *op,
|
const struct open_flags *op,
|
||||||
struct file *file, int *opened)
|
struct file *file, int *opened)
|
||||||
{
|
{
|
||||||
|
@ -3226,8 +3223,7 @@ static int do_tmpfile(int dfd, struct filename *pathname,
|
||||||
struct dentry *child;
|
struct dentry *child;
|
||||||
struct inode *dir;
|
struct inode *dir;
|
||||||
struct path path;
|
struct path path;
|
||||||
int error = path_lookupat(dfd, pathname,
|
int error = path_lookupat(nd, flags | LOOKUP_DIRECTORY, &path);
|
||||||
flags | LOOKUP_DIRECTORY, nd, &path);
|
|
||||||
if (unlikely(error))
|
if (unlikely(error))
|
||||||
return error;
|
return error;
|
||||||
error = mnt_want_write(path.mnt);
|
error = mnt_want_write(path.mnt);
|
||||||
|
@ -3252,7 +3248,7 @@ static int do_tmpfile(int dfd, struct filename *pathname,
|
||||||
error = dir->i_op->tmpfile(dir, child, op->mode);
|
error = dir->i_op->tmpfile(dir, child, op->mode);
|
||||||
if (error)
|
if (error)
|
||||||
goto out2;
|
goto out2;
|
||||||
audit_inode(pathname, child, 0);
|
audit_inode(nd->name, child, 0);
|
||||||
/* Don't check for other permissions, the inode was just created */
|
/* Don't check for other permissions, the inode was just created */
|
||||||
error = may_open(&path, MAY_OPEN, op->open_flag);
|
error = may_open(&path, MAY_OPEN, op->open_flag);
|
||||||
if (error)
|
if (error)
|
||||||
|
@ -3277,8 +3273,8 @@ out:
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct file *path_openat(int dfd, struct filename *pathname,
|
static struct file *path_openat(struct nameidata *nd,
|
||||||
struct nameidata *nd, const struct open_flags *op, int flags)
|
const struct open_flags *op, unsigned flags)
|
||||||
{
|
{
|
||||||
const char *s;
|
const char *s;
|
||||||
struct file *file;
|
struct file *file;
|
||||||
|
@ -3292,17 +3288,17 @@ static struct file *path_openat(int dfd, struct filename *pathname,
|
||||||
file->f_flags = op->open_flag;
|
file->f_flags = op->open_flag;
|
||||||
|
|
||||||
if (unlikely(file->f_flags & __O_TMPFILE)) {
|
if (unlikely(file->f_flags & __O_TMPFILE)) {
|
||||||
error = do_tmpfile(dfd, pathname, nd, flags, op, file, &opened);
|
error = do_tmpfile(nd, flags, op, file, &opened);
|
||||||
goto out2;
|
goto out2;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = path_init(dfd, pathname, flags, nd);
|
s = path_init(nd, flags);
|
||||||
if (IS_ERR(s)) {
|
if (IS_ERR(s)) {
|
||||||
put_filp(file);
|
put_filp(file);
|
||||||
return ERR_CAST(s);
|
return ERR_CAST(s);
|
||||||
}
|
}
|
||||||
while (!(error = link_path_walk(s, nd)) &&
|
while (!(error = link_path_walk(s, nd)) &&
|
||||||
(error = do_last(nd, file, op, &opened, pathname)) > 0) {
|
(error = do_last(nd, file, op, &opened, nd->name)) > 0) {
|
||||||
nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL);
|
nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL);
|
||||||
s = trailing_symlink(nd);
|
s = trailing_symlink(nd);
|
||||||
if (IS_ERR(s)) {
|
if (IS_ERR(s)) {
|
||||||
|
@ -3331,15 +3327,15 @@ out2:
|
||||||
struct file *do_filp_open(int dfd, struct filename *pathname,
|
struct file *do_filp_open(int dfd, struct filename *pathname,
|
||||||
const struct open_flags *op)
|
const struct open_flags *op)
|
||||||
{
|
{
|
||||||
struct nameidata nd, *saved_nd = set_nameidata(&nd);
|
struct nameidata nd, *saved_nd = set_nameidata(&nd, dfd, pathname);
|
||||||
int flags = op->lookup_flags;
|
int flags = op->lookup_flags;
|
||||||
struct file *filp;
|
struct file *filp;
|
||||||
|
|
||||||
filp = path_openat(dfd, pathname, &nd, op, flags | LOOKUP_RCU);
|
filp = path_openat(&nd, op, flags | LOOKUP_RCU);
|
||||||
if (unlikely(filp == ERR_PTR(-ECHILD)))
|
if (unlikely(filp == ERR_PTR(-ECHILD)))
|
||||||
filp = path_openat(dfd, pathname, &nd, op, flags);
|
filp = path_openat(&nd, op, flags);
|
||||||
if (unlikely(filp == ERR_PTR(-ESTALE)))
|
if (unlikely(filp == ERR_PTR(-ESTALE)))
|
||||||
filp = path_openat(dfd, pathname, &nd, op, flags | LOOKUP_REVAL);
|
filp = path_openat(&nd, op, flags | LOOKUP_REVAL);
|
||||||
restore_nameidata(saved_nd);
|
restore_nameidata(saved_nd);
|
||||||
return filp;
|
return filp;
|
||||||
}
|
}
|
||||||
|
@ -3362,12 +3358,12 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt,
|
||||||
if (unlikely(IS_ERR(filename)))
|
if (unlikely(IS_ERR(filename)))
|
||||||
return ERR_CAST(filename);
|
return ERR_CAST(filename);
|
||||||
|
|
||||||
saved_nd = set_nameidata(&nd);
|
saved_nd = set_nameidata(&nd, -1, filename);
|
||||||
file = path_openat(-1, filename, &nd, op, flags | LOOKUP_RCU);
|
file = path_openat(&nd, op, flags | LOOKUP_RCU);
|
||||||
if (unlikely(file == ERR_PTR(-ECHILD)))
|
if (unlikely(file == ERR_PTR(-ECHILD)))
|
||||||
file = path_openat(-1, filename, &nd, op, flags);
|
file = path_openat(&nd, op, flags);
|
||||||
if (unlikely(file == ERR_PTR(-ESTALE)))
|
if (unlikely(file == ERR_PTR(-ESTALE)))
|
||||||
file = path_openat(-1, filename, &nd, op, flags | LOOKUP_REVAL);
|
file = path_openat(&nd, op, flags | LOOKUP_REVAL);
|
||||||
restore_nameidata(saved_nd);
|
restore_nameidata(saved_nd);
|
||||||
putname(filename);
|
putname(filename);
|
||||||
return file;
|
return file;
|
||||||
|
|
Loading…
Add table
Reference in a new issue