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>
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;
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);
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;
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;
return ret;
}
- if (total_devs != 1) {
+ if (!skip_devices && total_devs != 1) {
ret = btrfs_scan_lblkid();
if (ret)
return ret;
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;
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)
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,
}
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;