All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v11 11/13] btrfs: relocation: Enhance error handling to avoid BUG_ON
Date: Wed, 15 Jun 2016 10:09:59 +0800	[thread overview]
Message-ID: <20160615021001.9588-12-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <20160615021001.9588-1-quwenruo@cn.fujitsu.com>

Since the introduce of btrfs dedupe tree, it's possible that balance can
race with dedupe disabling.

When this happens, dedupe_enabled will make btrfs_get_fs_root() return
PTR_ERR(-ENOENT).
But due to a bug in error handling branch, when this happens
backref_cache->nr_nodes is increased but the node is neither added to
backref_cache or nr_nodes decreased.
Causing BUG_ON() in backref_cache_cleanup()

[ 2611.668810] ------------[ cut here ]------------
[ 2611.669946] kernel BUG at
/home/sat/ktest/linux/fs/btrfs/relocation.c:243!
[ 2611.670572] invalid opcode: 0000 [#1] SMP
[ 2611.686797] Call Trace:
[ 2611.687034]  [<ffffffffa01f71d3>]
btrfs_relocate_block_group+0x1b3/0x290 [btrfs]
[ 2611.687706]  [<ffffffffa01cc177>]
btrfs_relocate_chunk.isra.40+0x47/0xd0 [btrfs]
[ 2611.688385]  [<ffffffffa01cdb12>] btrfs_balance+0xb22/0x11e0 [btrfs]
[ 2611.688966]  [<ffffffffa01d9611>] btrfs_ioctl_balance+0x391/0x3a0
[btrfs]
[ 2611.689587]  [<ffffffffa01ddaf0>] btrfs_ioctl+0x1650/0x2290 [btrfs]
[ 2611.690145]  [<ffffffff81171cda>] ? lru_cache_add+0x3a/0x80
[ 2611.690647]  [<ffffffff81171e4c>] ?
lru_cache_add_active_or_unevictable+0x4c/0xc0
[ 2611.691310]  [<ffffffff81193f04>] ? handle_mm_fault+0xcd4/0x17f0
[ 2611.691842]  [<ffffffff811da423>] ? cp_new_stat+0x153/0x180
[ 2611.692342]  [<ffffffff8119913d>] ? __vma_link_rb+0xfd/0x110
[ 2611.692842]  [<ffffffff81199209>] ? vma_link+0xb9/0xc0
[ 2611.693303]  [<ffffffff811e7e81>] do_vfs_ioctl+0xa1/0x5a0
[ 2611.693781]  [<ffffffff8104e024>] ? __do_page_fault+0x1b4/0x400
[ 2611.694310]  [<ffffffff811e83c1>] SyS_ioctl+0x41/0x70
[ 2611.694758]  [<ffffffff816dfc6e>] entry_SYSCALL_64_fastpath+0x12/0x71
[ 2611.695331] Code: ff 48 8b 45 bf 49 83 af a8 05 00 00 01 49 89 87 a0
05 00 00 e9 2e fd ff ff b8 f4 ff ff ff e9 e4 fb ff ff 0f 0b 0f 0b 0f 0b
0f 0b <0f> 0b 0f 0b 41 89 c6 e9 b8 fb ff ff e8 9e a6 e8 e0 4c 89 e7 44
[ 2611.697870] RIP  [<ffffffffa01f6fc1>]
relocate_block_group+0x741/0x7a0 [btrfs]
[ 2611.698818]  RSP <ffff88002a81fb30>

This patch will call remove_backref_node() in error handling branch, and
cache the returned -ENOENT in relocate_tree_block() and continue
balancing.

Reported-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 fs/btrfs/relocation.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index b7de713..32fcd8d 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -887,6 +887,13 @@ again:
 		root = read_fs_root(rc->extent_root->fs_info, key.offset);
 		if (IS_ERR(root)) {
 			err = PTR_ERR(root);
+			/*
+			 * Don't forget to cleanup current node.
+			 * As it may not be added to backref_cache but nr_node
+			 * increased.
+			 * This will cause BUG_ON() in backref_cache_cleanup().
+			 */
+			remove_backref_node(&rc->backref_cache, cur);
 			goto out;
 		}
 
@@ -2991,14 +2998,21 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
 	}
 
 	rb_node = rb_first(blocks);
