aboutsummaryrefslogtreecommitdiffstats
path: root/fs/namespace.c
diff options
context:
space:
mode:
authorRam Pai <linuxram@us.ibm.com>2005-11-07 17:16:09 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-07 21:18:10 -0500
commitb58fed8b1959d6b9e4c951a54adc8960e1401b18 (patch)
tree7e7ddca31fcbb263c03b33a6e29e09eff4d1ac26 /fs/namespace.c
parent5addc5dd8836aa061f6efc4a0d9ba6323726297a (diff)
[PATCH] lindent fs/namespace.c
Signed-off-by: Ram Pai <linuxram@us.ibm.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/namespace.c')
-rw-r--r--fs/namespace.c97
1 files changed, 48 insertions, 49 deletions
diff --git a/fs/namespace.c b/fs/namespace.c
index d1aca685aacf..685687dccbf1 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -43,29 +43,29 @@ static int event;
43 43
44static struct list_head *mount_hashtable; 44static struct list_head *mount_hashtable;
45static int hash_mask __read_mostly, hash_bits __read_mostly; 45static int hash_mask __read_mostly, hash_bits __read_mostly;
46static kmem_cache_t *mnt_cache; 46static kmem_cache_t *mnt_cache;
47 47
48static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry) 48static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
49{ 49{
50 unsigned long tmp = ((unsigned long) mnt / L1_CACHE_BYTES); 50 unsigned long tmp = ((unsigned long)mnt / L1_CACHE_BYTES);
51 tmp += ((unsigned long) dentry / L1_CACHE_BYTES); 51 tmp += ((unsigned long)dentry / L1_CACHE_BYTES);
52 tmp = tmp + (tmp >> hash_bits); 52 tmp = tmp + (tmp >> hash_bits);
53 return tmp & hash_mask; 53 return tmp & hash_mask;
54} 54}
55 55
56struct vfsmount *alloc_vfsmnt(const char *name) 56struct vfsmount *alloc_vfsmnt(const char *name)
57{ 57{
58 struct vfsmount *mnt = kmem_cache_alloc(mnt_cache, GFP_KERNEL); 58 struct vfsmount *mnt = kmem_cache_alloc(mnt_cache, GFP_KERNEL);
59 if (mnt) { 59 if (mnt) {
60 memset(mnt, 0, sizeof(struct vfsmount)); 60 memset(mnt, 0, sizeof(struct vfsmount));
61 atomic_set(&mnt->mnt_count,1); 61 atomic_set(&mnt->mnt_count, 1);
62 INIT_LIST_HEAD(&mnt->mnt_hash); 62 INIT_LIST_HEAD(&mnt->mnt_hash);
63 INIT_LIST_HEAD(&mnt->mnt_child); 63 INIT_LIST_HEAD(&mnt->mnt_child);
64 INIT_LIST_HEAD(&mnt->mnt_mounts); 64 INIT_LIST_HEAD(&mnt->mnt_mounts);
65 INIT_LIST_HEAD(&mnt->mnt_list); 65 INIT_LIST_HEAD(&mnt->mnt_list);
66 INIT_LIST_HEAD(&mnt->mnt_expire); 66 INIT_LIST_HEAD(&mnt->mnt_expire);
67 if (name) { 67 if (name) {
68 int size = strlen(name)+1; 68 int size = strlen(name) + 1;
69 char *newname = kmalloc(size, GFP_KERNEL); 69 char *newname = kmalloc(size, GFP_KERNEL);
70 if (newname) { 70 if (newname) {
71 memcpy(newname, name, size); 71 memcpy(newname, name, size);
@@ -88,8 +88,8 @@ void free_vfsmnt(struct vfsmount *mnt)
88 */ 88 */
89struct vfsmount *lookup_mnt(struct vfsmount *mnt, struct dentry *dentry) 89struct vfsmount *lookup_mnt(struct vfsmount *mnt, struct dentry *dentry)
90{ 90{
91 struct list_head * head = mount_hashtable + hash(mnt, dentry); 91 struct list_head *head = mount_hashtable + hash(mnt, dentry);
92 struct list_head * tmp = head; 92 struct list_head *tmp = head;
93 struct vfsmount *p, *found = NULL; 93 struct vfsmount *p, *found = NULL;
94 94
95 spin_lock(&vfsmount_lock); 95 spin_lock(&vfsmount_lock);
@@ -144,7 +144,7 @@ static void attach_mnt(struct vfsmount *mnt, struct nameidata *nd)
144{ 144{
145 mnt->mnt_parent = mntget(nd->mnt); 145 mnt->mnt_parent = mntget(nd->mnt);
146 mnt->mnt_mountpoint = dget(nd->dentry); 146 mnt->mnt_mountpoint = dget(nd->dentry);
147 list_add(&mnt->mnt_hash, mount_hashtable+hash(nd->mnt, nd->dentry)); 147 list_add(&mnt->mnt_hash, mount_hashtable + hash(nd->mnt, nd->dentry));
148 list_add_tail(&mnt->mnt_child, &nd->mnt->mnt_mounts); 148 list_add_tail(&mnt->mnt_child, &nd->mnt->mnt_mounts);
149 nd->dentry->d_mounted++; 149 nd->dentry->d_mounted++;
150} 150}
@@ -165,8 +165,7 @@ static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root)
165 return list_entry(next, struct vfsmount, mnt_child); 165 return list_entry(next, struct vfsmount, mnt_child);
166} 166}
167 167
168static struct vfsmount * 168static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root)
169clone_mnt(struct vfsmount *old, struct dentry *root)
170{ 169{
171 struct super_block *sb = old->mnt_sb; 170 struct super_block *sb = old->mnt_sb;
172 struct vfsmount *mnt = alloc_vfsmnt(old->mnt_devname); 171 struct vfsmount *mnt = alloc_vfsmnt(old->mnt_devname);
@@ -258,7 +257,7 @@ static void *m_next(struct seq_file *m, void *v, loff_t *pos)
258 struct namespace *n = m->private; 257 struct namespace *n = m->private;
259 struct list_head *p = ((struct vfsmount *)v)->mnt_list.next; 258 struct list_head *p = ((struct vfsmount *)v)->mnt_list.next;
260 (*pos)++; 259 (*pos)++;
261 return p==&n->list ? NULL : list_entry(p, struct vfsmount, mnt_list); 260 return p == &n->list ? NULL : list_entry(p, struct vfsmount, mnt_list);
262} 261}
263 262
264static void m_stop(struct seq_file *m, void *v) 263static void m_stop(struct seq_file *m, void *v)
@@ -344,7 +343,8 @@ repeat:
344 next = this_parent->mnt_mounts.next; 343 next = this_parent->mnt_mounts.next;
345resume: 344resume:
346 while (next != &this_parent->mnt_mounts) { 345 while (next != &this_parent->mnt_mounts) {
347 struct vfsmount *p = list_entry(next, struct vfsmount, mnt_child); 346 struct vfsmount *p =
347 list_entry(next, struct vfsmount, mnt_child);
348 348
349 next = next->next; 349 next = next->next;
350 350
@@ -425,7 +425,7 @@ static void umount_tree(struct vfsmount *mnt)
425 425
426static int do_umount(struct vfsmount *mnt, int flags) 426static int do_umount(struct vfsmount *mnt, int flags)
427{ 427{
428 struct super_block * sb = mnt->mnt_sb; 428 struct super_block *sb = mnt->mnt_sb;
429 int retval; 429 int retval;
430 430
431 retval = security_sb_umount(mnt, flags); 431 retval = security_sb_umount(mnt, flags);
@@ -461,7 +461,7 @@ static int do_umount(struct vfsmount *mnt, int flags)
461 */ 461 */
462 462
463 lock_kernel(); 463 lock_kernel();
464 if( (flags&MNT_FORCE) && sb->s_op->umount_begin) 464 if ((flags & MNT_FORCE) && sb->s_op->umount_begin)
465 sb->s_op->umount_begin(sb); 465 sb->s_op->umount_begin(sb);
466 unlock_kernel(); 466 unlock_kernel();
467 467
@@ -543,12 +543,11 @@ out:
543#ifdef __ARCH_WANT_SYS_OLDUMOUNT 543#ifdef __ARCH_WANT_SYS_OLDUMOUNT
544 544
545/* 545/*
546 * The 2.0 compatible umount. No flags. 546 * The 2.0 compatible umount. No flags.
547 */ 547 */
548
549asmlinkage long sys_oldumount(char __user * name) 548asmlinkage long sys_oldumount(char __user * name)
550{ 549{
551 return sys_umount(name,0); 550 return sys_umount(name, 0);
552} 551}
553 552
554#endif 553#endif
@@ -571,8 +570,7 @@ static int mount_is_safe(struct nameidata *nd)
571#endif 570#endif
572} 571}
573 572
574static int 573static int lives_below_in_same_fs(struct dentry *d, struct dentry *dentry)
575lives_below_in_same_fs(struct dentry *d, struct dentry *dentry)
576{ 574{
577 while (1) { 575 while (1) {
578 if (d == dentry) 576 if (d == dentry)
@@ -616,7 +614,7 @@ static struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry)
616 } 614 }
617 } 615 }
618 return res; 616 return res;
619 Enomem: 617Enomem:
620 if (res) { 618 if (res) {
621 spin_lock(&vfsmount_lock); 619 spin_lock(&vfsmount_lock);
622 umount_tree(res); 620 umount_tree(res);
@@ -718,12 +716,11 @@ out:
718 * If you've mounted a non-root directory somewhere and want to do remount 716 * If you've mounted a non-root directory somewhere and want to do remount
719 * on it - tough luck. 717 * on it - tough luck.
720 */ 718 */
721
722static int do_remount(struct nameidata *nd, int flags, int mnt_flags, 719static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
723 void *data) 720 void *data)
724{ 721{
725 int err; 722 int err;
726 struct super_block * sb = nd->mnt->mnt_sb; 723 struct super_block *sb = nd->mnt->mnt_sb;
727 724
728 if (!capable(CAP_SYS_ADMIN)) 725 if (!capable(CAP_SYS_ADMIN))
729 return -EPERM; 726 return -EPERM;
@@ -737,7 +734,7 @@ static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
737 down_write(&sb->s_umount); 734 down_write(&sb->s_umount);
738 err = do_remount_sb(sb, flags, data, 0); 735 err = do_remount_sb(sb, flags, data, 0);
739 if (!err) 736 if (!err)
740 nd->mnt->mnt_flags=mnt_flags; 737 nd->mnt->mnt_flags = mnt_flags;
741 up_write(&sb->s_umount); 738 up_write(&sb->s_umount);
742 if (!err) 739 if (!err)
743 security_sb_post_remount(nd->mnt, flags, data); 740 security_sb_post_remount(nd->mnt, flags, data);
@@ -758,7 +755,7 @@ static int do_move_mount(struct nameidata *nd, char *old_name)
758 return err; 755 return err;
759 756
760 down_write(&current->namespace->sem); 757 down_write(&current->namespace->sem);
761 while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry)) 758 while (d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
762 ; 759 ;
763 err = -EINVAL; 760 err = -EINVAL;
764 if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt)) 761 if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt))
@@ -785,7 +782,7 @@ static int do_move_mount(struct nameidata *nd, char *old_name)
785 goto out2; 782 goto out2;
786 783
787 err = -ELOOP; 784 err = -ELOOP;
788 for (p = nd->mnt; p->mnt_parent!=p; p = p->mnt_parent) 785 for (p = nd->mnt; p->mnt_parent != p; p = p->mnt_parent)
789 if (p == old_nd.mnt) 786 if (p == old_nd.mnt)
790 goto out2; 787 goto out2;
791 err = 0; 788 err = 0;
@@ -843,7 +840,7 @@ int do_add_mount(struct vfsmount *newmnt, struct nameidata *nd,
843 840
844 down_write(&current->namespace->sem); 841 down_write(&current->namespace->sem);
845 /* Something was mounted here while we slept */ 842 /* Something was mounted here while we slept */
846 while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry)) 843 while (d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
847 ; 844 ;
848 err = -EINVAL; 845 err = -EINVAL;
849 if (!check_mnt(nd->mnt)) 846 if (!check_mnt(nd->mnt))
@@ -986,8 +983,8 @@ EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);
986 * Note that this function differs from copy_from_user() in that it will oops 983 * Note that this function differs from copy_from_user() in that it will oops
987 * on bad values of `to', rather than returning a short copy. 984 * on bad values of `to', rather than returning a short copy.
988 */ 985 */
989static long 986static long exact_copy_from_user(void *to, const void __user * from,
990exact_copy_from_user(void *to, const void __user *from, unsigned long n) 987 unsigned long n)
991{ 988{
992 char *t = to; 989 char *t = to;
993 const char __user *f = from; 990 const char __user *f = from;
@@ -1008,12 +1005,12 @@ exact_copy_from_user(void *to, const void __user *from, unsigned long n)
1008 return n; 1005 return n;
1009} 1006}
1010 1007
1011int copy_mount_options(const void __user *data, unsigned long *where) 1008int copy_mount_options(const void __user * data, unsigned long *where)
1012{ 1009{
1013 int i; 1010 int i;
1014 unsigned long page; 1011 unsigned long page;
1015 unsigned long size; 1012 unsigned long size;
1016 1013
1017 *where = 0; 1014 *where = 0;
1018 if (!data) 1015 if (!data)
1019 return 0; 1016 return 0;
@@ -1032,7 +1029,7 @@ int copy_mount_options(const void __user *data, unsigned long *where)
1032 1029
1033 i = size - exact_copy_from_user((void *)page, data, size); 1030 i = size - exact_copy_from_user((void *)page, data, size);
1034 if (!i) { 1031 if (!i) {
1035 free_page(page); 1032 free_page(page);
1036 return -EFAULT; 1033 return -EFAULT;
1037 } 1034 }
1038 if (i != PAGE_SIZE) 1035 if (i != PAGE_SIZE)
@@ -1055,7 +1052,7 @@ int copy_mount_options(const void __user *data, unsigned long *where)
1055 * Therefore, if this magic number is present, it carries no information 1052 * Therefore, if this magic number is present, it carries no information
1056 * and must be discarded. 1053 * and must be discarded.
1057 */ 1054 */
1058long do_mount(char * dev_name, char * dir_name, char *type_page, 1055long do_mount(char *dev_name, char *dir_name, char *type_page,
1059 unsigned long flags, void *data_page) 1056 unsigned long flags, void *data_page)
1060{ 1057{
1061 struct nameidata nd; 1058 struct nameidata nd;
@@ -1083,7 +1080,7 @@ long do_mount(char * dev_name, char * dir_name, char *type_page,
1083 mnt_flags |= MNT_NODEV; 1080 mnt_flags |= MNT_NODEV;
1084 if (flags & MS_NOEXEC) 1081 if (flags & MS_NOEXEC)
1085 mnt_flags |= MNT_NOEXEC; 1082 mnt_flags |= MNT_NOEXEC;
1086 flags &= ~(MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_ACTIVE); 1083 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE);
1087 1084
1088 /* ... and get the mountpoint */ 1085 /* ... and get the mountpoint */
1089 retval = path_lookup(dir_name, LOOKUP_FOLLOW, &nd); 1086 retval = path_lookup(dir_name, LOOKUP_FOLLOW, &nd);
@@ -1207,7 +1204,7 @@ asmlinkage long sys_mount(char __user * dev_name, char __user * dir_name,
1207 unsigned long dev_page; 1204 unsigned long dev_page;
1208 char *dir_page; 1205 char *dir_page;
1209 1206
1210 retval = copy_mount_options (type, &type_page); 1207 retval = copy_mount_options(type, &type_page);
1211 if (retval < 0) 1208 if (retval < 0)
1212 return retval; 1209 return retval;
1213 1210
@@ -1216,17 +1213,17 @@ asmlinkage long sys_mount(char __user * dev_name, char __user * dir_name,
1216 if (IS_ERR(dir_page)) 1213 if (IS_ERR(dir_page))
1217 goto out1; 1214 goto out1;
1218 1215
1219 retval = copy_mount_options (dev_name, &dev_page); 1216 retval = copy_mount_options(dev_name, &dev_page);
1220 if (retval < 0) 1217 if (retval < 0)
1221 goto out2; 1218 goto out2;
1222 1219
1223 retval = copy_mount_options (data, &data_page); 1220 retval = copy_mount_options(data, &data_page);
1224 if (retval < 0) 1221 if (retval < 0)
1225 goto out3; 1222 goto out3;
1226 1223
1227 lock_kernel(); 1224 lock_kernel();
1228 retval = do_mount((char*)dev_page, dir_page, (char*)type_page, 1225 retval = do_mount((char *)dev_page, dir_page, (char *)type_page,
1229 flags, (void*)data_page); 1226 flags, (void *)data_page);
1230 unlock_kernel(); 1227 unlock_kernel();
1231 free_page(data_page); 1228 free_page(data_page);
1232 1229
@@ -1295,9 +1292,11 @@ static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd)
1295 if (fs) { 1292 if (fs) {
1296 atomic_inc(&fs->count); 1293 atomic_inc(&fs->count);
1297 task_unlock(p); 1294 task_unlock(p);
1298 if (fs->root==old_nd->dentry&&fs->rootmnt==old_nd->mnt) 1295 if (fs->root == old_nd->dentry
1296 && fs->rootmnt == old_nd->mnt)
1299 set_fs_root(fs, new_nd->mnt, new_nd->dentry); 1297 set_fs_root(fs, new_nd->mnt, new_nd->dentry);
1300 if (fs->pwd==old_nd->dentry&&fs->pwdmnt==old_nd->mnt) 1298 if (fs->pwd == old_nd->dentry
1299 && fs->pwdmnt == old_nd->mnt)
1301 set_fs_pwd(fs, new_nd->mnt, new_nd->dentry); 1300 set_fs_pwd(fs, new_nd->mnt, new_nd->dentry);
1302 put_fs_struct(fs); 1301 put_fs_struct(fs);
1303 } else 1302 } else
@@ -1327,8 +1326,8 @@ static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd)
1327 * though, so you may need to say mount --bind /nfs/my_root /nfs/my_root 1326 * though, so you may need to say mount --bind /nfs/my_root /nfs/my_root
1328 * first. 1327 * first.
1329 */ 1328 */
1330 1329asmlinkage long sys_pivot_root(const char __user * new_root,
1331asmlinkage long sys_pivot_root(const char __user *new_root, const char __user *put_old) 1330 const char __user * put_old)
1332{ 1331{
1333 struct vfsmount *tmp; 1332 struct vfsmount *tmp;
1334 struct nameidata new_nd, old_nd, parent_nd, root_parent, user_nd; 1333 struct nameidata new_nd, old_nd, parent_nd, root_parent, user_nd;
@@ -1339,14 +1338,15 @@ asmlinkage long sys_pivot_root(const char __user *new_root, const char __user *p
1339 1338
1340 lock_kernel(); 1339 lock_kernel();
1341 1340
1342 error = __user_walk(new_root, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &new_nd); 1341 error = __user_walk(new_root, LOOKUP_FOLLOW | LOOKUP_DIRECTORY,
1342 &new_nd);
1343 if (error) 1343 if (error)
1344 goto out0; 1344 goto out0;
1345 error = -EINVAL; 1345 error = -EINVAL;
1346 if (!check_mnt(new_nd.mnt)) 1346 if (!check_mnt(new_nd.mnt))
1347 goto out1; 1347 goto out1;
1348 1348
1349 error = __user_walk(put_old, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &old_nd); 1349 error = __user_walk(put_old, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &old_nd);
1350 if (error) 1350 if (error)
1351 goto out1; 1351 goto out1;
1352 1352
@@ -1464,10 +1464,9 @@ void __init mnt_init(unsigned long mempages)
1464 int i; 1464 int i;
1465 1465
1466 mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct vfsmount), 1466 mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct vfsmount),
1467 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL); 1467 0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL, NULL);
1468 1468
1469 mount_hashtable = (struct list_head *) 1469 mount_hashtable = (struct list_head *)__get_free_page(GFP_ATOMIC);
1470 __get_free_page(GFP_ATOMIC);
1471 1470
1472 if (!mount_hashtable) 1471 if (!mount_hashtable)
1473 panic("Failed to allocate mount hash table\n"); 1472 panic("Failed to allocate mount hash table\n");
@@ -1489,7 +1488,7 @@ void __init mnt_init(unsigned long mempages)
1489 * from the number of bits we can fit. 1488 * from the number of bits we can fit.
1490 */ 1489 */
1491 nr_hash = 1UL << hash_bits; 1490 nr_hash = 1UL << hash_bits;
1492 hash_mask = nr_hash-1; 1491 hash_mask = nr_hash - 1;
1493 1492
1494 printk("Mount-cache hash table entries: %d\n", nr_hash); 1493 printk("Mount-cache hash table entries: %d\n", nr_hash);
1495 1494