Btrfs-progs: fix wrong arg sb_bytenr for btrfs_scan_fs_devices()

For most time, In open_ctree_*(), we use the first superblock
(BTRFS_SUPER_INFO_OFFSET). However, for btrfs-convert, we don't,
we should pass the correct sb_bytenr to btrfs_scan_fs_devices() rather
than always use BTRFS_SUPER_INFO_OFFSET.This patch fix the following
regression:

mkfs.ext2 <dev>
btrfs-convert <dev>

warning, device 1 is missing
Check tree block failed, want=2670592, have=0
read block failed check_tree_block
Couldn't read chunk root
Segmentation fault (core dumped)

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
master
Wang Shilong 2013-07-18 00:03:40 +08:00 committed by David Sterba
parent b3a9a3c94a
commit 44aa9dce55
4 changed files with 9 additions and 6 deletions

View File

@ -82,7 +82,7 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device)
return NULL;
}
ret = btrfs_scan_fs_devices(fd, device, &fs_devices);
ret = btrfs_scan_fs_devices(fd, device, &fs_devices, 0);
if (ret)
goto out;

View File

@ -1291,7 +1291,7 @@ static int recover_prepare(struct recover_control *rc, char *path)
goto fail_free_sb;
}
ret = btrfs_scan_fs_devices(fd, path, &fs_devices);
ret = btrfs_scan_fs_devices(fd, path, &fs_devices, 0);
if (ret)
goto fail_free_sb;

View File

@ -909,13 +909,16 @@ 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)
struct btrfs_fs_devices **fs_devices,
u64 sb_bytenr)
{
u64 total_devs;
int ret;
if (!sb_bytenr)
sb_bytenr = BTRFS_SUPER_INFO_OFFSET;
ret = btrfs_scan_one_device(fd, path, fs_devices,
&total_devs, BTRFS_SUPER_INFO_OFFSET);
&total_devs, sb_bytenr);
if (ret) {
fprintf(stderr, "No valid Btrfs found on %s\n", path);
return ret;
@ -1001,7 +1004,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
if (restore)
fs_info->on_restoring = 1;
ret = btrfs_scan_fs_devices(fp, path, &fs_devices);
ret = btrfs_scan_fs_devices(fp, path, &fs_devices, sb_bytenr);
if (ret)
goto out;

View File

@ -59,7 +59,7 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info,
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);
struct btrfs_fs_devices **fs_devices, u64 sb_bytenr);
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, int writes);