diff mbox

[4/4] Btrfs-progs: fsck: fix wrong check for btrfs_read_fs_root()

Message ID 1401276041-18349-4-git-send-email-wangsl.fnst@cn.fujitsu.com (mailing list archive)
State Accepted
Delegated to: David Sterba
Headers show

Commit Message

Wang Shilong May 28, 2014, 11:20 a.m. UTC
When encountering a corrupted fs root node, fsck hit following message:

Check tree block failed, want=29360128, have=0
Check tree block failed, want=29360128, have=0
Check tree block failed, want=29360128, have=0
Check tree block failed, want=29360128, have=0
Check tree block failed, want=29360128, have=0
read block failed check_tree_block
Checking filesystem on /dev/sda9
UUID: 0d295d80-bae2-45f2-a106-120dbfd0e173
checking extents
Segmentation fault (core dumped)

This is because in btrfs_setup_all_roots(), we check
btrfs_read_fs_root() return value by verifing whether it is
NULL pointer, this is wrong since btrfs_read_fs_root() return
PTR_ERR(ret), fix it.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
---
 btrfs-calc-size.c | 2 +-
 disk-io.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/btrfs-calc-size.c b/btrfs-calc-size.c
index a832ee0..5eabdfc 100644
--- a/btrfs-calc-size.c
+++ b/btrfs-calc-size.c
@@ -326,7 +326,7 @@  static int calc_root_size(struct btrfs_root *tree_root, struct btrfs_key *key,
 	int size_fail = 0;
 
 	root = btrfs_read_fs_root(tree_root->fs_info, key);
-	if (!root) {
+	if (IS_ERR(root)) {
 		fprintf(stderr, "Failed to read root %Lu\n", key->objectid);
 		return 1;
 	}
diff --git a/disk-io.c b/disk-io.c
index bbfd8e7..c1c5b70 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -946,7 +946,7 @@  int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
 	key.offset = (u64)-1;
 	fs_info->fs_root = btrfs_read_fs_root(fs_info, &key);
 
-	if (!fs_info->fs_root)
+	if (IS_ERR(fs_info->fs_root))
 		return -EIO;
 	return 0;
 }