All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hugo Mills <hugo@carfax.org.uk>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/3] btrfs check: Fix wrong level access
Date: Mon,  5 May 2014 18:07:49 +0100	[thread overview]
Message-ID: <1399309671-9240-2-git-send-email-hugo@carfax.org.uk> (raw)
In-Reply-To: <1399309671-9240-1-git-send-email-hugo@carfax.org.uk>

There's no reason to assume that the bad key order is in a leaf block,
so accessing level 0 of the path is going to be an error if it's actually
a node block that's bad.

Reported-by: Chris Mason <clm@fb.com>
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
---
 cmds-check.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index d195e7a..fc84ad8 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -2418,6 +2418,7 @@ static int try_to_fix_bad_block(struct btrfs_trans_handle *trans,
 	struct btrfs_path *path;
 	struct btrfs_key k1, k2;
 	int i;
+	int level;
 	int ret;
 
 	if (status != BTRFS_TREE_BLOCK_BAD_KEY_ORDER)
@@ -2435,9 +2436,10 @@ static int try_to_fix_bad_block(struct btrfs_trans_handle *trans,
 	if (!path)
 		return -EIO;
 
-	path->lowest_level = btrfs_header_level(buf);
+	level = btrfs_header_level(buf);
+	path->lowest_level = level;
 	path->skip_check_block = 1;
-	if (btrfs_header_level(buf))
+	if (level)
 		btrfs_node_key_to_cpu(buf, &k1, 0);
 	else
 		btrfs_item_key_to_cpu(buf, &k1, 0);
@@ -2448,9 +2450,9 @@ static int try_to_fix_bad_block(struct btrfs_trans_handle *trans,
 		return -EIO;
 	}
 
-	buf = path->nodes[0];
+	buf = path->nodes[level];
 	for (i = 0; i < btrfs_header_nritems(buf) - 1; i++) {
-		if (btrfs_header_level(buf)) {
+		if (level) {
 			btrfs_node_key_to_cpu(buf, &k1, i);
 			btrfs_node_key_to_cpu(buf, &k2, i + 1);
 		} else {
-- 
1.9.2


  reply	other threads:[~2014-05-05 17:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-05 17:07 [[PATCH] 0/3] btrfs-check: Fix bitflipped keys from bad RAM Hugo Mills
2014-05-05 17:07 ` Hugo Mills [this message]
2014-05-05 17:07 ` [PATCH 2/3] btrfs check: Pre-sort keys in a block while searching Hugo Mills
2014-05-05 17:07 ` [PATCH 3/3] btrfs check: Attempt to fix misordered keys with bitflips in them Hugo Mills
2014-05-16 14:22   ` David Sterba
2014-05-16 14:43     ` Hugo Mills

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1399309671-9240-2-git-send-email-hugo@carfax.org.uk \
    --to=hugo@carfax.org.uk \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.