[PATCH] reduce stack footprint in namespace.c

A lot of places misuse struct nameidata when they need struct path.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 1a390689 3085354d

+37 -35
+37 -35
fs/namespace.c
··· 155 155 } 156 156 } 157 157 158 - static void detach_mnt(struct vfsmount *mnt, struct nameidata *old_nd) 158 + static void detach_mnt(struct vfsmount *mnt, struct path *old_path) 159 159 { 160 - old_nd->path.dentry = mnt->mnt_mountpoint; 161 - old_nd->path.mnt = mnt->mnt_parent; 160 + old_path->dentry = mnt->mnt_mountpoint; 161 + old_path->mnt = mnt->mnt_parent; 162 162 mnt->mnt_parent = mnt; 163 163 mnt->mnt_mountpoint = mnt->mnt_root; 164 164 list_del_init(&mnt->mnt_child); 165 165 list_del_init(&mnt->mnt_hash); 166 - old_nd->path.dentry->d_mounted--; 166 + old_path->dentry->d_mounted--; 167 167 } 168 168 169 169 void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry, ··· 174 174 dentry->d_mounted++; 175 175 } 176 176 177 - static void attach_mnt(struct vfsmount *mnt, struct nameidata *nd) 177 + static void attach_mnt(struct vfsmount *mnt, struct path *path) 178 178 { 179 - mnt_set_mountpoint(nd->path.mnt, nd->path.dentry, mnt); 179 + mnt_set_mountpoint(path->mnt, path->dentry, mnt); 180 180 list_add_tail(&mnt->mnt_hash, mount_hashtable + 181 - hash(nd->path.mnt, nd->path.dentry)); 182 - list_add_tail(&mnt->mnt_child, &nd->path.mnt->mnt_mounts); 181 + hash(path->mnt, path->dentry)); 182 + list_add_tail(&mnt->mnt_child, &path->mnt->mnt_mounts); 183 183 } 184 184 185 185 /* ··· 744 744 int flag) 745 745 { 746 746 struct vfsmount *res, *p, *q, *r, *s; 747 - struct nameidata nd; 747 + struct path path; 748 748 749 749 if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(mnt)) 750 750 return NULL; ··· 769 769 q = q->mnt_parent; 770 770 } 771 771 p = s; 772 - nd.path.mnt = q; 773 - nd.path.dentry = p->mnt_mountpoint; 772 + path.mnt = q; 773 + path.dentry = p->mnt_mountpoint; 774 774 q = clone_mnt(p, p->mnt_root, flag); 775 775 if (!q) 776 776 goto Enomem; 777 777 spin_lock(&vfsmount_lock); 778 778 list_add_tail(&q->mnt_list, &res->mnt_list); 779 - attach_mnt(q, &nd); 779 + attach_mnt(q, &path); 780 780 spin_unlock(&vfsmount_lock); 781 781 } 782 782 } ··· 876 876 * in allocations. 877 877 */ 878 878 static int attach_recursive_mnt(struct vfsmount *source_mnt, 879 - struct nameidata *nd, struct nameidata *parent_nd) 879 + struct path *path, struct path *parent_path) 880 880 { 881 881 LIST_HEAD(tree_list); 882 - struct vfsmount *dest_mnt = nd->path.mnt; 883 - struct dentry *dest_dentry = nd->path.dentry; 882 + struct vfsmount *dest_mnt = path->mnt; 883 + struct dentry *dest_dentry = path->dentry; 884 884 struct vfsmount *child, *p; 885 885 886 886 if (propagate_mnt(dest_mnt, dest_dentry, source_mnt, &tree_list)) ··· 892 892 } 893 893 894 894 spin_lock(&vfsmount_lock); 895 - if (parent_nd) { 896 - detach_mnt(source_mnt, parent_nd); 897 - attach_mnt(source_mnt, nd); 895 + if (parent_path) { 896 + detach_mnt(source_mnt, parent_path); 897 + attach_mnt(source_mnt, path); 898 898 touch_mnt_namespace(current->nsproxy->mnt_ns); 899 899 } else { 900 900 mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt); ··· 930 930 931 931 err = -ENOENT; 932 932 if (IS_ROOT(nd->path.dentry) || !d_unhashed(nd->path.dentry)) 933 - err = attach_recursive_mnt(mnt, nd, NULL); 933 + err = attach_recursive_mnt(mnt, &nd->path, NULL); 934 934 out_unlock: 935 935 mutex_unlock(&nd->path.dentry->d_inode->i_mutex); 936 936 if (!err) ··· 1059 1059 */ 1060 1060 static noinline int do_move_mount(struct nameidata *nd, char *old_name) 1061 1061 { 1062 - struct nameidata old_nd, parent_nd; 1062 + struct nameidata old_nd; 1063 + struct path parent_path; 1063 1064 struct vfsmount *p; 1064 1065 int err = 0; 1065 1066 if (!capable(CAP_SYS_ADMIN)) ··· 1115 1114 if (p == old_nd.path.mnt) 1116 1115 goto out1; 1117 1116 1118 - err = attach_recursive_mnt(old_nd.path.mnt, nd, &parent_nd); 1117 + err = attach_recursive_mnt(old_nd.path.mnt, &nd->path, &parent_path); 1119 1118 if (err) 1120 1119 goto out1; 1121 1120 ··· 1129 1128 out: 1130 1129 up_write(&namespace_sem); 1131 1130 if (!err) 1132 - path_put(&parent_nd.path); 1131 + path_put(&parent_path); 1133 1132 path_put(&old_nd.path); 1134 1133 return err; 1135 1134 } ··· 1684 1683 path_put(&old_pwd); 1685 1684 } 1686 1685 1687 - static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd) 1686 + static void chroot_fs_refs(struct path *old_root, struct path *new_root) 1688 1687 { 1689 1688 struct task_struct *g, *p; 1690 1689 struct fs_struct *fs; ··· 1696 1695 if (fs) { 1697 1696 atomic_inc(&fs->count); 1698 1697 task_unlock(p); 1699 - if (fs->root.dentry == old_nd->path.dentry 1700 - && fs->root.mnt == old_nd->path.mnt) 1701 - set_fs_root(fs, &new_nd->path); 1702 - if (fs->pwd.dentry == old_nd->path.dentry 1703 - && fs->pwd.mnt == old_nd->path.mnt) 1704 - set_fs_pwd(fs, &new_nd->path); 1698 + if (fs->root.dentry == old_root->dentry 1699 + && fs->root.mnt == old_root->mnt) 1700 + set_fs_root(fs, new_root); 1701 + if (fs->pwd.dentry == old_root->dentry 1702 + && fs->pwd.mnt == old_root->mnt) 1703 + set_fs_pwd(fs, new_root); 1705 1704 put_fs_struct(fs); 1706 1705 } else 1707 1706 task_unlock(p); ··· 1738 1737 const char __user * put_old) 1739 1738 { 1740 1739 struct vfsmount *tmp; 1741 - struct nameidata new_nd, old_nd, parent_nd, root_parent, user_nd; 1740 + struct nameidata new_nd, old_nd, user_nd; 1741 + struct path parent_path, root_parent; 1742 1742 int error; 1743 1743 1744 1744 if (!capable(CAP_SYS_ADMIN)) ··· 1813 1811 goto out3; 1814 1812 } else if (!is_subdir(old_nd.path.dentry, new_nd.path.dentry)) 1815 1813 goto out3; 1816 - detach_mnt(new_nd.path.mnt, &parent_nd); 1814 + detach_mnt(new_nd.path.mnt, &parent_path); 1817 1815 detach_mnt(user_nd.path.mnt, &root_parent); 1818 1816 /* mount old root on put_old */ 1819 - attach_mnt(user_nd.path.mnt, &old_nd); 1817 + attach_mnt(user_nd.path.mnt, &old_nd.path); 1820 1818 /* mount new_root on / */ 1821 1819 attach_mnt(new_nd.path.mnt, &root_parent); 1822 1820 touch_mnt_namespace(current->nsproxy->mnt_ns); 1823 1821 spin_unlock(&vfsmount_lock); 1824 - chroot_fs_refs(&user_nd, &new_nd); 1822 + chroot_fs_refs(&user_nd.path, &new_nd.path); 1825 1823 security_sb_post_pivotroot(&user_nd, &new_nd); 1826 1824 error = 0; 1827 - path_put(&root_parent.path); 1828 - path_put(&parent_nd.path); 1825 + path_put(&root_parent); 1826 + path_put(&parent_path); 1829 1827 out2: 1830 1828 mutex_unlock(&old_nd.path.dentry->d_inode->i_mutex); 1831 1829 up_write(&namespace_sem);