linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / fs / super.c
index 47d461a..c0993b9 100644 (file)
 #include <linux/vfs.h>
 #include <linux/writeback.h>           /* for the emergency remount stuff */
 #include <linux/idr.h>
+#include <linux/kobject.h>
 #include <linux/devpts_fs.h>
 #include <linux/proc_fs.h>
-#include <linux/kobject.h>
 #include <asm/uaccess.h>
+#include <linux/vs_base.h>
 
 
 void get_filesystem(struct file_system_type *fs);
@@ -47,7 +48,7 @@ void put_filesystem(struct file_system_type *fs);
 struct file_system_type *get_fs_type(const char *name);
 
 LIST_HEAD(super_blocks);
-spinlock_t sb_lock = SPIN_LOCK_UNLOCKED;
+DEFINE_SPINLOCK(sb_lock);
 
 /**
  *     alloc_super     -       create new superblock
@@ -72,8 +73,9 @@ static struct super_block *alloc_super(void)
                INIT_LIST_HEAD(&s->s_files);
                INIT_LIST_HEAD(&s->s_instances);
                INIT_HLIST_HEAD(&s->s_anon);
+               INIT_LIST_HEAD(&s->s_inodes);
                init_rwsem(&s->s_umount);
-               sema_init(&s->s_lock, 1);
+               mutex_init(&s->s_lock);
                down_write(&s->s_umount);
                s->s_count = S_BIAS;
                atomic_set(&s->s_active, 1);
@@ -86,6 +88,7 @@ static struct super_block *alloc_super(void)
                s->dq_op = sb_dquot_ops;
                s->s_qcop = sb_quotactl_ops;
                s->s_op = &default_op;
+               s->s_time_gran = 1000000000;
        }
 out:
        return s;
@@ -143,7 +146,7 @@ int __put_super_and_need_restart(struct super_block *sb)
 
 /**
  *     put_super       -       drop a temporary reference to superblock
- *     @s: superblock in question
+ *     @sb: superblock in question
  *
  *     Drops a temporary reference, frees superblock if there's no
  *     references left.
@@ -171,6 +174,7 @@ void deactivate_super(struct super_block *s)
        if (atomic_dec_and_lock(&s->s_active, &sb_lock)) {
                s->s_count -= S_BIAS-1;
                spin_unlock(&sb_lock);
+               DQUOT_OFF(s);
                down_write(&s->s_umount);
                fs->kill_sb(s);
                put_filesystem(fs);
@@ -234,10 +238,10 @@ void generic_shutdown_super(struct super_block *sb)
                dput(root);
                fsync_super(sb);
                lock_super(sb);
-               lock_kernel();
                sb->s_flags &= ~MS_ACTIVE;
                /* bad name - it should be evict_inodes() */
                invalidate_inodes(sb);
+               lock_kernel();
 
                if (sop->write_super && sb->s_dirt)
                        sop->write_super(sb);
@@ -246,8 +250,9 @@ void generic_shutdown_super(struct super_block *sb)
 
                /* Forget any remaining inodes */
                if (invalidate_inodes(sb)) {
-                       printk("VFS: Busy inodes after unmount. "
-                          "Self-destruct in 5 seconds.  Have a nice day...\n");
+                       printk("VFS: Busy inodes after unmount of %s. "
+                          "Self-destruct in 5 seconds.  Have a nice day...\n",
+                          sb->s_id);
                }
 
                unlock_kernel();
@@ -341,20 +346,22 @@ static inline void write_super(struct super_block *sb)
  */
 void sync_supers(void)
 {
-       struct super_block * sb;
-restart:
+       struct super_block *sb;
+
        spin_lock(&sb_lock);
-       sb = sb_entry(super_blocks.next);
-       while (sb != sb_entry(&super_blocks))
+restart:
+       list_for_each_entry(sb, &super_blocks, s_list) {
                if (sb->s_dirt) {
                        sb->s_count++;
                        spin_unlock(&sb_lock);
                        down_read(&sb->s_umount);
                        write_super(sb);
-                       drop_super(sb);
-                       goto restart;
-               } else
-                       sb = sb_entry(sb->s_list.next);
+                       up_read(&sb->s_umount);
+                       spin_lock(&sb_lock);
+                       if (__put_super_and_need_restart(sb))
+                               goto restart;
+               }
+       }
        spin_unlock(&sb_lock);
 }
 
