Commit 4ac91378 authored by Jan Blunck's avatar Jan Blunck Committed by Linus Torvalds

Embed a struct path into struct nameidata instead of nd->{dentry,mnt}

This is the central patch of a cleanup series. In most cases there is no good
reason why someone would want to use a dentry for itself. This series reflects
that fact and embeds a struct path into nameidata.

Together with the other patches of this series
- it enforced the correct order of getting/releasing the reference count on
  <dentry,vfsmount> pairs
- it prepares the VFS for stacking support since it is essential to have a
  struct path in every place where the stack can be traversed
- it reduces the overall code size:

without patch series:
   text    data     bss     dec     hex filename
5321639  858418  715768 6895825  6938d1 vmlinux

with patch series:
   text    data     bss     dec     hex filename
5320026  858418  715768 6894212  693284 vmlinux

This patch:

Switch from nd->{dentry,mnt} to nd->path.{dentry,mnt} everywhere.

[akpm@linux-foundation.org: coding-style fixes]
[akpm@linux-foundation.org: fix cifs]
[akpm@linux-foundation.org: fix smack]
Signed-off-by: default avatarJan Blunck <jblunck@suse.de>
Signed-off-by: default avatarAndreas Gruenbacher <agruen@suse.de>
Acked-by: default avatarChristoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c5e725f3
......@@ -259,7 +259,7 @@ osf_statfs(char __user *path, struct osf_statfs __user *buffer, unsigned long bu
retval = user_path_walk(path, &nd);
if (!retval) {
retval = do_osf_statfs(nd.dentry, buffer, bufsiz);
retval = do_osf_statfs(nd.path.dentry, buffer, bufsiz);
path_release(&nd);
}
return retval;
......
......@@ -694,7 +694,7 @@ asmlinkage int irix_statfs(const char __user *path,
if (error)
goto out;
error = vfs_statfs(nd.dentry, &kbuf);
error = vfs_statfs(nd.path.dentry, &kbuf);
if (error)
goto dput_and_out;
......@@ -1360,7 +1360,7 @@ asmlinkage int irix_statvfs(char __user *fname, struct irix_statvfs __user *buf)
error = user_path_walk(fname, &nd);
if (error)
goto out;
error = vfs_statfs(nd.dentry, &kbuf);
error = vfs_statfs(nd.path.dentry, &kbuf);
if (error)
goto dput_and_out;
......@@ -1611,7 +1611,7 @@ asmlinkage int irix_statvfs64(char __user *fname, struct irix_statvfs64 __user *
error = user_path_walk(fname, &nd);
if (error)
goto out;
error = vfs_statfs(nd.dentry, &kbuf);
error = vfs_statfs(nd.path.dentry, &kbuf);
if (error)
goto dput_and_out;
......
......@@ -219,7 +219,7 @@ asmlinkage long hpux_statfs(const char __user *path,
error = user_path_walk(path, &nd);
if (!error) {
struct hpux_statfs tmp;
error = vfs_statfs_hpux(nd.dentry, &tmp);
error = vfs_statfs_hpux(nd.path.dentry, &tmp);
if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
error = -EFAULT;
path_release(&nd);
......
/*
* SPU file system
*
......@@ -592,7 +593,7 @@ long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode,
ret = -EINVAL;
/* check if we are on spufs */
if (nd->dentry->d_sb->s_type != &spufs_type)
if (nd->path.dentry->d_sb->s_type != &spufs_type)
goto out;
/* don't accept undefined flags */
......@@ -600,9 +601,9 @@ long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode,
goto out;
/* only threads can be underneath a gang */
if (nd->dentry != nd->dentry->d_sb->s_root) {
if (nd->path.dentry != nd->path.dentry->d_sb->s_root) {
if ((flags & SPU_CREATE_GANG) ||
!SPUFS_I(nd->dentry->d_inode)->i_gang)
!SPUFS_I(nd->path.dentry->d_inode)->i_gang)
goto out;
}
......@@ -618,16 +619,17 @@ long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode,
mode &= ~current->fs->umask;
if (flags & SPU_CREATE_GANG)
return spufs_create_gang(nd->dentry->d_inode,
dentry, nd->mnt, mode);
return spufs_create_gang(nd->path.dentry->d_inode,
dentry, nd->path.mnt, mode);
else
return spufs_create_context(nd->dentry->d_inode,
dentry, nd->mnt, flags, mode, filp);
return spufs_create_context(nd->path.dentry->d_inode,
dentry, nd->path.mnt, flags, mode,
filp);
out_dput:
dput(dentry);
out_dir:
mutex_unlock(&nd->dentry->d_inode->i_mutex);
mutex_unlock(&nd->path.dentry->d_inode->i_mutex);
out:
return ret;
}
......
......@@ -434,8 +434,8 @@ asmlinkage int solaris_statvfs(u32 path, u32 buf)
error = user_path_walk(A(path),&nd);
if (!error) {
struct inode * inode = nd.dentry->d_inode;
error = report_statvfs(nd.mnt, inode, buf);
struct inode *inode = nd.path.dentry->d_inode;
error = report_statvfs(nd.path.mnt, inode, buf);
path_release(&nd);
}
return error;
......@@ -464,8 +464,8 @@ asmlinkage int solaris_statvfs64(u32 path, u32 buf)
lock_kernel();
error = user_path_walk(A(path), &nd);
if (!error) {
struct inode * inode = nd.dentry->d_inode;
error = report_statvfs64(nd.mnt, inode, buf);
struct inode *inode = nd.path.dentry->d_inode;
error = report_statvfs64(nd.path.mnt, inode, buf);
path_release(&nd);
}
unlock_kernel();
......
......@@ -145,8 +145,8 @@ void mconsole_proc(struct mc_request *req)
}
up_write(&super->s_umount);
nd.dentry = super->s_root;
nd.mnt = NULL;
nd.path.dentry = super->s_root;
nd.path.mnt = NULL;
nd.flags = O_RDONLY + 1;
nd.last_type = LAST_ROOT;
......@@ -159,7 +159,7 @@ void mconsole_proc(struct mc_request *req)
goto out_kill;
}
file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
file = dentry_open(nd.path.dentry, nd.path.mnt, O_RDONLY);
if (IS_ERR(file)) {
mconsole_reply(req, "Failed to open file", 1, 0);
goto out_kill;
......
......@@ -361,7 +361,7 @@ static int lookup_device(const char *path, dev_t *dev)
if ((r = path_lookup(path, LOOKUP_FOLLOW, &nd)))
return r;
inode = nd.dentry->d_inode;
inode = nd.path.dentry->d_inode;
if (!inode) {
r = -ENOENT;
goto out;
......
......@@ -184,25 +184,25 @@ int get_sb_mtd(struct file_system_type *fs_type, int flags,
ret = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
DEBUG(1, "MTDSB: path_lookup() returned %d, inode %p\n",
ret, nd.dentry ? nd.dentry->d_inode : NULL);
ret, nd.path.dentry ? nd.path.dentry->d_inode : NULL);
if (ret)
return ret;
ret = -EINVAL;
if (!S_ISBLK(nd.dentry->d_inode->i_mode))
if (!S_ISBLK(nd.path.dentry->d_inode->i_mode))
goto out;
if (nd.mnt->mnt_flags & MNT_NODEV) {
if (nd.path.mnt->mnt_flags & MNT_NODEV) {
ret = -EACCES;
goto out;
}
if (imajor(nd.dentry->d_inode) != MTD_BLOCK_MAJOR)
if (imajor(nd.path.dentry->d_inode) != MTD_BLOCK_MAJOR)
goto not_an_MTD_device;
mtdnr = iminor(nd.dentry->d_inode);
mtdnr = iminor(nd.path.dentry->d_inode);
path_release(&nd);
return get_sb_mtd_nr(fs_type, flags, dev_name, data, mtdnr, fill_super,
......
......@@ -218,14 +218,14 @@ static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd)
_enter("%p{%s},{%s:%p{%s},}",
dentry,
dentry->d_name.name,
nd->mnt->mnt_devname,
nd->path.mnt->mnt_devname,
dentry,
nd->dentry->d_name.name);
nd->path.dentry->d_name.name);
dput(nd->dentry);
nd->dentry = dget(dentry);
dput(nd->path.dentry);
nd->path.dentry = dget(dentry);
newmnt = afs_mntpt_do_automount(nd->dentry);
newmnt = afs_mntpt_do_automount(nd->path.dentry);
if (IS_ERR(newmnt)) {
path_release(nd);
return (void *)newmnt;
......@@ -235,17 +235,17 @@ static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd)
err = do_add_mount(newmnt, nd, MNT_SHRINKABLE, &afs_vfsmounts);
switch (err) {
case 0:
dput(nd->dentry);
mntput(nd->mnt);
nd->mnt = newmnt;
nd->dentry = dget(newmnt->mnt_root);
dput(nd->path.dentry);
mntput(nd->path.mnt);
nd->path.mnt = newmnt;
nd->path.dentry = dget(newmnt->mnt_root);
schedule_delayed_work(&afs_mntpt_expiry_timer,
afs_mntpt_expiry_timeout * HZ);
break;
case -EBUSY:
/* someone else made a mount here whilst we were busy */
while (d_mountpoint(nd->dentry) &&
follow_down(&nd->mnt, &nd->dentry))
while (d_mountpoint(nd->path.dentry) &&
follow_down(&nd->path.mnt, &nd->path.dentry))
;
err = 0;
default:
......
......@@ -368,7 +368,8 @@ static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
* so we don't need to follow the mount.
*/
if (d_mountpoint(dentry)) {
if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) {
if (!autofs4_follow_mount(&nd->path.mnt,
&nd->path.dentry)) {
status = -ENOENT;
goto out_error;
}
......
......@@ -1397,12 +1397,12 @@ struct block_device *lookup_bdev(const char *path)
if (error)
return ERR_PTR(error);
inode = nd.dentry->d_inode;
inode = nd.path.dentry->d_inode;
error = -ENOTBLK;
if (!S_ISBLK(inode->i_mode))
goto fail;
error = -EACCES;
if (nd.mnt->mnt_flags & MNT_NODEV)
if (nd.path.mnt->mnt_flags & MNT_NODEV)
goto fail;
error = -ENOMEM;
bdev = bd_acquire(inode);
......
......@@ -259,18 +259,18 @@ static int add_mount_helper(struct vfsmount *newmnt, struct nameidata *nd,
int err;
mntget(newmnt);
err = do_add_mount(newmnt, nd, nd->mnt->mnt_flags, mntlist);
err = do_add_mount(newmnt, nd, nd->path.mnt->mnt_flags, mntlist);
switch (err) {
case 0:
dput(nd->dentry);
mntput(nd->mnt);
nd->mnt = newmnt;
nd->dentry = dget(newmnt->mnt_root);
dput(nd->path.dentry);
mntput(nd->path.mnt);
nd->path.mnt = newmnt;
nd->path.dentry = dget(newmnt->mnt_root);
break;
case -EBUSY:
/* someone else made a mount here whilst we were busy */
while (d_mountpoint(nd->dentry) &&
follow_down(&nd->mnt, &nd->dentry))
while (d_mountpoint(nd->path.dentry) &&
follow_down(&nd->path.mnt, &nd->path.dentry))
;
err = 0;
default:
......@@ -307,8 +307,8 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
xid = GetXid();
dput(nd->dentry);
nd->dentry = dget(dentry);
dput(nd->path.dentry);
nd->path.dentry = dget(dentry);
cifs_sb = CIFS_SB(dentry->d_inode->i_sb);
ses = cifs_sb->tcon->ses;
......@@ -340,7 +340,8 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
rc = -EINVAL;
goto out_err;
}
mnt = cifs_dfs_do_refmount(nd->mnt, nd->dentry,
mnt = cifs_dfs_do_refmount(nd->path.mnt,
nd->path.dentry,
referrals[i].node_name);
cFYI(1, ("%s: cifs_dfs_do_refmount:%s , mnt:%p",
__FUNCTION__,
......@@ -357,7 +358,7 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
if (IS_ERR(mnt))
goto out_err;
nd->mnt->mnt_flags |= MNT_SHRINKABLE;
nd->path.mnt->mnt_flags |= MNT_SHRINKABLE;
rc = add_mount_helper(mnt, nd, &cifs_dfs_automount_list);
out:
......
......@@ -75,7 +75,7 @@ static int coda_pioctl(struct inode * inode, struct file * filp,
if ( error ) {
return error;
} else {
target_inode = nd.dentry->d_inode;
target_inode = nd.path.dentry->d_inode;
}
/* return if it is not a Coda inode */
......
......@@ -241,7 +241,7 @@ asmlinkage long compat_sys_statfs(const char __user *path, struct compat_statfs
error = user_path_walk(path, &nd);
if (!error) {
struct kstatfs tmp;
error = vfs_statfs(nd.dentry, &tmp);
error = vfs_statfs(nd.path.dentry, &tmp);
if (!error)
error = put_compat_statfs(buf, &tmp);
path_release(&nd);
......@@ -309,7 +309,7 @@ asmlinkage long compat_sys_statfs64(const char __user *path, compat_size_t sz, s
error = user_path_walk(path, &nd);
if (!error) {
struct kstatfs tmp;
error = vfs_statfs(nd.dentry, &tmp);
error = vfs_statfs(nd.path.dentry, &tmp);
if (!error)
error = put_compat_statfs64(buf, &tmp);
path_release(&nd);
......
......@@ -99,8 +99,8 @@ static int get_target(const char *symname, struct nameidata *nd,
ret = path_lookup(symname, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, nd);
if (!ret) {
if (nd->dentry->d_sb == configfs_sb) {
*target = configfs_get_config_item(nd->dentry);
if (nd->path.dentry->d_sb == configfs_sb) {
*target = configfs_get_config_item(nd->path.dentry);
if (!*target) {
ret = -ENOENT;
path_release(nd);
......
......@@ -1633,14 +1633,15 @@ int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path)
error = path_lookup(path, LOOKUP_FOLLOW, &nd);
if (error < 0)
return error;
error = security_quota_on(nd.dentry);
error = security_quota_on(nd.path.dentry);
if (error)
goto out_path;
/* Quota file not on the same filesystem? */
if (nd.mnt->mnt_sb != sb)
if (nd.path.mnt->mnt_sb != sb)
error = -EXDEV;
else
error = vfs_quota_on_inode(nd.dentry->d_inode, type, format_id);
error = vfs_quota_on_inode(nd.path.dentry->d_inode, type,
format_id);
out_path:
path_release(&nd);
return error;
......
......@@ -51,13 +51,13 @@ static int ecryptfs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
if (!lower_dentry->d_op || !lower_dentry->d_op->d_revalidate)
goto out;
dentry_save = nd->dentry;
vfsmount_save = nd->mnt;
nd->dentry = lower_dentry;
nd->mnt = lower_mnt;
dentry_save = nd->path.dentry;
vfsmount_save = nd->path.mnt;
nd->path.dentry = lower_dentry;
nd->path.mnt = lower_mnt;
rc = lower_dentry->d_op->d_revalidate(lower_dentry, nd);
nd->dentry = dentry_save;
nd->mnt = vfsmount_save;
nd->path.dentry = dentry_save;
nd->path.mnt = vfsmount_save;
if (dentry->d_inode) {
struct inode *lower_inode =
ecryptfs_inode_to_lower(dentry->d_inode);
......
......@@ -77,13 +77,13 @@ ecryptfs_create_underlying_file(struct inode *lower_dir_inode,
struct vfsmount *vfsmount_save;
int rc;
dentry_save = nd->dentry;
vfsmount_save = nd->mnt;
nd->dentry = lower_dentry;
nd->mnt = lower_mnt;
dentry_save = nd->path.dentry;
vfsmount_save = nd->path.mnt;
nd->path.dentry = lower_dentry;
nd->path.mnt = lower_mnt;
rc = vfs_create(lower_dir_inode, lower_dentry, mode, nd);
nd->dentry = dentry_save;
nd->mnt = vfsmount_save;
nd->path.dentry = dentry_save;
nd->path.mnt = vfsmount_save;
return rc;
}
......@@ -819,14 +819,14 @@ ecryptfs_permission(struct inode *inode, int mask, struct nameidata *nd)
int rc;
if (nd) {
struct vfsmount *vfsmnt_save = nd->mnt;
struct dentry *dentry_save = nd->dentry;
struct vfsmount *vfsmnt_save = nd->path.mnt;
struct dentry *dentry_save = nd->path.dentry;
nd->mnt = ecryptfs_dentry_to_lower_mnt(nd->dentry);
nd->dentry = ecryptfs_dentry_to_lower(nd->dentry);
nd->path.mnt = ecryptfs_dentry_to_lower_mnt(nd->path.dentry);
nd->path.dentry = ecryptfs_dentry_to_lower(nd->path.dentry);
rc = permission(ecryptfs_inode_to_lower(inode), mask, nd);
nd->mnt = vfsmnt_save;
nd->dentry = dentry_save;
nd->path.mnt = vfsmnt_save;
nd->path.dentry = dentry_save;
} else
rc = permission(ecryptfs_inode_to_lower(inode), mask, NULL);
return rc;
......
......@@ -513,8 +513,8 @@ static int ecryptfs_read_super(struct super_block *sb, const char *dev_name)
ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n");
goto out;
}
lower_root = nd.dentry;
lower_mnt = nd.mnt;
lower_root = nd.path.dentry;
lower_mnt = nd.path.mnt;
ecryptfs_set_superblock_lower(sb, lower_root->d_sb);
sb->s_maxbytes = lower_root->d_sb->s_maxbytes;
sb->s_blocksize = lower_root->d_sb->s_blocksize;
......
......@@ -112,7 +112,7 @@ asmlinkage long sys_uselib(const char __user * library)
goto out;
error = -EINVAL;
if (!S_ISREG(nd.dentry->d_inode->i_mode))
if (!S_ISREG(nd.path.dentry->d_inode->i_mode))
goto exit;
error = vfs_permission(&nd, MAY_READ | MAY_EXEC);
......@@ -652,7 +652,7 @@ struct file *open_exec(const char *name)
file = ERR_PTR(err);
if (!err) {
struct inode *inode = nd.dentry->d_inode;
struct inode *inode = nd.path.dentry->d_inode;
file = ERR_PTR(-EACCES);
if (S_ISREG(inode->i_mode)) {
int err = vfs_permission(&nd, MAY_EXEC);
......
......@@ -2758,12 +2758,12 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id,
if (err)
return err;
/* Quotafile not on the same filesystem? */
if (nd.mnt->mnt_sb != sb) {
if (nd.path.mnt->mnt_sb != sb) {
path_release(&nd);
return -EXDEV;
}
/* Quotafile not of fs root? */
if (nd.dentry->d_parent->d_inode != sb->s_root->d_inode)
if (nd.path.dentry->d_parent->d_inode != sb->s_root->d_inode)
printk(KERN_WARNING
"EXT3-fs: Quota file not on filesystem root. "
"Journalled quota will not work.\n");
......
......@@ -3158,12 +3158,12 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
if (err)
return err;
/* Quotafile not on the same filesystem? */
if (nd.mnt->mnt_sb != sb) {
if (nd.path.mnt->mnt_sb != sb) {
path_release(&nd);
return -EXDEV;
}
/* Quotafile not of fs root? */
if (nd.dentry->d_parent->d_inode != sb->s_root->d_inode)
if (nd.path.dentry->d_parent->d_inode != sb->s_root->d_inode)
printk(KERN_WARNING
"EXT4-fs: Quota file not on filesystem root. "
"Journalled quota will not work.\n");
......
......@@ -884,12 +884,13 @@ static struct super_block* get_gfs2_sb(const char *dev_name)
dev_name);
goto out;
}
error = vfs_getattr(nd.mnt, nd.dentry, &stat);
error = vfs_getattr(nd.path.mnt, nd.path.dentry, &stat);
fstype = get_fs_type("gfs2");
list_for_each_entry(s, &fstype->fs_supers, s_instances) {
if ((S_ISBLK(stat.mode) && s->s_dev == stat.rdev) ||
(S_ISDIR(stat.mode) && s == nd.dentry->d_inode->i_sb)) {
(S_ISDIR(stat.mode) &&
s == nd.path.dentry->d_inode->i_sb)) {
sb = s;
goto free_nd;
}
......
......@@ -667,7 +667,7 @@ asmlinkage long sys_inotify_add_watch(int fd, const char __user *path, u32 mask)
goto fput_and_out;
/* inode held in place by reference to nd; dev by fget on fd */
inode = nd.dentry->d_inode;
inode = nd.path.dentry->d_inode;
dev = filp->private_data;
mutex_lock(&dev->up_mutex);
......
......@@ -231,7 +231,7 @@ int permission(struct inode *inode, int mask, struct nameidata *nd)
struct vfsmount *mnt = NULL;
if (nd)
mnt = nd->mnt;
mnt = nd->path.mnt;
if (mask & MAY_WRITE) {
umode_t mode = inode->i_mode;
......@@ -296,7 +296,7 @@ int permission(struct inode *inode, int mask, struct nameidata *nd)
*/
int vfs_permission(struct nameidata *nd, int mask)
{
return permission(nd->dentry->d_inode, mask, nd);
return permission(nd->path.dentry->d_inode, mask, nd);
}
/**
......@@ -364,8 +364,8 @@ int deny_write_access(struct file * file)
void path_release(struct nameidata *nd)
{
dput(nd->dentry);
mntput(nd->mnt);
dput(nd->path.dentry);
mntput(nd->path.mnt);
}
/**
......@@ -530,15 +530,15 @@ walk_init_root(const char *name, struct nameidata *nd)
read_lock(&fs->lock);
if (fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
nd->mnt = mntget(fs->altrootmnt);
nd->dentry = dget(fs->altroot);
nd->path.mnt = mntget(fs->altrootmnt);
nd->path.dentry = dget(fs->altroot);
read_unlock(&fs->lock);
if (__emul_lookup_dentry(name,nd))
return 0;
read_lock(&fs->lock);
}
nd->mnt = mntget(fs->rootmnt);
nd->dentry = dget(fs->root);
nd->path.mnt = mntget(fs->rootmnt);
nd->path.dentry = dget(fs->root);
read_unlock(&fs->lock);
return 1;
}
......@@ -581,17 +581,17 @@ fail:
static inline void dput_path(struct path *path, struct nameidata *nd)
{
dput(path->dentry);
if (path->mnt != nd->mnt)
if (path->mnt != nd->path.mnt)
mntput(path->mnt);
}
static inline void path_to_nameidata(struct path *path, struct nameidata *nd)
{
dput(nd->dentry);
if (nd->mnt != path->mnt)
mntput(nd->mnt);
nd->mnt = path->mnt;
nd->dentry = path->dentry;
dput(nd->path.dentry);
if (nd->path.mnt != path->mnt)
mntput(nd->path.mnt);
nd->path.mnt = path->mnt;
nd->path.dentry = path->dentry;
}
static __always_inline int __do_follow_link(struct path *path, struct nameidata *nd)
......@@ -603,7 +603,7 @@ static __always_inline int __do_follow_link(struct path *path, struct nameidata
touch_atime(path->mnt, dentry);
nd_set_link(nd, NULL);