public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: bug fixes
@ 2009-10-02  5:35 TARUISI Hiroaki
  2009-10-02  5:39 ` [PATCH] btrfsck: Fix Check limit in check_node/leaf TARUISI Hiroaki
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: TARUISI Hiroaki @ 2009-10-02  5:35 UTC (permalink / raw)
  To: linux-btrfs; +Cc: chris.mason

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.

-- 
taruisi


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] btrfsck: Fix Check limit in check_node/leaf.
  2009-10-02  5:35 [PATCH] btrfs-progs: bug fixes TARUISI Hiroaki
@ 2009-10-02  5:39 ` TARUISI Hiroaki
  2009-10-02  5:52 ` [PATCH] btrfs-progs: CRC on disk printed correctly in CRC error message TARUISI Hiroaki
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: TARUISI Hiroaki @ 2009-10-02  5:39 UTC (permalink / raw)
  To: linux-btrfs; +Cc: chris.mason


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


Signed-off-by: TARUISI Hiroaki <taruishi.hiroak@jp.fujitsu.com>
---
 btrfsck.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/btrfsck.c b/btrfsck.c
index 73f1836..ecc7b19 100644
--- a/btrfsck.c
+++ b/btrfsck.c
@@ -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) {
-- 
1.6.2.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] btrfs-progs: CRC on disk printed correctly in CRC error message
  2009-10-02  5:35 [PATCH] btrfs-progs: bug fixes TARUISI Hiroaki
  2009-10-02  5:39 ` [PATCH] btrfsck: Fix Check limit in check_node/leaf TARUISI Hiroaki
@ 2009-10-02  5:52 ` TARUISI Hiroaki
  2009-10-02  5:52 ` [PATCH] btrfsck: CRC error case handling TARUISI Hiroaki
  2009-10-02 19:09 ` [PATCH] btrfs-progs: bug fixes Chris Mason
  3 siblings, 0 replies; 5+ messages in thread
From: TARUISI Hiroaki @ 2009-10-02  5:52 UTC (permalink / raw)
  To: linux-btrfs; +Cc: chris.mason


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


Signed-off-by: TARUISI Hiroaki <taruishi.hiroak@jp.fujitsu.com>
---
 disk-io.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/disk-io.c b/disk-io.c
index addebe1..190301f 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -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;
 		}
-- 
1.6.2.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] btrfsck: CRC error case handling.
  2009-10-02  5:35 [PATCH] btrfs-progs: bug fixes TARUISI Hiroaki
  2009-10-02  5:39 ` [PATCH] btrfsck: Fix Check limit in check_node/leaf TARUISI Hiroaki
  2009-10-02  5:52 ` [PATCH] btrfs-progs: CRC on disk printed correctly in CRC error message TARUISI Hiroaki
@ 2009-10-02  5:52 ` TARUISI Hiroaki
  2009-10-02 19:09 ` [PATCH] btrfs-progs: bug fixes Chris Mason
  3 siblings, 0 replies; 5+ messages in thread
From: TARUISI Hiroaki @ 2009-10-02  5:52 UTC (permalink / raw)
  To: linux-btrfs; +Cc: chris.mason


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.


Signed-off-by: TARUISI Hiroaki <taruishi.hiroak@jp.fujitsu.com>
---
 btrfsck.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/btrfsck.c b/btrfsck.c
index ecc7b19..cc00e28 100644
--- a/btrfsck.c
+++ b/btrfsck.c
@@ -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;
 	}
-- 
1.6.2.1




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs-progs: bug fixes
  2009-10-02  5:35 [PATCH] btrfs-progs: bug fixes TARUISI Hiroaki
                   ` (2 preceding siblings ...)
  2009-10-02  5:52 ` [PATCH] btrfsck: CRC error case handling TARUISI Hiroaki
@ 2009-10-02 19:09 ` Chris Mason
  3 siblings, 0 replies; 5+ messages in thread
From: Chris Mason @ 2009-10-02 19:09 UTC (permalink / raw)
  To: TARUISI Hiroaki; +Cc: linux-btrfs

On Fri, Oct 02, 2009 at 02:35:20PM +0900, TARUISI Hiroaki wrote:
> 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-10-02 19:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-02  5:35 [PATCH] btrfs-progs: bug fixes TARUISI Hiroaki
2009-10-02  5:39 ` [PATCH] btrfsck: Fix Check limit in check_node/leaf TARUISI Hiroaki
2009-10-02  5:52 ` [PATCH] btrfs-progs: CRC on disk printed correctly in CRC error message TARUISI Hiroaki
2009-10-02  5:52 ` [PATCH] btrfsck: CRC error case handling TARUISI Hiroaki
2009-10-02 19:09 ` [PATCH] btrfs-progs: bug fixes Chris Mason

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox