]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - fs/super.c
convert get_sb_single() users
[net-next-2.6.git] / fs / super.c
index 938119ab8dcbc28f3f9853bc0808d6d70cd51d55..6f021a171ac61a0577525093ee9f78953f0cf29c 100644 (file)
@@ -54,7 +54,22 @@ static struct super_block *alloc_super(struct file_system_type *type)
                        s = NULL;
                        goto out;
                }
+#ifdef CONFIG_SMP
+               s->s_files = alloc_percpu(struct list_head);
+               if (!s->s_files) {
+                       security_sb_free(s);
+                       kfree(s);
+                       s = NULL;
+                       goto out;
+               } else {
+                       int i;
+
+                       for_each_possible_cpu(i)
+                               INIT_LIST_HEAD(per_cpu_ptr(s->s_files, i));
+               }
+#else
                INIT_LIST_HEAD(&s->s_files);
+#endif
                INIT_LIST_HEAD(&s->s_instances);
                INIT_HLIST_HEAD(&s->s_anon);
                INIT_LIST_HEAD(&s->s_inodes);
@@ -108,6 +123,9 @@ out:
  */
 static inline void destroy_super(struct super_block *s)
 {
+#ifdef CONFIG_SMP
+       free_percpu(s->s_files);
+#endif
        security_sb_free(s);
        kfree(s->s_subtype);
        kfree(s->s_options);
@@ -255,14 +273,14 @@ void generic_shutdown_super(struct super_block *sb)
                get_fs_excl();
                sb->s_flags &= ~MS_ACTIVE;
 
-               /* bad name - it should be evict_inodes() */
-               invalidate_inodes(sb);
+               fsnotify_unmount_inodes(&sb->s_inodes);
+
+               evict_inodes(sb);
 
                if (sop->put_super)
                        sop->put_super(sb);
 
-               /* Forget any remaining inodes */
-               if (invalidate_inodes(sb)) {
+               if (!list_empty(&sb->s_inodes)) {
                        printk("VFS: Busy inodes after unmount of %s. "
                           "Self-destruct in 5 seconds.  Have a nice day...\n",
                           sb->s_id);
@@ -305,8 +323,13 @@ retry:
                        if (s) {
                                up_write(&s->s_umount);
                                destroy_super(s);
+                               s = NULL;
                        }
                        down_write(&old->s_umount);
+                       if (unlikely(!(old->s_flags & MS_BORN))) {
+                               deactivate_locked_super(old);
+                               goto retry;
+                       }
                        return old;
                }
        }
@@ -358,10 +381,10 @@ EXPORT_SYMBOL(drop_super);
  */
 void sync_supers(void)
 {
-       struct super_block *sb, *n;
+       struct super_block *sb, *p = NULL;
 
        spin_lock(&sb_lock);
-       list_for_each_entry_safe(sb, n, &super_blocks, s_list) {
+       list_for_each_entry(sb, &super_blocks, s_list) {
                if (list_empty(&sb->s_instances))
                        continue;
                if (sb->s_op->write_super && sb->s_dirt) {
@@ -374,11 +397,13 @@ void sync_supers(void)
                        up_read(&sb->s_umount);
 
                        spin_lock(&sb_lock);
-                       /* lock was dropped, must reset next */
-                       list_safe_reset_next(sb, n, s_list);
-                       __put_super(sb);
+                       if (p)
+                               __put_super(p);
+                       p = sb;
                }
        }
+       if (p)
+               __put_super(p);
        spin_unlock(&sb_lock);
 }
 
@@ -392,10 +417,10 @@ void sync_supers(void)
  */
 void iterate_supers(void (*f)(struct super_block *, void *), void *arg)
 {
-       struct super_block *sb, *n;
+       struct super_block *sb, *p = NULL;
 
        spin_lock(&sb_lock);
-       list_for_each_entry_safe(sb, n, &super_blocks, s_list) {
+       list_for_each_entry(sb, &super_blocks, s_list) {
                if (list_empty(&sb->s_instances))
                        continue;
                sb->s_count++;
@@ -407,10 +432,12 @@ void iterate_supers(void (*f)(struct super_block *, void *), void *arg)
                up_read(&sb->s_umount);
 
                spin_lock(&sb_lock);
-               /* lock was dropped, must reset next */
-               list_safe_reset_next(sb, n, s_list);
-               __put_super(sb);
+               if (p)
+                       __put_super(p);
+               p = sb;
        }
+       if (p)
+               __put_super(p);
        spin_unlock(&sb_lock);
 }
 
@@ -572,10 +599,10 @@ int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
 
 static void do_emergency_remount(struct work_struct *work)
 {
-       struct super_block *sb, *n;
+       struct super_block *sb, *p = NULL;
 
        spin_lock(&sb_lock);
-       list_for_each_entry_safe(sb, n, &super_blocks, s_list) {
+       list_for_each_entry(sb, &super_blocks, s_list) {
                if (list_empty(&sb->s_instances))
                        continue;
                sb->s_count++;
@@ -589,10 +616,12 @@ static void do_emergency_remount(struct work_struct *work)
                }
                up_write(&sb->s_umount);
                spin_lock(&sb_lock);
-               /* lock was dropped, must reset next */
-               list_safe_reset_next(sb, n, s_list);
-               __put_super(sb);
+               if (p)
+                       __put_super(p);
+               p = sb;
        }
+       if (p)
+               __put_super(p);
        spin_unlock(&sb_lock);
        kfree(work);
        printk("Emergency Remount complete\n");
@@ -733,10 +762,9 @@ static int test_bdev_super(struct super_block *s, void *data)
        return (void *)s->s_bdev == data;
 }
 
-int get_sb_bdev(struct file_system_type *fs_type,
+struct dentry *mount_bdev(struct file_system_type *fs_type,
        int flags, const char *dev_name, void *data,
-       int (*fill_super)(struct super_block *, void *, int),
-       struct vfsmount *mnt)
+       int (*fill_super)(struct super_block *, void *, int))
 {
        struct block_device *bdev;
        struct super_block *s;
@@ -748,7 +776,7 @@ int get_sb_bdev(struct file_system_type *fs_type,
 
        bdev = open_bdev_exclusive(dev_name, mode, fs_type);
        if (IS_ERR(bdev))
-               return PTR_ERR(bdev);
+               return ERR_CAST(bdev);
 
        /*
         * once the super is inserted into the list by sget, s_umount
@@ -773,7 +801,16 @@ int get_sb_bdev(struct file_system_type *fs_type,
                        goto error_bdev;
                }
 
+               /*
+                * s_umount nests inside bd_mutex during
+                * __invalidate_device().  close_bdev_exclusive()
+                * acquires bd_mutex and can't be called under
+                * s_umount.  Drop s_umount temporarily.  This is safe
+                * as we're holding an active reference.
+                */
+               up_write(&s->s_umount);
                close_bdev_exclusive(bdev, mode);
+               down_write(&s->s_umount);
        } else {
                char b[BDEVNAME_SIZE];
 
@@ -791,15 +828,30 @@ int get_sb_bdev(struct file_system_type *fs_type,
                bdev->bd_super = s;
        }
 
-       simple_set_mnt(mnt, s);
-       return 0;
+       return dget(s->s_root);
 
 error_s:
        error = PTR_ERR(s);
 error_bdev:
        close_bdev_exclusive(bdev, mode);
 error:
-       return error;
+       return ERR_PTR(error);
+}
+EXPORT_SYMBOL(mount_bdev);
+
+int get_sb_bdev(struct file_system_type *fs_type,
+       int flags, const char *dev_name, void *data,
+       int (*fill_super)(struct super_block *, void *, int),
+       struct vfsmount *mnt)
+{
+       struct dentry *root;
+
+       root = mount_bdev(fs_type, flags, dev_name, data, fill_super);
+       if (IS_ERR(root))
+               return PTR_ERR(root);
+       mnt->mnt_root = root;
+       mnt->mnt_sb = root->d_sb;
+       return 0;
 }
 
 EXPORT_SYMBOL(get_sb_bdev);
@@ -848,29 +900,42 @@ static int compare_single(struct super_block *s, void *p)
        return 1;
 }
 
-int get_sb_single(struct file_system_type *fs_type,
+struct dentry *mount_single(struct file_system_type *fs_type,
        int flags, void *data,
-       int (*fill_super)(struct super_block *, void *, int),
-       struct vfsmount *mnt)
+       int (*fill_super)(struct super_block *, void *, int))
 {
        struct super_block *s;
        int error;
 
        s = sget(fs_type, compare_single, set_anon_super, NULL);
        if (IS_ERR(s))
-               return PTR_ERR(s);
+               return ERR_CAST(s);
        if (!s->s_root) {
                s->s_flags = flags;
                error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
                if (error) {
                        deactivate_locked_super(s);
-                       return error;
+                       return ERR_PTR(error);
                }
                s->s_flags |= MS_ACTIVE;
        } else {
                do_remount_sb(s, flags, data, 0);
        }
-       simple_set_mnt(mnt, s);
+       return dget(s->s_root);
+}
+EXPORT_SYMBOL(mount_single);
+
+int get_sb_single(struct file_system_type *fs_type,
+       int flags, void *data,
+       int (*fill_super)(struct super_block *, void *, int),
+       struct vfsmount *mnt)
+{
+       struct dentry *root;
+       root = mount_single(fs_type, flags, data, fill_super);
+       if (IS_ERR(root))
+               return PTR_ERR(root);
+       mnt->mnt_root = root;
+       mnt->mnt_sb = root->d_sb;
        return 0;
 }
 
@@ -880,6 +945,7 @@ struct vfsmount *
 vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
 {
        struct vfsmount *mnt;
+       struct dentry *root;
        char *secdata = NULL;
        int error;
 
@@ -904,11 +970,22 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void
                        goto out_free_secdata;
        }
 
-       error = type->get_sb(type, flags, name, data, mnt);
-       if (error < 0)
-               goto out_free_secdata;
+       if (type->mount) {
+               root = type->mount(type, flags, name, data);
+               if (IS_ERR(root)) {
+                       error = PTR_ERR(root);
+                       goto out_free_secdata;
+               }
+               mnt->mnt_root = root;
+               mnt->mnt_sb = root->d_sb;
+       } else {
+               error = type->get_sb(type, flags, name, data, mnt);
+               if (error < 0)
+                       goto out_free_secdata;
+       }
        BUG_ON(!mnt->mnt_sb);
        WARN_ON(!mnt->mnt_sb->s_bdi);
+       mnt->mnt_sb->s_flags |= MS_BORN;
 
        error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
        if (error)