-	while (rb_node) {
+	for (rb_node = rb_first(blocks); rb_node; rb_node = rb_next(rb_node)) {
 		block = rb_entry(rb_node, struct tree_block, rb_node);
 
 		node = build_backref_tree(rc, &block->key,
 					  block->level, block->bytenr);
 		if (IS_ERR(node)) {
+			/*
+			 * The root(dedupe tree yet) of the tree block is
+			 * going to be freed and can't be reached.
+			 * Just skip it and continue balancing.
+			 */
+			if (PTR_ERR(node) == -ENOENT)
+				continue;
 			err = PTR_ERR(node);
-			goto out;
+			break;
 		}
 
 		ret = relocate_tree_block(trans, rc, node, &block->key,
@@ -3006,11 +3020,9 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
 		if (ret < 0) {
 			if (ret != -EAGAIN || rb_node == rb_first(blocks))
 				err = ret;
-			goto out;
+			break;
 		}
-		rb_node = rb_next(rb_node);
 	}
-out:
 	err = finish_pending_nodes(trans, rc, path, err);
 
 out_free_path:
-- 
2.8.3




  parent reply	other threads:[~2016-06-15  2:10 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-15  2:09 [PATCH v11 00/13] Btrfs dedupe framework Qu Wenruo
2016-06-15  2:09 ` [PATCH v11 01/13] btrfs: dedupe: Introduce dedupe framework and its header Qu Wenruo
2016-06-15  2:09 ` [PATCH v11 02/13] btrfs: dedupe: Introduce function to initialize dedupe info Qu Wenruo
2016-06-15  2:09 ` [PATCH v11 03/13] btrfs: dedupe: Introduce function to add hash into in-memory tree Qu Wenruo
2016-06-15  2:09 ` [PATCH v11 04/13] btrfs: dedupe: Introduce function to remove hash from " Qu Wenruo
2016-06-15  2:09 ` [PATCH v11 05/13] btrfs: delayed-ref: Add support for increasing data ref under spinlock Qu Wenruo
2016-06-15  2:09 ` [PATCH v11 06/13] btrfs: dedupe: Introduce function to search for an existing hash Qu Wenruo
2016-06-15  2:09 ` [PATCH v11 07/13] btrfs: dedupe: Implement btrfs_dedupe_calc_hash interface Qu Wenruo
2016-06-15  2:09 ` [PATCH v11 08/13] btrfs: ordered-extent: Add support for dedupe Qu Wenruo
2016-06-15  2:09 ` [PATCH v11 09/13] btrfs: dedupe: Inband in-memory only de-duplication implement Qu Wenruo
2016-06-15  2:09 ` [PATCH v11 10/13] btrfs: dedupe: Add ioctl for inband dedupelication Qu Wenruo
2016-06-15  2:09 ` Qu Wenruo [this message]
2016-06-15  2:10 ` [PATCH v11 12/13] btrfs: improve inode's outstanding_extents computation Qu Wenruo
2016-06-15  2:10 ` [PATCH v11 13/13] btrfs: dedupe: fix false ENOSPC Qu Wenruo
2016-06-15  3:11   ` kbuild test robot
2016-06-15  3:17   ` [PATCH v11.1 " Qu Wenruo
2016-06-15  3:26   ` [PATCH v11 " kbuild test robot
2016-06-20 16:03 ` [PATCH v11 00/13] Btrfs dedupe framework David Sterba
2016-06-21  0:36   ` Qu Wenruo
2016-06-21  9:13     ` David Sterba
2016-06-21  9:26       ` Qu Wenruo
2016-06-21  9:34         ` David Sterba
2016-06-21 16:55           ` Chandan Rajendra
2016-06-23 12:17             ` David Sterba
2016-06-24  2:50               ` Qu Wenruo
2016-06-24  4:34                 ` Chandan Rajendra
2016-06-24  9:29                 ` Chandan Rajendra
2016-06-25  1:22                   ` Qu Wenruo
2016-06-25  5:45                     ` Chandan Rajendra
2016-06-27  3:04                       ` Qu Wenruo
2016-06-24  4:10               ` Chandan Rajendra
2016-06-22  1:48 ` Qu Wenruo
2016-06-24  6:54   ` Satoru Takeuchi
2016-06-24  8:30     ` Qu Wenruo

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=20160615021001.9588-12-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.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 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.