btrfs delete ordered inode handling fix
[deliverable/linux.git] / fs / btrfs / super.c
index 67ed216df4755c750c3d27f4fe4259710f80ea67..05029656e42e9c871238175ea692ade0cc031b66 100644 (file)
@@ -44,6 +44,7 @@
 #include "ioctl.h"
 #include "print-tree.h"
 #include "xattr.h"
+#include "volumes.h"
 
 #define BTRFS_SUPER_MAGIC 0x9123683E
 
@@ -64,11 +65,13 @@ static void btrfs_put_super (struct super_block * sb)
 }
 
 enum {
-       Opt_subvol, Opt_nodatasum, Opt_nodatacow, Opt_max_extent,
-       Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd, Opt_err,
+       Opt_degraded, Opt_subvol, Opt_nodatasum, Opt_nodatacow,
+       Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier,
+       Opt_ssd, Opt_err,
 };
 
 static match_table_t tokens = {
+       {Opt_degraded, "degraded"},
        {Opt_subvol, "subvol=%s"},
        {Opt_nodatasum, "nodatasum"},
        {Opt_nodatacow, "nodatacow"},
@@ -105,9 +108,8 @@ u64 btrfs_parse_size(char *str)
        return res;
 }
 
-static int parse_options (char * options,
-                         struct btrfs_root *root,
-                         char **subvol_name)
+int btrfs_parse_options(char *options, struct btrfs_root *root,
+                       char **subvol_name)
 {
        char * p;
        struct btrfs_fs_info *info = NULL;
@@ -134,6 +136,12 @@ static int parse_options (char * options,
 
                token = match_token(p, tokens, args);
                switch (token) {
+               case Opt_degraded:
+                       if (info) {
+                               printk("btrfs: allowing degraded mounts\n");
+                               btrfs_set_opt(info->mount_opt, DEGRADED);
+                       }
+                       break;
                case Opt_subvol:
                        if (subvol_name) {
                                *subvol_name = match_strdup(&args[0]);
@@ -216,7 +224,9 @@ static int parse_options (char * options,
        return 1;
 }
 
-static int btrfs_fill_super(struct super_block * sb, void * data, int silent)
+static int btrfs_fill_super(struct super_block * sb,
+                           struct btrfs_fs_devices *fs_devices,
+                           void * data, int silent)
 {
        struct inode * inode;
        struct dentry * root_dentry;
@@ -231,11 +241,11 @@ static int btrfs_fill_super(struct super_block * sb, void * data, int silent)
        sb->s_xattr = btrfs_xattr_handlers;
        sb->s_time_gran = 1;
 
-       tree_root = open_ctree(sb);
+       tree_root = open_ctree(sb, fs_devices, (char *)data);
 
-       if (!tree_root || IS_ERR(tree_root)) {
+       if (IS_ERR(tree_root)) {
                printk("btrfs: open_ctree failed\n");
-               return -EIO;
+               return PTR_ERR(tree_root);
        }
        sb->s_fs_info = tree_root;
        disk_super = &tree_root->fs_info->super_copy;
@@ -264,8 +274,6 @@ static int btrfs_fill_super(struct super_block * sb, void * data, int silent)
                goto fail_close;
        }
 
-       parse_options((char *)data, tree_root, NULL);
-
        /* this does the super kobj at the same time */
        err = btrfs_sysfs_add_super(tree_root->fs_info);
        if (err)
@@ -312,48 +320,36 @@ static void btrfs_write_super(struct super_block *sb)
        sb->s_dirt = 0;
 }
 
-/*
- * This is almost a copy of get_sb_bdev in fs/super.c.
- * We need the local copy to allow direct mounting of
- * subvolumes, but this could be easily integrated back
- * into the generic version.  --hch
- */
-
-/* start copy & paste */
-static int set_bdev_super(struct super_block *s, void *data)
+static int btrfs_test_super(struct super_block *s, void *data)
 {
-       s->s_bdev = data;
-       s->s_dev = s->s_bdev->bd_dev;
-       return 0;
-}
+       struct btrfs_fs_devices *test_fs_devices = data;
+       struct btrfs_root *root = btrfs_sb(s);
 
-static int test_bdev_super(struct super_block *s, void *data)
-{
-       return (void *)s->s_bdev == data;
+       return root->fs_info->fs_devices == test_fs_devices;
 }
 
 int btrfs_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, const char *subvol)
 {
        struct block_device *bdev = NULL;
        struct super_block *s;
        struct dentry *root;
+       struct btrfs_fs_devices *fs_devices = NULL;
        int error = 0;
 
-       bdev = open_bdev_excl(dev_name, flags, fs_type);
-       if (IS_ERR(bdev))
-               return PTR_ERR(bdev);
+       error = btrfs_scan_one_device(dev_name, flags, fs_type, &fs_devices);
+       if (error)
+               return error;
 
-       /*
-        * once the super is inserted into the list by sget, s_umount
-        * will protect the lockfs code from trying to start a snapshot
-        * while we are mounting
-        */
-       down(&bdev->bd_mount_sem);
-       s = sget(fs_type, test_bdev_super, set_bdev_super, bdev);
-       up(&bdev->bd_mount_sem);
+       error = btrfs_open_devices(fs_devices, flags, fs_type);
+       if (error)
+               return error;
+
+       bdev = fs_devices->latest_bdev;
+       btrfs_lock_volumes();
+       s = sget(fs_type, btrfs_test_super, set_anon_super, fs_devices);
+       btrfs_unlock_volumes();
        if (IS_ERR(s))
                goto error_s;
 
@@ -365,20 +361,20 @@ int btrfs_get_sb_bdev(struct file_system_type *fs_type,
                        goto error_bdev;
                }
 
-               close_bdev_excl(bdev);
        } else {
                char b[BDEVNAME_SIZE];
 
                s->s_flags = flags;
                strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
-               sb_set_blocksize(s, block_size(bdev));
-               error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
+               error = btrfs_fill_super(s, fs_devices, data,
+                                        flags & MS_SILENT ? 1 : 0);
                if (error) {
                        up_write(&s->s_umount);
                        deactivate_super(s);
                        goto error;
                }
 
+               btrfs_sb(s)->fs_info->bdev_holder = fs_type;
                s->s_flags |= MS_ACTIVE;
        }
 
@@ -408,7 +404,7 @@ int btrfs_get_sb_bdev(struct file_system_type *fs_type,
 error_s:
        error = PTR_ERR(s);
 error_bdev:
-       close_bdev_excl(bdev);
+       btrfs_close_devices(fs_devices);
 error:
        return error;
 }
@@ -420,9 +416,8 @@ static int btrfs_get_sb(struct file_system_type *fs_type,
        int ret;
        char *subvol_name = NULL;
 
-       parse_options((char *)data, NULL, &subvol_name);
-       ret = btrfs_get_sb_bdev(fs_type, flags, dev_name, data,
-                       btrfs_fill_super, mnt,
+       btrfs_parse_options((char *)data, NULL, &subvol_name);
+       ret = btrfs_get_sb_bdev(fs_type, flags, dev_name, data, mnt,
                        subvol_name ? subvol_name : "default");
        if (subvol_name)
                kfree(subvol_name);
@@ -445,21 +440,39 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
        return 0;
 }
 
-static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
-                               unsigned long arg)
-{
-       printk("btrfs control ioctl %d\n", cmd);
-       return 0;
-}
-
 static struct file_system_type btrfs_fs_type = {
        .owner          = THIS_MODULE,
        .name           = "btrfs",
        .get_sb         = btrfs_get_sb,
-       .kill_sb        = kill_block_super,
+       .kill_sb        = kill_anon_super,
        .fs_flags       = FS_REQUIRES_DEV,
 };
 
+static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
+                               unsigned long arg)
+{
+       struct btrfs_ioctl_vol_args *vol;
+       struct btrfs_fs_devices *fs_devices;
+       int ret;
+       int len;
+
+       vol = kmalloc(sizeof(*vol), GFP_KERNEL);
+       if (copy_from_user(vol, (void __user *)arg, sizeof(*vol))) {
+               ret = -EFAULT;
+               goto out;
+       }
+       len = strnlen(vol->name, BTRFS_PATH_NAME_MAX);
+       switch (cmd) {
+       case BTRFS_IOC_SCAN_DEV:
+               ret = btrfs_scan_one_device(vol->name, MS_RDONLY,
+                                           &btrfs_fs_type, &fs_devices);
+               break;
+       }
+out:
+       kfree(vol);
+       return 0;
+}
+
 static void btrfs_write_super_lockfs(struct super_block *sb)
 {
        struct btrfs_root *root = btrfs_sb(sb);
@@ -474,7 +487,6 @@ static void btrfs_unlockfs(struct super_block *sb)
 
 static struct super_operations btrfs_super_ops = {
        .delete_inode   = btrfs_delete_inode,
-       .put_inode      = btrfs_put_inode,
        .put_super      = btrfs_put_super,
        .write_super    = btrfs_write_super,
        .sync_fs        = btrfs_sync_fs,
@@ -567,6 +579,7 @@ static void __exit exit_btrfs_fs(void)
        btrfs_interface_exit();
        unregister_filesystem(&btrfs_fs_type);
        btrfs_exit_sysfs();
+       btrfs_cleanup_fs_uuids();
 }
 
 module_init(init_btrfs_fs)
This page took 0.029052 seconds and 5 git commands to generate.