mirror of
https://github.com/kdave/btrfs-progs
synced 2024-12-24 07:02:45 +00:00
Btrfs-progs: skip opening all devices with restore
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>
This commit is contained in:
parent
c6b388ef2d
commit
34a5ec12ee
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user