aboutsummaryrefslogtreecommitdiffstats
path: root/fs/namespace.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/namespace.c')
-rw-r--r--fs/namespace.c120
1 files changed, 62 insertions, 58 deletions
diff --git a/fs/namespace.c b/fs/namespace.c
index 55442a6cf221..5ef336c1103c 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -20,7 +20,7 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/sysfs.h> 21#include <linux/sysfs.h>
22#include <linux/seq_file.h> 22#include <linux/seq_file.h>
23#include <linux/namespace.h> 23#include <linux/mnt_namespace.h>
24#include <linux/namei.h> 24#include <linux/namei.h>
25#include <linux/security.h> 25#include <linux/security.h>
26#include <linux/mount.h> 26#include <linux/mount.h>
@@ -36,7 +36,7 @@ static int event;
36 36
37static struct list_head *mount_hashtable __read_mostly; 37static struct list_head *mount_hashtable __read_mostly;
38static int hash_mask __read_mostly, hash_bits __read_mostly; 38static int hash_mask __read_mostly, hash_bits __read_mostly;
39static kmem_cache_t *mnt_cache __read_mostly; 39static struct kmem_cache *mnt_cache __read_mostly;
40static struct rw_semaphore namespace_sem; 40static struct rw_semaphore namespace_sem;
41 41
42/* /sys/fs */ 42/* /sys/fs */
@@ -133,10 +133,10 @@ struct vfsmount *lookup_mnt(struct vfsmount *mnt, struct dentry *dentry)
133 133
134static inline int check_mnt(struct vfsmount *mnt) 134static inline int check_mnt(struct vfsmount *mnt)
135{ 135{
136 return mnt->mnt_namespace == current->nsproxy->namespace; 136 return mnt->mnt_ns == current->nsproxy->mnt_ns;
137} 137}
138 138
139static void touch_namespace(struct namespace *ns) 139static void touch_mnt_namespace(struct mnt_namespace *ns)
140{ 140{
141 if (ns) { 141 if (ns) {
142 ns->event = ++event; 142 ns->event = ++event;
@@ -144,7 +144,7 @@ static void touch_namespace(struct namespace *ns)
144 } 144 }
145} 145}
146 146
147static void __touch_namespace(struct namespace *ns) 147static void __touch_mnt_namespace(struct mnt_namespace *ns)
148{ 148{
149 if (ns && ns->event != event) { 149 if (ns && ns->event != event) {
150 ns->event = event; 150 ns->event = event;
@@ -187,19 +187,19 @@ static void commit_tree(struct vfsmount *mnt)
187 struct vfsmount *parent = mnt->mnt_parent; 187 struct vfsmount *parent = mnt->mnt_parent;
188 struct vfsmount *m; 188 struct vfsmount *m;
189 LIST_HEAD(head); 189 LIST_HEAD(head);
190 struct namespace *n = parent->mnt_namespace; 190 struct mnt_namespace *n = parent->mnt_ns;
191 191
192 BUG_ON(parent == mnt); 192 BUG_ON(parent == mnt);
193 193
194 list_add_tail(&head, &mnt->mnt_list); 194 list_add_tail(&head, &mnt->mnt_list);
195 list_for_each_entry(m, &head, mnt_list) 195 list_for_each_entry(m, &head, mnt_list)
196 m->mnt_namespace = n; 196 m->mnt_ns = n;
197 list_splice(&head, n->list.prev); 197 list_splice(&head, n->list.prev);
198 198
199 list_add_tail(&mnt->mnt_hash, mount_hashtable + 199 list_add_tail(&mnt->mnt_hash, mount_hashtable +
200 hash(parent, mnt->mnt_mountpoint)); 200 hash(parent, mnt->mnt_mountpoint));
201 list_add_tail(&mnt->mnt_child, &parent->mnt_mounts); 201 list_add_tail(&mnt->mnt_child, &parent->mnt_mounts);
202 touch_namespace(n); 202 touch_mnt_namespace(n);
203} 203}
204 204
205static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root) 205static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root)
@@ -320,7 +320,7 @@ EXPORT_SYMBOL(mnt_unpin);
320/* iterator */ 320/* iterator */
321static void *m_start(struct seq_file *m, loff_t *pos) 321static void *m_start(struct seq_file *m, loff_t *pos)
322{ 322{
323 struct namespace *n = m->private; 323 struct mnt_namespace *n = m->private;
324 struct list_head *p; 324 struct list_head *p;
325 loff_t l = *pos; 325 loff_t l = *pos;
326 326
@@ -333,7 +333,7 @@ static void *m_start(struct seq_file *m, loff_t *pos)
333 333
334static void *m_next(struct seq_file *m, void *v, loff_t *pos) 334static void *m_next(struct seq_file *m, void *v, loff_t *pos)
335{ 335{
336 struct namespace *n = m->private; 336 struct mnt_namespace *n = m->private;
337 struct list_head *p = ((struct vfsmount *)v)->mnt_list.next; 337 struct list_head *p = ((struct vfsmount *)v)->mnt_list.next;
338 (*pos)++; 338 (*pos)++;
339 return p == &n->list ? NULL : list_entry(p, struct vfsmount, mnt_list); 339 return p == &n->list ? NULL : list_entry(p, struct vfsmount, mnt_list);
@@ -368,6 +368,7 @@ static int show_vfsmnt(struct seq_file *m, void *v)
368 { MNT_NOEXEC, ",noexec" }, 368 { MNT_NOEXEC, ",noexec" },
369 { MNT_NOATIME, ",noatime" }, 369 { MNT_NOATIME, ",noatime" },
370 { MNT_NODIRATIME, ",nodiratime" }, 370 { MNT_NODIRATIME, ",nodiratime" },
371 { MNT_RELATIME, ",relatime" },
371 { 0, NULL } 372 { 0, NULL }
372 }; 373 };
373 struct proc_fs_info *fs_infop; 374 struct proc_fs_info *fs_infop;
@@ -526,8 +527,8 @@ void umount_tree(struct vfsmount *mnt, int propagate, struct list_head *kill)
526 list_for_each_entry(p, kill, mnt_hash) { 527 list_for_each_entry(p, kill, mnt_hash) {
527 list_del_init(&p->mnt_expire); 528 list_del_init(&p->mnt_expire);
528 list_del_init(&p->mnt_list); 529 list_del_init(&p->mnt_list);
529 __touch_namespace(p->mnt_namespace); 530 __touch_mnt_namespace(p->mnt_ns);
530 p->mnt_namespace = NULL; 531 p->mnt_ns = NULL;
531 list_del_init(&p->mnt_child); 532 list_del_init(&p->mnt_child);
532 if (p->mnt_parent != p) 533 if (p->mnt_parent != p)
533 p->mnt_mountpoint->d_mounted--; 534 p->mnt_mountpoint->d_mounted--;
@@ -830,7 +831,7 @@ static int attach_recursive_mnt(struct vfsmount *source_mnt,
830 if (parent_nd) { 831 if (parent_nd) {
831 detach_mnt(source_mnt, parent_nd); 832 detach_mnt(source_mnt, parent_nd);
832 attach_mnt(source_mnt, nd); 833 attach_mnt(source_mnt, nd);
833 touch_namespace(current->nsproxy->namespace); 834 touch_mnt_namespace(current->nsproxy->mnt_ns);
834 } else { 835 } else {
835 mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt); 836 mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt);
836 commit_tree(source_mnt); 837 commit_tree(source_mnt);
@@ -1145,9 +1146,9 @@ static void expire_mount(struct vfsmount *mnt, struct list_head *mounts,
1145 */ 1146 */
1146 if (!propagate_mount_busy(mnt, 2)) { 1147 if (!propagate_mount_busy(mnt, 2)) {
1147 /* delete from the namespace */ 1148 /* delete from the namespace */
1148 touch_namespace(mnt->mnt_namespace); 1149 touch_mnt_namespace(mnt->mnt_ns);
1149 list_del_init(&mnt->mnt_list); 1150 list_del_init(&mnt->mnt_list);
1150 mnt->mnt_namespace = NULL; 1151 mnt->mnt_ns = NULL;
1151 umount_tree(mnt, 1, umounts); 1152 umount_tree(mnt, 1, umounts);
1152 spin_unlock(&vfsmount_lock); 1153 spin_unlock(&vfsmount_lock);
1153 } else { 1154 } else {
@@ -1168,7 +1169,7 @@ static void expire_mount(struct vfsmount *mnt, struct list_head *mounts,
1168 */ 1169 */
1169static void expire_mount_list(struct list_head *graveyard, struct list_head *mounts) 1170static void expire_mount_list(struct list_head *graveyard, struct list_head *mounts)
1170{ 1171{
1171 struct namespace *namespace; 1172 struct mnt_namespace *ns;
1172 struct vfsmount *mnt; 1173 struct vfsmount *mnt;
1173 1174
1174 while (!list_empty(graveyard)) { 1175 while (!list_empty(graveyard)) {
@@ -1178,10 +1179,10 @@ static void expire_mount_list(struct list_head *graveyard, struct list_head *mou
1178 1179
1179 /* don't do anything if the namespace is dead - all the 1180 /* don't do anything if the namespace is dead - all the
1180 * vfsmounts from it are going away anyway */ 1181 * vfsmounts from it are going away anyway */
1181 namespace = mnt->mnt_namespace; 1182 ns = mnt->mnt_ns;
1182 if (!namespace || !namespace->root) 1183 if (!ns || !ns->root)
1183 continue; 1184 continue;
1184 get_namespace(namespace); 1185 get_mnt_ns(ns);
1185 1186
1186 spin_unlock(&vfsmount_lock); 1187 spin_unlock(&vfsmount_lock);
1187 down_write(&namespace_sem); 1188 down_write(&namespace_sem);
@@ -1189,7 +1190,7 @@ static void expire_mount_list(struct list_head *graveyard, struct list_head *mou
1189 up_write(&namespace_sem); 1190 up_write(&namespace_sem);
1190 release_mounts(&umounts); 1191 release_mounts(&umounts);
1191 mntput(mnt); 1192 mntput(mnt);
1192 put_namespace(namespace); 1193 put_mnt_ns(ns);
1193 spin_lock(&vfsmount_lock); 1194 spin_lock(&vfsmount_lock);
1194 } 1195 }
1195} 1196}
@@ -1405,9 +1406,11 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
1405 mnt_flags |= MNT_NOATIME; 1406 mnt_flags |= MNT_NOATIME;
1406 if (flags & MS_NODIRATIME) 1407 if (flags & MS_NODIRATIME)
1407 mnt_flags |= MNT_NODIRATIME; 1408 mnt_flags |= MNT_NODIRATIME;
1409 if (flags & MS_RELATIME)
1410 mnt_flags |= MNT_RELATIME;
1408 1411
1409 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | 1412 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
1410 MS_NOATIME | MS_NODIRATIME); 1413 MS_NOATIME | MS_NODIRATIME | MS_RELATIME);
1411 1414
1412 /* ... and get the mountpoint */ 1415 /* ... and get the mountpoint */
1413 retval = path_lookup(dir_name, LOOKUP_FOLLOW, &nd); 1416 retval = path_lookup(dir_name, LOOKUP_FOLLOW, &nd);
@@ -1439,14 +1442,15 @@ dput_out:
1439 * Allocate a new namespace structure and populate it with contents 1442 * Allocate a new namespace structure and populate it with contents
1440 * copied from the namespace of the passed in task structure. 1443 * copied from the namespace of the passed in task structure.
1441 */ 1444 */
1442struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs) 1445struct mnt_namespace *dup_mnt_ns(struct task_struct *tsk,
1446 struct fs_struct *fs)
1443{ 1447{
1444 struct namespace *namespace = tsk->nsproxy->namespace; 1448 struct mnt_namespace *mnt_ns = tsk->nsproxy->mnt_ns;
1445 struct namespace *new_ns; 1449 struct mnt_namespace *new_ns;
1446 struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL; 1450 struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL;
1447 struct vfsmount *p, *q; 1451 struct vfsmount *p, *q;
1448 1452
1449 new_ns = kmalloc(sizeof(struct namespace), GFP_KERNEL); 1453 new_ns = kmalloc(sizeof(struct mnt_namespace), GFP_KERNEL);
1450 if (!new_ns) 1454 if (!new_ns)
1451 return NULL; 1455 return NULL;
1452 1456
@@ -1457,7 +1461,7 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1457 1461
1458 down_write(&namespace_sem); 1462 down_write(&namespace_sem);
1459 /* First pass: copy the tree topology */ 1463 /* First pass: copy the tree topology */
1460 new_ns->root = copy_tree(namespace->root, namespace->root->mnt_root, 1464 new_ns->root = copy_tree(mnt_ns->root, mnt_ns->root->mnt_root,
1461 CL_COPY_ALL | CL_EXPIRE); 1465 CL_COPY_ALL | CL_EXPIRE);
1462 if (!new_ns->root) { 1466 if (!new_ns->root) {
1463 up_write(&namespace_sem); 1467 up_write(&namespace_sem);
@@ -1473,10 +1477,10 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1473 * as belonging to new namespace. We have already acquired a private 1477 * as belonging to new namespace. We have already acquired a private
1474 * fs_struct, so tsk->fs->lock is not needed. 1478 * fs_struct, so tsk->fs->lock is not needed.
1475 */ 1479 */
1476 p = namespace->root; 1480 p = mnt_ns->root;
1477 q = new_ns->root; 1481 q = new_ns->root;
1478 while (p) { 1482 while (p) {
1479 q->mnt_namespace = new_ns; 1483 q->mnt_ns = new_ns;
1480 if (fs) { 1484 if (fs) {
1481 if (p == fs->rootmnt) { 1485 if (p == fs->rootmnt) {
1482 rootmnt = p; 1486 rootmnt = p;
@@ -1491,7 +1495,7 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1491 fs->altrootmnt = mntget(q); 1495 fs->altrootmnt = mntget(q);
1492 } 1496 }
1493 } 1497 }
1494 p = next_mnt(p, namespace->root); 1498 p = next_mnt(p, mnt_ns->root);
1495 q = next_mnt(q, new_ns->root); 1499 q = next_mnt(q, new_ns->root);
1496 } 1500 }
1497 up_write(&namespace_sem); 1501 up_write(&namespace_sem);
@@ -1506,16 +1510,16 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1506 return new_ns; 1510 return new_ns;
1507} 1511}
1508 1512
1509int copy_namespace(int flags, struct task_struct *tsk) 1513int copy_mnt_ns(int flags, struct task_struct *tsk)
1510{ 1514{
1511 struct namespace *namespace = tsk->nsproxy->namespace; 1515 struct mnt_namespace *ns = tsk->nsproxy->mnt_ns;
1512 struct namespace *new_ns; 1516 struct mnt_namespace *new_ns;
1513 int err = 0; 1517 int err = 0;
1514 1518
1515 if (!namespace) 1519 if (!ns)
1516 return 0; 1520 return 0;
1517 1521
1518 get_namespace(namespace); 1522 get_mnt_ns(ns);
1519 1523
1520 if (!(flags & CLONE_NEWNS)) 1524 if (!(flags & CLONE_NEWNS))
1521 return 0; 1525 return 0;
@@ -1525,16 +1529,16 @@ int copy_namespace(int flags, struct task_struct *tsk)
1525 goto out; 1529 goto out;
1526 } 1530 }
1527 1531
1528 new_ns = dup_namespace(tsk, tsk->fs); 1532 new_ns = dup_mnt_ns(tsk, tsk->fs);
1529 if (!new_ns) { 1533 if (!new_ns) {
1530 err = -ENOMEM; 1534 err = -ENOMEM;
1531 goto out; 1535 goto out;
1532 } 1536 }
1533 1537
1534 tsk->nsproxy->namespace = new_ns; 1538 tsk->nsproxy->mnt_ns = new_ns;
1535 1539
1536out: 1540out:
1537 put_namespace(namespace); 1541 put_mnt_ns(ns);
1538 return err; 1542 return err;
1539} 1543}
1540 1544
@@ -1754,7 +1758,7 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
1754 detach_mnt(user_nd.mnt, &root_parent); 1758 detach_mnt(user_nd.mnt, &root_parent);
1755 attach_mnt(user_nd.mnt, &old_nd); /* mount old root on put_old */ 1759 attach_mnt(user_nd.mnt, &old_nd); /* mount old root on put_old */
1756 attach_mnt(new_nd.mnt, &root_parent); /* mount new_root on / */ 1760 attach_mnt(new_nd.mnt, &root_parent); /* mount new_root on / */
1757 touch_namespace(current->nsproxy->namespace); 1761 touch_mnt_namespace(current->nsproxy->mnt_ns);
1758 spin_unlock(&vfsmount_lock); 1762 spin_unlock(&vfsmount_lock);
1759 chroot_fs_refs(&user_nd, &new_nd); 1763 chroot_fs_refs(&user_nd, &new_nd);
1760 security_sb_post_pivotroot(&user_nd, &new_nd); 1764 security_sb_post_pivotroot(&user_nd, &new_nd);
@@ -1779,27 +1783,27 @@ out3:
1779static void __init init_mount_tree(void) 1783static void __init init_mount_tree(void)
1780{ 1784{
1781 struct vfsmount *mnt; 1785 struct vfsmount *mnt;
1782 struct namespace *namespace; 1786 struct mnt_namespace *ns;
1783 1787
1784 mnt = do_kern_mount("rootfs", 0, "rootfs", NULL); 1788 mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
1785 if (IS_ERR(mnt)) 1789 if (IS_ERR(mnt))
1786 panic("Can't create rootfs"); 1790 panic("Can't create rootfs");
1787 namespace = kmalloc(sizeof(*namespace), GFP_KERNEL); 1791 ns = kmalloc(sizeof(*ns), GFP_KERNEL);
1788 if (!namespace) 1792 if (!ns)
1789 panic("Can't allocate initial namespace"); 1793 panic("Can't allocate initial namespace");
1790 atomic_set(&namespace->count, 1); 1794 atomic_set(&ns->count, 1);
1791 INIT_LIST_HEAD(&namespace->list); 1795 INIT_LIST_HEAD(&ns->list);
1792 init_waitqueue_head(&namespace->poll); 1796 init_waitqueue_head(&ns->poll);
1793 namespace->event = 0; 1797 ns->event = 0;
1794 list_add(&mnt->mnt_list, &namespace->list); 1798 list_add(&mnt->mnt_list, &ns->list);
1795 namespace->root = mnt; 1799 ns->root = mnt;
1796 mnt->mnt_namespace = namespace; 1800 mnt->mnt_ns = ns;
1797 1801
1798 init_task.nsproxy->namespace = namespace; 1802 init_task.nsproxy->mnt_ns = ns;
1799 get_namespace(namespace); 1803 get_mnt_ns(ns);
1800 1804
1801 set_fs_pwd(current->fs, namespace->root, namespace->root->mnt_root); 1805 set_fs_pwd(current->fs, ns->root, ns->root->mnt_root);
1802 set_fs_root(current->fs, namespace->root, namespace->root->mnt_root); 1806 set_fs_root(current->fs, ns->root, ns->root->mnt_root);
1803} 1807}
1804 1808
1805void __init mnt_init(unsigned long mempages) 1809void __init mnt_init(unsigned long mempages)
@@ -1860,11 +1864,11 @@ void __init mnt_init(unsigned long mempages)
1860 init_mount_tree(); 1864 init_mount_tree();
1861} 1865}
1862 1866
1863void __put_namespace(struct namespace *namespace) 1867void __put_mnt_ns(struct mnt_namespace *ns)
1864{ 1868{
1865 struct vfsmount *root = namespace->root; 1869 struct vfsmount *root = ns->root;
1866 LIST_HEAD(umount_list); 1870 LIST_HEAD(umount_list);
1867 namespace->root = NULL; 1871 ns->root = NULL;
1868 spin_unlock(&vfsmount_lock); 1872 spin_unlock(&vfsmount_lock);
1869 down_write(&namespace_sem); 1873 down_write(&namespace_sem);
1870 spin_lock(&vfsmount_lock); 1874 spin_lock(&vfsmount_lock);
@@ -1872,5 +1876,5 @@ void __put_namespace(struct namespace *namespace)
1872 spin_unlock(&vfsmount_lock); 1876 spin_unlock(&vfsmount_lock);
1873 up_write(&namespace_sem); 1877 up_write(&namespace_sem);
1874 release_mounts(&umount_list); 1878 release_mounts(&umount_list);
1875 kfree(namespace); 1879 kfree(ns);
1876} 1880}