aboutsummaryrefslogtreecommitdiffstats
path: root/fs/namespace.c
diff options
context:
space:
mode:
authorKirill Korotaev <dev@sw.ru>2006-12-08 05:37:56 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-08 11:28:51 -0500
commit6b3286ed1169d74fea401367d6d4d6c6ec758a81 (patch)
treefaf5beddb797875bb92855f8606735478267959a /fs/namespace.c
parent1ec320afdc9552c92191d5f89fcd1ebe588334ca (diff)
[PATCH] rename struct namespace to struct mnt_namespace
Rename 'struct namespace' to 'struct mnt_namespace' to avoid confusion with other namespaces being developped for the containers : pid, uts, ipc, etc. 'namespace' variables and attributes are also renamed to 'mnt_ns' Signed-off-by: Kirill Korotaev <dev@sw.ru> Signed-off-by: Cedric Le Goater <clg@fr.ibm.com> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Herbert Poetzl <herbert@13thfloor.at> Cc: Sukadev Bhattiprolu <sukadev@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/namespace.c')
-rw-r--r--fs/namespace.c113
1 files changed, 57 insertions, 56 deletions
diff --git a/fs/namespace.c b/fs/namespace.c
index b00ac84ebbdd..fde8553faa76 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>
@@ -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);
@@ -526,8 +526,8 @@ void umount_tree(struct vfsmount *mnt, int propagate, struct list_head *kill)
526 list_for_each_entry(p, kill, mnt_hash) { 526 list_for_each_entry(p, kill, mnt_hash) {
527 list_del_init(&p->mnt_expire); 527 list_del_init(&p->mnt_expire);
528 list_del_init(&p->mnt_list); 528 list_del_init(&p->mnt_list);
529 __touch_namespace(p->mnt_namespace); 529 __touch_mnt_namespace(p->mnt_ns);
530 p->mnt_namespace = NULL; 530 p->mnt_ns = NULL;
531 list_del_init(&p->mnt_child); 531 list_del_init(&p->mnt_child);
532 if (p->mnt_parent != p) 532 if (p->mnt_parent != p)
533 p->mnt_mountpoint->d_mounted--; 533 p->mnt_mountpoint->d_mounted--;
@@ -830,7 +830,7 @@ static int attach_recursive_mnt(struct vfsmount *source_mnt,
830 if (parent_nd) { 830 if (parent_nd) {
831 detach_mnt(source_mnt, parent_nd); 831 detach_mnt(source_mnt, parent_nd);
832 attach_mnt(source_mnt, nd); 832 attach_mnt(source_mnt, nd);
833 touch_namespace(current->nsproxy->namespace); 833 touch_mnt_namespace(current->nsproxy->mnt_ns);
834 } else { 834 } else {
835 mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt); 835 mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt);
836 commit_tree(source_mnt); 836 commit_tree(source_mnt);
@@ -1145,9 +1145,9 @@ static void expire_mount(struct vfsmount *mnt, struct list_head *mounts,
1145 */ 1145 */
1146 if (!propagate_mount_busy(mnt, 2)) { 1146 if (!propagate_mount_busy(mnt, 2)) {
1147 /* delete from the namespace */ 1147 /* delete from the namespace */
1148 touch_namespace(mnt->mnt_namespace); 1148 touch_mnt_namespace(mnt->mnt_ns);
1149 list_del_init(&mnt->mnt_list); 1149 list_del_init(&mnt->mnt_list);
1150 mnt->mnt_namespace = NULL; 1150 mnt->mnt_ns = NULL;
1151 umount_tree(mnt, 1, umounts); 1151 umount_tree(mnt, 1, umounts);
1152 spin_unlock(&vfsmount_lock); 1152 spin_unlock(&vfsmount_lock);
1153 } else { 1153 } else {
@@ -1168,7 +1168,7 @@ static void expire_mount(struct vfsmount *mnt, struct list_head *mounts,
1168 */ 1168 */
1169static void expire_mount_list(struct list_head *graveyard, struct list_head *mounts) 1169static void expire_mount_list(struct list_head *graveyard, struct list_head *mounts)
1170{ 1170{
1171 struct namespace *namespace; 1171 struct mnt_namespace *ns;
1172 struct vfsmount *mnt; 1172 struct vfsmount *mnt;
1173 1173
1174 while (!list_empty(graveyard)) { 1174 while (!list_empty(graveyard)) {
@@ -1178,10 +1178,10 @@ static void expire_mount_list(struct list_head *graveyard, struct list_head *mou
1178 1178
1179 /* don't do anything if the namespace is dead - all the 1179 /* don't do anything if the namespace is dead - all the
1180 * vfsmounts from it are going away anyway */ 1180 * vfsmounts from it are going away anyway */
1181 namespace = mnt->mnt_namespace; 1181 ns = mnt->mnt_ns;
1182 if (!namespace || !namespace->root) 1182 if (!ns || !ns->root)
1183 continue; 1183 continue;
1184 get_namespace(namespace); 1184 get_mnt_ns(ns);
1185 1185
1186 spin_unlock(&vfsmount_lock); 1186 spin_unlock(&vfsmount_lock);
1187 down_write(&namespace_sem); 1187 down_write(&namespace_sem);
@@ -1189,7 +1189,7 @@ static void expire_mount_list(struct list_head *graveyard, struct list_head *mou
1189 up_write(&namespace_sem); 1189 up_write(&namespace_sem);
1190 release_mounts(&umounts); 1190 release_mounts(&umounts);
1191 mntput(mnt); 1191 mntput(mnt);
1192 put_namespace(namespace); 1192 put_mnt_ns(ns);
1193 spin_lock(&vfsmount_lock); 1193 spin_lock(&vfsmount_lock);
1194 } 1194 }
1195} 1195}
@@ -1439,14 +1439,15 @@ dput_out:
1439 * Allocate a new namespace structure and populate it with contents 1439 * Allocate a new namespace structure and populate it with contents
1440 * copied from the namespace of the passed in task structure. 1440 * copied from the namespace of the passed in task structure.
1441 */ 1441 */
1442struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs) 1442struct mnt_namespace *dup_mnt_ns(struct task_struct *tsk,
1443 struct fs_struct *fs)
1443{ 1444{
1444 struct namespace *namespace = tsk->nsproxy->namespace; 1445 struct mnt_namespace *mnt_ns = tsk->nsproxy->mnt_ns;
1445 struct namespace *new_ns; 1446 struct mnt_namespace *new_ns;
1446 struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL; 1447 struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL;
1447 struct vfsmount *p, *q; 1448 struct vfsmount *p, *q;
1448 1449
1449 new_ns = kmalloc(sizeof(struct namespace), GFP_KERNEL); 1450 new_ns = kmalloc(sizeof(struct mnt_namespace), GFP_KERNEL);
1450 if (!new_ns) 1451 if (!new_ns)
1451 return NULL; 1452 return NULL;
1452 1453
@@ -1457,7 +1458,7 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1457 1458
1458 down_write(&namespace_sem); 1459 down_write(&namespace_sem);
1459 /* First pass: copy the tree topology */ 1460 /* First pass: copy the tree topology */
1460 new_ns->root = copy_tree(namespace->root, namespace->root->mnt_root, 1461 new_ns->root = copy_tree(mnt_ns->root, mnt_ns->root->mnt_root,
1461 CL_COPY_ALL | CL_EXPIRE); 1462 CL_COPY_ALL | CL_EXPIRE);
1462 if (!new_ns->root) { 1463 if (!new_ns->root) {
1463 up_write(&namespace_sem); 1464 up_write(&namespace_sem);
@@ -1473,10 +1474,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 1474 * as belonging to new namespace. We have already acquired a private
1474 * fs_struct, so tsk->fs->lock is not needed. 1475 * fs_struct, so tsk->fs->lock is not needed.
1475 */ 1476 */
1476 p = namespace->root; 1477 p = mnt_ns->root;
1477 q = new_ns->root; 1478 q = new_ns->root;
1478 while (p) { 1479 while (p) {
1479 q->mnt_namespace = new_ns; 1480 q->mnt_ns = new_ns;
1480 if (fs) { 1481 if (fs) {
1481 if (p == fs->rootmnt) { 1482 if (p == fs->rootmnt) {
1482 rootmnt = p; 1483 rootmnt = p;
@@ -1491,7 +1492,7 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1491 fs->altrootmnt = mntget(q); 1492 fs->altrootmnt = mntget(q);
1492 } 1493 }
1493 } 1494 }
1494 p = next_mnt(p, namespace->root); 1495 p = next_mnt(p, mnt_ns->root);
1495 q = next_mnt(q, new_ns->root); 1496 q = next_mnt(q, new_ns->root);
1496 } 1497 }
1497 up_write(&namespace_sem); 1498 up_write(&namespace_sem);
@@ -1506,16 +1507,16 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1506 return new_ns; 1507 return new_ns;
1507} 1508}
1508 1509
1509int copy_namespace(int flags, struct task_struct *tsk) 1510int copy_mnt_ns(int flags, struct task_struct *tsk)
1510{ 1511{
1511 struct namespace *namespace = tsk->nsproxy->namespace; 1512 struct mnt_namespace *ns = tsk->nsproxy->mnt_ns;
1512 struct namespace *new_ns; 1513 struct mnt_namespace *new_ns;
1513 int err = 0; 1514 int err = 0;
1514 1515
1515 if (!namespace) 1516 if (!ns)
1516 return 0; 1517 return 0;
1517 1518
1518 get_namespace(namespace); 1519 get_mnt_ns(ns);
1519 1520
1520 if (!(flags & CLONE_NEWNS)) 1521 if (!(flags & CLONE_NEWNS))
1521 return 0; 1522 return 0;
@@ -1525,16 +1526,16 @@ int copy_namespace(int flags, struct task_struct *tsk)
1525 goto out; 1526 goto out;
1526 } 1527 }
1527 1528
1528 new_ns = dup_namespace(tsk, tsk->fs); 1529 new_ns = dup_mnt_ns(tsk, tsk->fs);
1529 if (!new_ns) { 1530 if (!new_ns) {
1530 err = -ENOMEM; 1531 err = -ENOMEM;
1531 goto out; 1532 goto out;
1532 } 1533 }
1533 1534
1534 tsk->nsproxy->namespace = new_ns; 1535 tsk->nsproxy->mnt_ns = new_ns;
1535 1536
1536out: 1537out:
1537 put_namespace(namespace); 1538 put_mnt_ns(ns);
1538 return err; 1539 return err;
1539} 1540}
1540 1541
@@ -1754,7 +1755,7 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
1754 detach_mnt(user_nd.mnt, &root_parent); 1755 detach_mnt(user_nd.mnt, &root_parent);
1755 attach_mnt(user_nd.mnt, &old_nd); /* mount old root on put_old */ 1756 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 / */ 1757 attach_mnt(new_nd.mnt, &root_parent); /* mount new_root on / */
1757 touch_namespace(current->nsproxy->namespace); 1758 touch_mnt_namespace(current->nsproxy->mnt_ns);
1758 spin_unlock(&vfsmount_lock); 1759 spin_unlock(&vfsmount_lock);
1759 chroot_fs_refs(&user_nd, &new_nd); 1760 chroot_fs_refs(&user_nd, &new_nd);
1760 security_sb_post_pivotroot(&user_nd, &new_nd); 1761 security_sb_post_pivotroot(&user_nd, &new_nd);
@@ -1779,27 +1780,27 @@ out3:
1779static void __init init_mount_tree(void) 1780static void __init init_mount_tree(void)
1780{ 1781{
1781 struct vfsmount *mnt; 1782 struct vfsmount *mnt;
1782 struct namespace *namespace; 1783 struct mnt_namespace *ns;
1783 1784
1784 mnt = do_kern_mount("rootfs", 0, "rootfs", NULL); 1785 mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
1785 if (IS_ERR(mnt)) 1786 if (IS_ERR(mnt))
1786 panic("Can't create rootfs"); 1787 panic("Can't create rootfs");
1787 namespace = kmalloc(sizeof(*namespace), GFP_KERNEL); 1788 ns = kmalloc(sizeof(*ns), GFP_KERNEL);
1788 if (!namespace) 1789 if (!ns)
1789 panic("Can't allocate initial namespace"); 1790 panic("Can't allocate initial namespace");
1790 atomic_set(&namespace->count, 1); 1791 atomic_set(&ns->count, 1);
1791 INIT_LIST_HEAD(&namespace->list); 1792 INIT_LIST_HEAD(&ns->list);
1792 init_waitqueue_head(&namespace->poll); 1793 init_waitqueue_head(&ns->poll);
1793 namespace->event = 0; 1794 ns->event = 0;
1794 list_add(&mnt->mnt_list, &namespace->list); 1795 list_add(&mnt->mnt_list, &ns->list);
1795 namespace->root = mnt; 1796 ns->root = mnt;
1796 mnt->mnt_namespace = namespace; 1797 mnt->mnt_ns = ns;
1797 1798
1798 init_task.nsproxy->namespace = namespace; 1799 init_task.nsproxy->mnt_ns = ns;
1799 get_namespace(namespace); 1800 get_mnt_ns(ns);
1800 1801
1801 set_fs_pwd(current->fs, namespace->root, namespace->root->mnt_root); 1802 set_fs_pwd(current->fs, ns->root, ns->root->mnt_root);
1802 set_fs_root(current->fs, namespace->root, namespace->root->mnt_root); 1803 set_fs_root(current->fs, ns->root, ns->root->mnt_root);
1803} 1804}
1804 1805
1805void __init mnt_init(unsigned long mempages) 1806void __init mnt_init(unsigned long mempages)
@@ -1860,11 +1861,11 @@ void __init mnt_init(unsigned long mempages)
1860 init_mount_tree(); 1861 init_mount_tree();
1861} 1862}
1862 1863
1863void __put_namespace(struct namespace *namespace) 1864void __put_mnt_ns(struct mnt_namespace *ns)
1864{ 1865{
1865 struct vfsmount *root = namespace->root; 1866 struct vfsmount *root = ns->root;
1866 LIST_HEAD(umount_list); 1867 LIST_HEAD(umount_list);
1867 namespace->root = NULL; 1868 ns->root = NULL;
1868 spin_unlock(&vfsmount_lock); 1869 spin_unlock(&vfsmount_lock);
1869 down_write(&namespace_sem); 1870 down_write(&namespace_sem);
1870 spin_lock(&vfsmount_lock); 1871 spin_lock(&vfsmount_lock);
@@ -1872,5 +1873,5 @@ void __put_namespace(struct namespace *namespace)
1872 spin_unlock(&vfsmount_lock); 1873 spin_unlock(&vfsmount_lock);
1873 up_write(&namespace_sem); 1874 up_write(&namespace_sem);
1874 release_mounts(&umount_list); 1875 release_mounts(&umount_list);
1875 kfree(namespace); 1876 kfree(ns);
1876} 1877}