Btrfs-progs: skip opening all devices with restore
authorJosef Bacik <jbacik@fb.com>
Tue, 3 Feb 2015 14:48:57 +0000 (09:48 -0500)
committerJosef Bacik <jbacik@fb.com>
Mon, 9 Feb 2015 19:53:15 +0000 (14:53 -0500)
When we go to fixup the dev items after a restore we scan all existing devices.
If you happen to be a btrfs developer you could possibly open up some random
device that you didn't just restore onto, which gives you weird errors and makes
you super cranky and waste a day trying to figure out what is failing.  This
will make it so that we use the fd we've already opened for opening our ctree.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
btrfs-find-root.c
btrfs-image.c
chunk-recover.c
disk-io.c
disk-io.h
super-recover.c

index 3edb833..c6e6b82 100644 (file)
@@ -79,7 +79,7 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device)
                return NULL;
        }
 
-       ret = btrfs_scan_fs_devices(fd, device, &fs_devices, 0, 1);
+       ret = btrfs_scan_fs_devices(fd, device, &fs_devices, 0, 1, 0);
        if (ret)
                goto out;
 
index 3c78388..04ec473 100644 (file)
@@ -2557,16 +2557,19 @@ static int restore_metadump(const char *input, FILE *out, int old_restore,
        ret = wait_for_worker(&mdrestore);
 
        if (!ret && !multi_devices && !old_restore) {
+               struct btrfs_root *root;
                struct stat st;
 
-               info = open_ctree_fs_info(target, 0, 0,
+               root = open_ctree_fd(fileno(out), target, 0,
                                          OPEN_CTREE_PARTIAL |
-                                         OPEN_CTREE_WRITES);
-               if (!info) {
+                                         OPEN_CTREE_WRITES |
+                                         OPEN_CTREE_NO_DEVICES);
+               if (!root) {
                        fprintf(stderr, "unable to open %s\n", target);
                        ret = -EIO;
                        goto out;
                }
+               info = root->fs_info;
 
                if (stat(target, &st)) {
                        fprintf(stderr, "statting %s failed\n", target);
index 94efc43..832b3b1 100644 (file)
@@ -1520,7 +1520,7 @@ static int recover_prepare(struct recover_control *rc, char *path)
                goto fail_free_sb;
        }
 
-       ret = btrfs_scan_fs_devices(fd, path, &fs_devices, 0, 1);
+       ret = btrfs_scan_fs_devices(fd, path, &fs_devices, 0, 1, 0);
        if (ret)
                goto fail_free_sb;
 
index ca39f17..0aec56e 100644 (file)
--- a/disk-io.c
+++ b/disk-io.c
@@ -1006,7 +1006,8 @@ void btrfs_cleanup_all_caches(struct btrfs_fs_info *fs_info)
 
 int btrfs_scan_fs_devices(int fd, const char *path,
                          struct btrfs_fs_devices **fs_devices,
-                         u64 sb_bytenr, int super_recover)
+                         u64 sb_bytenr, int super_recover,
+                         int skip_devices)
 {
        u64 total_devs;
        u64 dev_size;
@@ -1033,7 +1034,7 @@ int btrfs_scan_fs_devices(int fd, const char *path,
                return ret;
        }
 
-       if (total_devs != 1) {
+       if (!skip_devices && total_devs != 1) {
                ret = btrfs_scan_lblkid();
                if (ret)
                        return ret;
@@ -1114,7 +1115,8 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
                fs_info->on_restoring = 1;
 
        ret = btrfs_scan_fs_devices(fp, path, &fs_devices, sb_bytenr,
-                                   (flags & OPEN_CTREE_RECOVER_SUPER));
+                                   (flags & OPEN_CTREE_RECOVER_SUPER),
+                                   (flags & OPEN_CTREE_NO_DEVICES));
        if (ret)
                goto out;
 
index f963a96..53df8f0 100644 (file)
--- a/disk-io.h
+++ b/disk-io.h
@@ -33,6 +33,7 @@ enum btrfs_open_ctree_flags {
        OPEN_CTREE_RESTORE              = (1 << 4),
        OPEN_CTREE_NO_BLOCK_GROUPS      = (1 << 5),
        OPEN_CTREE_EXCLUSIVE            = (1 << 6),
+       OPEN_CTREE_NO_DEVICES           = (1 << 7),
 };
 
 static inline u64 btrfs_sb_offset(int mirror)
@@ -68,7 +69,7 @@ void btrfs_release_all_roots(struct btrfs_fs_info *fs_info);
 void btrfs_cleanup_all_caches(struct btrfs_fs_info *fs_info);
 int btrfs_scan_fs_devices(int fd, const char *path,
                          struct btrfs_fs_devices **fs_devices, u64 sb_bytenr,
-                         int super_recover);
+                         int super_recover, int skip_devices);
 int btrfs_setup_chunk_tree_and_device_map(struct btrfs_fs_info *fs_info);
 
 struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr,
index 197fc4b..e2c3129 100644 (file)
@@ -279,7 +279,7 @@ int btrfs_recover_superblocks(const char *dname,
        }
        init_recover_superblock(&recover);
 
-       ret = btrfs_scan_fs_devices(fd, dname, &recover.fs_devices, 0, 1);
+       ret = btrfs_scan_fs_devices(fd, dname, &recover.fs_devices, 0, 1, 0);
        close(fd);
        if (ret) {
                ret = 1;