linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Liu Bo <bo.li.liu@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.cz>, Jeff Mahoney <jeffm@suse.com>
Subject: [PATCH] Btrfs: fix BUG_ON in btrfs_mark_buffer_dirty
Date: Fri,  2 Sep 2016 12:35:34 -0700	[thread overview]
Message-ID: <1472844934-32343-1-git-send-email-bo.li.liu@oracle.com> (raw)
In-Reply-To: <fe9b1bde-9069-b75f-eb53-83b729cde711@suse.com>

This can only happen with CONFIG_BTRFS_FS_CHECK_INTEGRITY=y.

Commit 1ba98d0 ("Btrfs: detect corruption when non-root leaf has zero item")
assumes that a leaf is its root when leaf->bytenr == btrfs_root_bytenr(root),
however, we should not use btrfs_root_bytenr(root) since it's mainly got
updated during committing transaction.  So the check can fail when doing
COW on this leaf while it is a root.

This changes to use "if (leaf == btrfs_root_node(root))" instead, just like
how we check whether leaf is a root in __btrfs_cow_block().

Reported-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 fs/btrfs/disk-io.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 9367c31..b401e6d 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -572,13 +572,17 @@ static noinline int check_leaf(struct btrfs_root *root,
 		 * open_ctree() some roots has not yet been set up.
 		 */
 		if (!IS_ERR_OR_NULL(check_root)) {
+			struct extent_buffer *eb;
+
+			eb = btrfs_root_node(check_root);
 			/* if leaf is the root, then it's fine */
-			if (leaf->start !=
-			    btrfs_root_bytenr(&check_root->root_item)) {
+			if (leaf != eb) {
 				CORRUPT("non-root leaf's nritems is 0",
-					leaf, root, 0);
+					leaf, check_root, 0);
+				free_extent_buffer(eb);
 				return -EIO;
 			}
+			free_extent_buffer(eb);
 		}
 		return 0;
 	}
-- 
2.5.5


  parent reply	other threads:[~2016-09-02 19:30 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04  4:57 [PATCH] Btrfs: detect corruption when non-root leaf has zero item Liu Bo
2016-08-16 17:07 ` David Sterba
2016-08-22  0:04   ` Liu Bo
2016-08-23 22:22 ` [PATCH v2] " Liu Bo
2016-08-24 11:51   ` David Sterba
2016-09-02  5:26   ` Jeff Mahoney
2016-09-02 19:33     ` Liu Bo
2016-09-02 19:35     ` Liu Bo [this message]
2016-09-05 15:28       ` [PATCH] Btrfs: fix BUG_ON in btrfs_mark_buffer_dirty Filipe Manana
2016-09-06 21:51         ` Liu Bo
2016-09-07 14:25           ` Jeff Mahoney
2016-09-07 21:36             ` Liu Bo
2016-10-12 21:23           ` Filipe Manana
2016-10-13  0:37             ` Liu Bo
2016-10-13  8:47               ` Filipe Manana
2016-10-17 13:00                 ` David Sterba
2016-10-17 15:44                   ` Liu Bo
2016-11-23 13:15                     ` Filipe Manana
2016-11-23 17:48                       ` Filipe Manana
2016-11-23 21:39                         ` Liu Bo

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=1472844934-32343-1-git-send-email-bo.li.liu@oracle.com \
    --to=bo.li.liu@oracle.com \
    --cc=dsterba@suse.cz \
    --cc=jeffm@suse.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).