Btrfs-progs: pass flag to control whether run ioctl in btrfs_scan_for_fsid()
authorWang Shilong <wangsl.fnst@cn.fujitsu.com>
Wed, 18 Sep 2013 08:27:34 +0000 (16:27 +0800)
committerChris Mason <chris.mason@fusionio.com>
Wed, 16 Oct 2013 12:22:26 +0000 (08:22 -0400)
If some fatal superblocks are damaged, running ioctl will return failure,
in this case, we should avoid run ioctl.

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>
btrfs-find-root.c
chunk-recover.c
disk-io.c
disk-io.h

index b48c800..7572f52 100644 (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, 0);
+       ret = btrfs_scan_fs_devices(fd, device, &fs_devices, 0, 1);
        if (ret)
                goto out;
 
index 45da9a6..9af4887 100644 (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, 0);
+       ret = btrfs_scan_fs_devices(fd, path, &fs_devices, 0, 1);
        if (ret)
                goto fail_free_sb;
 
index bc673c2..6281569 100644 (file)
--- a/disk-io.c
+++ b/disk-io.c
@@ -911,7 +911,7 @@ 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)
+                         u64 sb_bytenr, int run_ioctl)
 {
        u64 total_devs;
        int ret;
@@ -926,7 +926,7 @@ int btrfs_scan_fs_devices(int fd, const char *path,
        }
 
        if (total_devs != 1) {
-               ret = btrfs_scan_for_fsid(1);
+               ret = btrfs_scan_for_fsid(run_ioctl);
                if (ret)
                        return ret;
        }
@@ -1005,7 +1005,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, sb_bytenr);
+       ret = btrfs_scan_fs_devices(fp, path, &fs_devices, sb_bytenr, 1);
        if (ret)
                goto out;
 
index b61eb43..7219c2e 100644 (file)
--- a/disk-io.h
+++ b/disk-io.h
@@ -57,7 +57,8 @@ 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, u64 sb_bytenr);
+                         struct btrfs_fs_devices **fs_devices, u64 sb_bytenr,
+                         int run_ioctl);
 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);