Skip to contentSkip to conversation

btrfs-progs: bug fixes

PATCH In review TARUISI Hiroaki 2 participants 5 messages Oct 2, 2009 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: bug fixes

Hi,

I have tested btrfsck in some error case, such as item missing case or CRC error case or so. In this test session I found some bugs in btrfsck.c and disk-io.c in btrfs-progs.
1. The last pair of ptrs and items are not checked at 2 place of check_node/leaf.
2. Csum printed CRC error message is not correct.
3. In CRC error, btrfsck fails in segmentation fault.

I'll post three tiny patches to fix these bugs.

Signature · 1 line
taruisi
#1 lore raw

PATCH 1/1 btrfsck: Fix Check limit in check_node/leaf.

In btrfsck.c( check_node/leaf ), it seems that last pair of ptrs and items are not checked at 2 place.

---
 btrfsck.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
btrfsck.c +2 -2
index 73f1836..ecc7b19 100644
@@ -1720,7 +1720,7 @@ static int check_node(struct btrfs_root *root,
 		if (memcmp(parent_key, &key, sizeof(key)))
 			return 1;
 	}
-	for (i = 0; nritems > 1 && i < nritems - 2; i++) {
+	for (i = 0; nritems > 1 && i < nritems - 1; i++) {
 		btrfs_node_key(buf, &key, i);
 		btrfs_node_key_to_cpu(buf, &cpukey, i + 1);
 		if (btrfs_comp_keys(&key, &cpukey) >= 0)
@@ -1759,7 +1759,7 @@ static int check_leaf(struct btrfs_root *root,
 		       (unsigned long long)btrfs_header_bytenr(buf));
 		return 1;
 	}
-	for (i = 0; nritems > 1 && i < nritems - 2; i++) {
+	for (i = 0; nritems > 1 && i < nritems - 1; i++) {
 		btrfs_item_key(buf, &key, i);
 		btrfs_item_key_to_cpu(buf, &cpukey, i + 1);
 		if (btrfs_comp_keys(&key, &cpukey) >= 0) {
Signature · 1 line
1.6.2.1
#2 lore raw

PATCH 1/1 btrfs-progs: CRC on disk printed correctly in CRC error message

In reply to TARUISI Hiroaki

I've tested btrfsck in CRC error case. However CRC on disk printed in error message is not correct (extent_buffer itsself is printed).

---
 disk-io.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
disk-io.c +1 -1
index addebe1..190301f 100644
@@ -86,7 +86,7 @@ int csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
 		if (memcmp_extent_buffer(buf, result, 0, csum_size)) {
 			printk("checksum verify failed on %llu wanted %X "
 			       "found %X\n", (unsigned long long)buf->start,
-			       *((int *)result), *((int *)buf));
+			       *((int *)result), *((int *)buf->data));
 			free(result);
 			return 1;
 		}
Signature · 1 line
1.6.2.1
#3 lore raw

PATCH 1/1 btrfsck: CRC error case handling.

In reply to TARUISI Hiroaki

In tree block CRC error case, btrfsck fails in segmentation fault. In CRC error case, read_tree_block returns NULL as extent_buffer like other(ex. ENOMEM) case, and btrfsck refers it without check.

If CRC error tree block is tree root, btrfsck aborts in previous stage.
Like this, as for CRC error handling, BUG() is often used such as in find_and_setup_root(disk-io.c), but CRC error is not a bug, so, btrfsck should not abort but report, I think.

Because read_tree_block puts error message in CRC error case, patch logic is simply return to caller with error.

---
 btrfsck.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
btrfsck.c +7 -0
index ecc7b19..cc00e28 100644
@@ -2504,6 +2504,9 @@ static int run_next_block(struct btrfs_root *root,
 
 	/* fixme, get the real parent transid */
 	buf = read_tree_block(root, bytenr, size, 0);
+	if (buf == NULL)
+		return -1;
+
 	nritems = btrfs_header_nritems(buf);
 
 	ret = btrfs_lookup_extent_info(NULL, root, bytenr, size, NULL, &flags);
@@ -2785,6 +2788,8 @@ static int check_extents(struct btrfs_root *root)
 					      btrfs_root_bytenr(&ri),
 					      btrfs_level_size(root,
 					       btrfs_root_level(&ri)), 0);
+			if (buf == NULL)
+				return 1;
 			add_root_to_pending(buf, bits, bits_nr, &extent_cache,
 					    &pending, &seen, &reada, &nodes,
 					    &found_key);
@@ -2796,6 +2801,8 @@ static int check_extents(struct btrfs_root *root)
 	while(1) {
 		ret = run_next_block(root, bits, bits_nr, &last, &pending,
 				     &seen, &reada, &nodes, &extent_cache);
+		if (ret < 0)
+			return 1;
 		if (ret != 0)
 			break;
 	}
Signature · 1 line
1.6.2.1
#4 lore raw
In reply to TARUISI Hiroaki
Quoted 11 lines · TARUISI Hiroaki

Hi,

I have tested btrfsck in some error case, such as item missing case or CRC error case or so. In this test session I found some bugs in btrfsck.c and disk-io.c in btrfs-progs.
1. The last pair of ptrs and items are not checked at 2 place of check_node/leaf.
2. Csum printed CRC error message is not correct.
3. In CRC error, btrfsck fails in segmentation fault.

I'll post three tiny patches to fix these bugs.

Thank you for spending time in the btrfsck code. I'll test these out and get them pushed into the btrfs-progs repository.

-chris