From: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Qu Wenruo <quwenruo@cn.fujitsu.com>
Subject: [PATCH v15.1 12/13] btrfs: relocation: Enhance error handling to avoid BUG_ON
Date: Tue, 6 Nov 2018 14:41:21 +0800 [thread overview]
Message-ID: <20181106064122.6154-13-lufq.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <20181106064122.6154-1-lufq.fnst@cn.fujitsu.com>
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
Since the introduction 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>
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
---
fs/btrfs/relocation.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index b7c304c6e741..ee96390d1e42 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -854,6 +854,13 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
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;
}
@@ -3021,8 +3028,15 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
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,
@@ -3030,10 +3044,9 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
if (ret < 0) {
if (ret != -EAGAIN || &block->rb_node == rb_first(blocks))
err = ret;
- goto out;
+ break;
}
}
-out:
err = finish_pending_nodes(trans, rc, path, err);
out_free_path:
--
2.19.1
next prev parent reply other threads:[~2018-11-06 6:41 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-06 6:41 [PATCH v15.1 00/13] Btrfs In-band De-duplication Lu Fengqi
2018-11-06 6:41 ` [PATCH v15.1 01/13] btrfs: dedupe: Introduce dedupe framework and its header Lu Fengqi
2018-11-08 9:53 ` Timofey Titovets
2018-11-09 21:10 ` Josef Bacik
2018-11-06 6:41 ` [PATCH v15.1 02/13] btrfs: dedupe: Introduce function to initialize dedupe info Lu Fengqi
2018-11-08 12:31 ` Timofey Titovets
2018-11-06 6:41 ` [PATCH v15.1 03/13] btrfs: dedupe: Introduce function to add hash into in-memory tree Lu Fengqi
2018-11-08 20:18 ` Timofey Titovets
2018-11-06 6:41 ` [PATCH v15.1 04/13] btrfs: dedupe: Introduce function to remove hash from " Lu Fengqi
2018-11-09 21:17 ` Josef Bacik
2018-11-06 6:41 ` [PATCH v15.1 05/13] btrfs: delayed-ref: Add support for increasing data ref under spinlock Lu Fengqi
2018-11-06 6:41 ` [PATCH v15.1 06/13] btrfs: dedupe: Introduce function to search for an existing hash Lu Fengqi
2018-11-06 6:41 ` [PATCH v15.1 07/13] btrfs: dedupe: Implement btrfs_dedupe_calc_hash interface Lu Fengqi
2018-11-06 6:41 ` [PATCH v15.1 08/13] btrfs: ordered-extent: Add support for dedupe Lu Fengqi
2018-11-06 6:41 ` [PATCH v15.1 09/13] btrfs: introduce type based delalloc metadata reserve Lu Fengqi
2018-11-06 6:41 ` [PATCH v15.1 10/13] btrfs: dedupe: Inband in-memory only de-duplication implement Lu Fengqi
2018-11-06 6:41 ` [PATCH v15.1 11/13] btrfs: dedupe: Add ioctl for inband deduplication Lu Fengqi
2018-11-06 6:41 ` Lu Fengqi [this message]
2018-11-06 6:41 ` [PATCH v15.1 13/13] btrfs: dedupe: Introduce new reconfigure ioctl Lu Fengqi
2018-11-10 7:21 ` [PATCH v15.1 00/13] Btrfs In-band De-duplication Anand Jain
2018-11-13 13:45 ` David Sterba
2018-11-14 3:47 ` Lu Fengqi
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=20181106064122.6154-13-lufq.fnst@cn.fujitsu.com \
--to=lufq.fnst@cn.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo@cn.fujitsu.com \
/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).