Skip to content

Commit

Permalink
Embed a struct path into struct nameidata instead of nd->{dentry,mnt}
Browse files Browse the repository at this point in the history
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.

[[email protected]: coding-style fixes]
[[email protected]: fix cifs]
[[email protected]: fix smack]
Signed-off-by: Jan Blunck <[email protected]>
Signed-off-by: Andreas Gruenbacher <[email protected]>
Acked-by: Christoph Hellwig <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Casey Schaufler <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Jan Blunck authored and Linus Torvalds committed Feb 15, 2008
1 parent c5e725f commit 4ac9137
Show file tree
Hide file tree
Showing 47 changed files with 431 additions and 402 deletions.
2 changes: 1 addition & 1 deletion arch/alpha/kernel/osf_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions arch/mips/kernel/sysirix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion arch/parisc/hpux/sys_hpux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 10 additions & 8 deletions arch/powerpc/platforms/cell/spufs/inode.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* SPU file system
*
Expand Down Expand Up @@ -592,17 +593,17 @@ 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 */
if (flags & (~SPU_CREATE_FLAG_ALL))
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;
}

Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions arch/sparc64/solaris/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions arch/um/drivers/mconsole_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion drivers/md/dm-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions drivers/mtd/mtdsuper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 11 additions & 11 deletions fs/afs/mntpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion fs/autofs4/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 12 additions & 11 deletions fs/cifs/cifs_dfs_ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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__,
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion fs/coda/pioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions fs/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions fs/configfs/symlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions fs/dquot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions fs/ecryptfs/dentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 4ac9137

Please sign in to comment.