@@ -381,20 +388,16 @@ void sync_filesystems(int wait)
 
        down(&mutex);           /* Could be down_interruptible */
        spin_lock(&sb_lock);
-       for (sb = sb_entry(super_blocks.next); sb != sb_entry(&super_blocks);
-                       sb = sb_entry(sb->s_list.next)) {
+       list_for_each_entry(sb, &super_blocks, s_list) {
                if (!sb->s_op->sync_fs)
                        continue;
                if (sb->s_flags & MS_RDONLY)
                        continue;
                sb->s_need_sync_fs = 1;
        }
-       spin_unlock(&sb_lock);
 
 restart:
-       spin_lock(&sb_lock);
-       for (sb = sb_entry(super_blocks.next); sb != sb_entry(&super_blocks);
-                       sb = sb_entry(sb->s_list.next)) {
+       list_for_each_entry(sb, &super_blocks, s_list) {
                if (!sb->s_need_sync_fs)
                        continue;
                sb->s_need_sync_fs = 0;
@@ -405,8 +408,11 @@ restart:
                down_read(&sb->s_umount);
                if (sb->s_root && (wait || sb->s_dirt))
                        sb->s_op->sync_fs(sb, wait);
-               drop_super(sb);
-               goto restart;
+               up_read(&sb->s_umount);
+               /* restart only when sb is no longer on the list */
+               spin_lock(&sb_lock);
+               if (__put_super_and_need_restart(sb))
+                       goto restart;
        }
        spin_unlock(&sb_lock);
        up(&mutex);
@@ -422,21 +428,25 @@ restart:
 
 struct super_block * get_super(struct block_device *bdev)
 {
-       struct list_head *p;
+       struct super_block *sb;
+
        if (!bdev)
                return NULL;
-rescan:
+
        spin_lock(&sb_lock);
-       list_for_each(p, &super_blocks) {
-               struct super_block *s = sb_entry(p);
-               if (s->s_bdev == bdev) {
-                       s->s_count++;
+rescan:
+       list_for_each_entry(sb, &super_blocks, s_list) {
+               if (sb->s_bdev == bdev) {
+                       sb->s_count++;
                        spin_unlock(&sb_lock);
-                       down_read(&s->s_umount);
-                       if (s->s_root)
-                               return s;
-                       drop_super(s);
-                       goto rescan;
+                       down_read(&sb->s_umount);
+                       if (sb->s_root)
+                               return sb;
+                       up_read(&sb->s_umount);
+                       /* restart only when sb is no longer on the list */
+                       spin_lock(&sb_lock);
+                       if (__put_super_and_need_restart(sb))
+                               goto rescan;
                }
        }
        spin_unlock(&sb_lock);
@@ -447,28 +457,28 @@ EXPORT_SYMBOL(get_super);
  
 struct super_block * user_get_super(dev_t dev)
 {
-       struct list_head *p;
+       struct super_block *sb;
 
-rescan:
        spin_lock(&sb_lock);
-       list_for_each(p, &super_blocks) {
-               struct super_block *s = sb_entry(p);
-               if (s->s_dev ==  dev) {
-                       s->s_count++;
+rescan:
+       list_for_each_entry(sb, &super_blocks, s_list) {
+               if (sb->s_dev ==  dev) {
+                       sb->s_count++;
                        spin_unlock(&sb_lock);
-                       down_read(&s->s_umount);
-                       if (s->s_root)
-                               return s;
-                       drop_super(s);
-                       goto rescan;
+                       down_read(&sb->s_umount);
+                       if (sb->s_root)
+                               return sb;
+                       up_read(&sb->s_umount);
+                       /* restart only when sb is no longer on the list */
+                       spin_lock(&sb_lock);
+                       if (__put_super_and_need_restart(sb))
+                               goto rescan;
                }
        }
        spin_unlock(&sb_lock);
        return NULL;
 }
 
-EXPORT_SYMBOL(user_get_super);
-
 asmlinkage long sys_ustat(unsigned dev, struct ustat __user * ubuf)
 {
         struct super_block *s;
@@ -506,7 +516,7 @@ static void mark_files_ro(struct super_block *sb)
        struct file *f;
 
        file_list_lock();
-       list_for_each_entry(f, &sb->s_files, f_list) {
+       list_for_each_entry(f, &sb->s_files, f_u.fu_list) {
                if (S_ISREG(f->f_dentry->d_inode->i_mode) && file_count(f))
                        f->f_mode &= ~FMODE_WRITE;
        }
@@ -590,7 +600,7 @@ void emergency_remount(void)
  */
 
 static struct idr unnamed_dev_idr;
-static spinlock_t unnamed_dev_lock = SPIN_LOCK_UNLOCKED;/* protects the above */
+static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */
 
 int set_anon_super(struct super_block *s, void *data)
 {
@@ -663,9 +673,9 @@ static void bdev_uevent(struct block_device *bdev, enum kobject_action action)
 {
        if (bdev->bd_disk) {
                if (bdev->bd_part)
-                       kobject_uevent(&bdev->bd_part->kobj, action, NULL);
+                       kobject_uevent(&bdev->bd_part->kobj, action);
                else
-                       kobject_uevent(&bdev->bd_disk->kobj, action, NULL);
+                       kobject_uevent(&bdev->bd_disk->kobj, action);
        }
 }
 
@@ -704,8 +714,7 @@ struct super_block *get_sb_bdev(struct file_system_type *fs_type,
 
                s->s_flags = flags;
                strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
-               s->s_old_blocksize = block_size(bdev);
-               sb_set_blocksize(s, s->s_old_blocksize);
+               sb_set_blocksize(s, block_size(bdev));
                error = fill_super(s, data, flags & MS_VERBOSE ? 1 : 0);
                if (error) {
                        up_write(&s->s_umount);
@@ -732,7 +741,7 @@ void kill_block_super(struct super_block *sb)
 
        bdev_uevent(bdev, KOBJ_UMOUNT);
        generic_shutdown_super(sb);
-       set_blocksize(bdev, sb->s_old_blocksize);
+       sync_blockdev(bdev);
        close_bdev_excl(bdev);
 }
 
@@ -797,7 +806,7 @@ struct vfsmount *
 do_kern_mount(const char *fstype, int flags, const char *name, void *data)
 {
        struct file_system_type *type = get_fs_type(fstype);
-       struct super_block *sb = ERR_PTR(-ENOMEM);
+       struct super_block *sb;
        struct vfsmount *mnt;
        int error;
        char *secdata = NULL;
@@ -805,6 +814,12 @@ do_kern_mount(const char *fstype, int flags, const char *name, void *data)
        if (!type)
                return ERR_PTR(-ENODEV);
 
+       sb = ERR_PTR(-EPERM);
+       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
+               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
+               goto out;
+
+       sb = ERR_PTR(-ENOMEM);
        mnt = alloc_vfsmnt(name);
        if (!mnt)
                goto out;
@@ -840,8 +855,8 @@ do_kern_mount(const char *fstype, int flags, const char *name, void *data)
        mnt->mnt_root = dget(sb->s_root);
        mnt->mnt_mountpoint = sb->s_root;
        mnt->mnt_parent = mnt;
-       mnt->mnt_namespace = current->namespace;
        up_write(&sb->s_umount);
+       free_secdata(secdata);
        put_filesystem(type);
        return mnt;
 out_sb: