From patchwork Fri Aug 3 05:50:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10554575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C57715E9 for ; Fri, 3 Aug 2018 05:50:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 601032C2B3 for ; Fri, 3 Aug 2018 05:50:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 544722C36B; Fri, 3 Aug 2018 05:50:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F10082C2B3 for ; Fri, 3 Aug 2018 05:50:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727313AbeHCHpH (ORCPT ); Fri, 3 Aug 2018 03:45:07 -0400 Received: from mx2.suse.de ([195.135.220.15]:41492 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726799AbeHCHpH (ORCPT ); Fri, 3 Aug 2018 03:45:07 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D3E83AFA5 for ; Fri, 3 Aug 2018 05:50:27 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/6] btrfs-progs: Exit gracefully if we hit ENOSPC when allocating tree block Date: Fri, 3 Aug 2018 13:50:17 +0800 Message-Id: <20180803055022.9816-2-wqu@suse.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180803055022.9816-1-wqu@suse.com> References: <20180803055022.9816-1-wqu@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When running test fuzz/003, we could hit the following BUG_ON: ------ Reviewed-by: Nikolay Borisov ====== RUN MAYFAIL /home/adam/btrfs/btrfs-progs/btrfs check --init-csum-tree /home/adam/btrfs/btrfs-progs/tests//fuzz-tests/images/bko-155621-bad-block-group-offset.raw.restored Unable to find block group for 0 Unable to find block group for 0 Unable to find block group for 0 extent-tree.c:2657: alloc_tree_block: BUG_ON `ret` triggered, value -28 failed (ignored, ret=134): /home/adam/btrfs/btrfs-progs/btrfs check --init-csum-tree /home/adam/btrfs/btrfs-progs/tests//fuzz-tests/images/bko-155621-bad-block-group-offset.raw.restored mayfail: returned code 134 (SIGABRT), not ignored test failed for case 003-multi-check-unmounted ------ Just remove that BUG_ON() and allow us to exit gracefully. Signed-off-by: Qu Wenruo --- extent-tree.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extent-tree.c b/extent-tree.c index b9d51b388c9a..a1f711ece7a8 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -2654,7 +2654,10 @@ static int alloc_tree_block(struct btrfs_trans_handle *trans, ret = btrfs_reserve_extent(trans, root, num_bytes, empty_size, hint_byte, search_end, ins, 0); - BUG_ON(ret); + if (ret < 0) { + btrfs_free_delayed_extent_op(extent_op); + return ret; + } if (key) memcpy(&extent_op->key, key, sizeof(extent_op->key)); From patchwork Fri Aug 3 05:50:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10554577 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CDC6139A for ; Fri, 3 Aug 2018 05:50:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 226952C356 for ; Fri, 3 Aug 2018 05:50:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16E7C2C385; Fri, 3 Aug 2018 05:50:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5E282C356 for ; Fri, 3 Aug 2018 05:50:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727426AbeHCHpJ (ORCPT ); Fri, 3 Aug 2018 03:45:09 -0400 Received: from mx2.suse.de ([195.135.220.15]:41500 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726799AbeHCHpJ (ORCPT ); Fri, 3 Aug 2018 03:45:09 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9FD57AF76 for ; Fri, 3 Aug 2018 05:50:29 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/6] btrfs-progs: Exit gracefully when failed to repair root dir item Date: Fri, 3 Aug 2018 13:50:18 +0800 Message-Id: <20180803055022.9816-3-wqu@suse.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180803055022.9816-1-wqu@suse.com> References: <20180803055022.9816-1-wqu@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Another BUG_ON() during fuzz/003: ------ Reviewed-by: Nikolay Borisov ====== RUN MAYFAIL /home/adam/btrfs/btrfs-progs/btrfs check --init-csum-tree /home/adam/btrfs/btrfs-progs/tests//fuzz-tests/images/bko-161821.raw.restored [1/7] checking root items Fixed 0 roots. [2/7] checking extents parent transid verify failed on 4198400 wanted 14 found 1114126 parent transid verify failed on 4198400 wanted 14 found 1114126 Ignoring transid failure owner ref check failed [4198400 4096] repair deleting extent record: key [4198400,169,0] adding new tree backref on start 4198400 len 4096 parent 0 root 5 Repaired extent references for 4198400 ref mismatch on [4222976 4096] extent item 1, found 0 backref 4222976 root 7 not referenced back 0x55e9cc694780 incorrect global backref count on 4222976 found 1 wanted 0 backpointer mismatch on [4222976 4096] owner ref check failed [4222976 4096] repair deleting extent record: key [4222976,169,0] Repaired extent references for 4222976 [3/7] checking free space cache [4/7] checking fs roots parent transid verify failed on 4198400 wanted 14 found 1114126 Ignoring transid failure Wrong generation of child node/leaf, wanted: 1114126, have: 14 root 5 missing its root dir, recreating parent transid verify failed on 4198400 wanted 14 found 1114126 Ignoring transid failure ERROR: child eb corrupted: parent bytenr=4222976 item=0 parent level=1 child level=2 check/main.c:2738: check_inode_recs: BUG_ON `ret` triggered, value -5 failed (ignored, ret=134): /home/adam/btrfs/btrfs-progs/btrfs check --init-csum-tree /home/adam/btrfs/btrfs-progs/tests//fuzz-tests/images/bko-161821.raw.restored mayfail: returned code 134 (SIGABRT), not ignored test failed for case 003-multi-check-unmounted ------ Just abort current transaction and exit gracefully in this case. Signed-off-by: Qu Wenruo --- check/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/check/main.c b/check/main.c index b597e2a607e5..e6756e0f852b 100644 --- a/check/main.c +++ b/check/main.c @@ -2735,7 +2735,10 @@ static int check_inode_recs(struct btrfs_root *root, (unsigned long long)root->objectid); ret = btrfs_make_root_dir(trans, root, root_dirid); - BUG_ON(ret); + if (ret < 0) { + btrfs_abort_transaction(trans, ret); + return ret; + } btrfs_commit_transaction(trans, root); return -EAGAIN; From patchwork Fri Aug 3 05:50:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10554579 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B57A5139A for ; Fri, 3 Aug 2018 05:50:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB66C2C356 for ; Fri, 3 Aug 2018 05:50:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FF032C385; Fri, 3 Aug 2018 05:50:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 409062C356 for ; Fri, 3 Aug 2018 05:50:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727494AbeHCHpL (ORCPT ); Fri, 3 Aug 2018 03:45:11 -0400 Received: from mx2.suse.de ([195.135.220.15]:41512 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726799AbeHCHpL (ORCPT ); Fri, 3 Aug 2018 03:45:11 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 6A97CAFA5 for ; Fri, 3 Aug 2018 05:50:31 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/6] btrfs-progs: Don't report dirty leaked eb using BUG_ON Date: Fri, 3 Aug 2018 13:50:19 +0800 Message-Id: <20180803055022.9816-4-wqu@suse.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180803055022.9816-1-wqu@suse.com> References: <20180803055022.9816-1-wqu@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Another BUG_ON() during fuzz/003: ------ ====== RUN MAYFAIL /home/adam/btrfs/btrfs-progs/btrfs check --init-csum-tree /home/adam/btrfs/btrfs-progs/tests//fuzz-tests/images/bko-161821.raw.restored [1/7] checking root items Fixed 0 roots. [2/7] checking extents parent transid verify failed on 4198400 wanted 14 found 1114126 parent transid verify failed on 4198400 wanted 14 found 1114126 Ignoring transid failure owner ref check failed [4198400 4096] repair deleting extent record: key [4198400,169,0] adding new tree backref on start 4198400 len 4096 parent 0 root 5 Repaired extent references for 4198400 ref mismatch on [4222976 4096] extent item 1, found 0 backref 4222976 root 7 not referenced back 0x5617f8ecf780 incorrect global backref count on 4222976 found 1 wanted 0 backpointer mismatch on [4222976 4096] owner ref check failed [4222976 4096] repair deleting extent record: key [4222976,169,0] Repaired extent references for 4222976 [3/7] checking free space cache [4/7] checking fs roots parent transid verify failed on 4198400 wanted 14 found 1114126 Ignoring transid failure Wrong generation of child node/leaf, wanted: 1114126, have: 14 root 5 missing its root dir, recreating parent transid verify failed on 4198400 wanted 14 found 1114126 Ignoring transid failure ERROR: child eb corrupted: parent bytenr=4222976 item=0 parent level=1 child level=2 ERROR: errors found in fs roots extent buffer leak: start 4222976 len 4096 extent_io.c:611: free_extent_buffer_internal: BUG_ON `eb->flags & EXTENT_DIRTY` triggered, value 1 failed (ignored, ret=134): /home/adam/btrfs/btrfs-progs/btrfs check --init-csum-tree /home/adam/btrfs/btrfs-progs/tests//fuzz-tests/images/bko-161821.raw.restored mayfail: returned code 134 (SIGABRT), not ignored test failed for case 003-multi-check-unmounted ------ Since we're shifting to using btrfs_abort_transaction() in btrfs-progs, it will be more and more common to see dirty leaked eb. Instead of BUG_ON(), we only needs to report it as warning. Signed-off-by: Qu Wenruo --- extent_io.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extent_io.c b/extent_io.c index 198492699438..b8510b0ae94e 100644 --- a/extent_io.c +++ b/extent_io.c @@ -608,7 +608,11 @@ static void free_extent_buffer_internal(struct extent_buffer *eb, bool free_now) eb->refs--; BUG_ON(eb->refs < 0); if (eb->refs == 0) { - BUG_ON(eb->flags & EXTENT_DIRTY); + if (eb->flags & EXTENT_DIRTY) { + warning( + "dirty eb leak (aborted trans): start %llu len %u", + eb->start, eb->len); + } list_del_init(&eb->recow); if (eb->flags & EXTENT_BUFFER_DUMMY || free_now) free_extent_buffer_final(eb); From patchwork Fri Aug 3 05:50:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10554581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 634C7139A for ; Fri, 3 Aug 2018 05:50:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59DAB2C356 for ; Fri, 3 Aug 2018 05:50:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E6882C385; Fri, 3 Aug 2018 05:50:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3B192C356 for ; Fri, 3 Aug 2018 05:50:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727606AbeHCHpM (ORCPT ); Fri, 3 Aug 2018 03:45:12 -0400 Received: from mx2.suse.de ([195.135.220.15]:41522 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726799AbeHCHpM (ORCPT ); Fri, 3 Aug 2018 03:45:12 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 266C1AF76 for ; Fri, 3 Aug 2018 05:50:33 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/6] btrfs-progs: Fix infinite loop when failed to repair bad key order Date: Fri, 3 Aug 2018 13:50:20 +0800 Message-Id: <20180803055022.9816-5-wqu@suse.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180803055022.9816-1-wqu@suse.com> References: <20180803055022.9816-1-wqu@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP [BUG] An infinite loop can be triggered during fuzz/003: ------ ====== RUN MAYFAIL /home/adam/btrfs/btrfs-progs/btrfs check --repair /home/adam/btrfs/btrfs-progs/tests//fuzz-tests/images/bko-199833-reloc-recovery-crash.raw.restored [1/7] checking root items Fixed 0 roots. [2/7] checking extents ctree.c:1650: leaf_space_used: Warning: assertion `data_len < 0` failed, value 1 bad key ordering 18 19 ctree.c:1650: leaf_space_used: Warning: assertion `data_len < 0` failed, value 1 bad key ordering 18 19 ctree.c:1650: leaf_space_used: Warning: assertion `data_len < 0` failed, value 1 bad key ordering 18 19 ... ------ [CAUSE] In try_to_fix_bad_block() it's possible that btrfs_find_all_roots() finds no root referring to that tree block, thus we can't do any repair. However in that case, we still return 0 since the last caller assigning @ret is btrfs_find_all_roots(), and the ulist while loop doesn't get run at all. And since try_to_fix_bad_block() returns 0, check_block() in check/main.c will return -EAGAIN to re-check the tree block. This leads to the infinite loop. [FIX] Change the default return value from 0 to -EIO in try_to_fix_bad_block(), so if there is no tree referring to the bad tree block, it won't cause infinite loop any more. Signed-off-by: Qu Wenruo --- check/main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/check/main.c b/check/main.c index e6756e0f852b..571edc7ef928 100644 --- a/check/main.c +++ b/check/main.c @@ -4051,6 +4051,11 @@ static int try_to_fix_bad_block(struct btrfs_root *root, btrfs_init_path(&path); ULIST_ITER_INIT(&iter); + /* + * If we found no roots referrening to this tree block, there is no + * chance to fix. So our default ret is -EIO. + */ + ret = -EIO; while ((node = ulist_next(roots, &iter))) { root_key.objectid = node->val; root_key.type = BTRFS_ROOT_ITEM_KEY; From patchwork Fri Aug 3 05:50:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10554583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6825715A6 for ; Fri, 3 Aug 2018 05:50:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E7FD2C356 for ; Fri, 3 Aug 2018 05:50:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52D802C385; Fri, 3 Aug 2018 05:50:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFB852C356 for ; Fri, 3 Aug 2018 05:50:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727619AbeHCHpO (ORCPT ); Fri, 3 Aug 2018 03:45:14 -0400 Received: from mx2.suse.de ([195.135.220.15]:41538 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726799AbeHCHpO (ORCPT ); Fri, 3 Aug 2018 03:45:14 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E714FAF76 for ; Fri, 3 Aug 2018 05:50:34 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 5/6] btrfs-progs: Exit gracefull when we failed to alloc dev extent Date: Fri, 3 Aug 2018 13:50:21 +0800 Message-Id: <20180803055022.9816-6-wqu@suse.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180803055022.9816-1-wqu@suse.com> References: <20180803055022.9816-1-wqu@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Another BUG_ON() during fuzz/003: ------ Reviewed-by: Nikolay Borisov ====== RUN MAYFAIL /home/adam/btrfs/btrfs-progs/btrfs check --repair /home/adam/btrfs/btrfs-progs/tests//fuzz-tests/images/bko-199833-reloc-recovery-crash.raw.restored [1/7] checking root items Fixed 0 roots. [2/7] checking extents ctree.c:1650: leaf_space_used: Warning: assertion `data_len < 0` failed, value 1 bad key ordering 18 19 bad block 29409280 ERROR: errors found in extent allocation tree or chunk allocation WARNING: minor unaligned/mismatch device size detected WARNING: recommended to use 'btrfs rescue fix-device-size' to fix it [3/7] checking free space cache [4/7] checking fs roots ctree.c:1650: leaf_space_used: Warning: assertion `data_len < 0` failed, value 1 bad key ordering 18 19 root 18446744073709551608 missing its root dir, recreating Unable to find block group for 0 Unable to find block group for 0 Unable to find block group for 0 volumes.c:564: btrfs_alloc_dev_extent: BUG_ON `ret` triggered, value -28 failed (ignored, ret=134): /home/adam/btrfs/btrfs-progs/btrfs check --repair /home/adam/btrfs/btrfs-progs/tests//fuzz-tests/images/bko-199833-reloc-recovery-crash.raw.restored mayfail: returned code 134 (SIGABRT), not ignored test failed for case 003-multi-check-unmounted ------ However the culprit function btrfs_alloc_dev_extent() has proper error handler tag err:, just use that tag would solve the problem easily. Signed-off-by: Qu Wenruo --- volumes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/volumes.c b/volumes.c index d81b348eb14d..f7a413b71d52 100644 --- a/volumes.c +++ b/volumes.c @@ -561,7 +561,8 @@ static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans, key.type = BTRFS_DEV_EXTENT_KEY; ret = btrfs_insert_empty_item(trans, root, path, &key, sizeof(*extent)); - BUG_ON(ret); + if (ret < 0) + goto err; leaf = path->nodes[0]; extent = btrfs_item_ptr(leaf, path->slots[0], From patchwork Fri Aug 3 05:50:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10554585 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3B0A15A6 for ; Fri, 3 Aug 2018 05:50:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA2B12C356 for ; Fri, 3 Aug 2018 05:50:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE88D2C385; Fri, 3 Aug 2018 05:50:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6868C2C356 for ; Fri, 3 Aug 2018 05:50:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727653AbeHCHpQ (ORCPT ); Fri, 3 Aug 2018 03:45:16 -0400 Received: from mx2.suse.de ([195.135.220.15]:41544 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726799AbeHCHpQ (ORCPT ); Fri, 3 Aug 2018 03:45:16 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A4440AF76 for ; Fri, 3 Aug 2018 05:50:36 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 6/6] btrfs-progs: rescue-super: Don't double free fs_devices Date: Fri, 3 Aug 2018 13:50:22 +0800 Message-Id: <20180803055022.9816-7-wqu@suse.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180803055022.9816-1-wqu@suse.com> References: <20180803055022.9816-1-wqu@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP [BUG] During fuzz/007 we hit the following error: ------ ====== RUN MAYFAIL /home/adam/btrfs/btrfs-progs/btrfs rescue super-recover -y -v /home/adam/btrfs/btrfs-progs/tests//fuzz-tests/images/bko-200409.raw.restored.scratch ERROR: tree_root block unaligned: 33554431 ERROR: superblock checksum matches but it has invalid members ERROR: tree_root block unaligned: 33554431 ERROR: superblock checksum matches but it has invalid members ERROR: tree_root block unaligned: 33554431 ERROR: superblock checksum matches but it has invalid members ERROR: failed to add chunk map start=12582912 len=8454144: -17 (File exists) Couldn't read chunk tree failed (ignored, ret=139): /home/adam/btrfs/btrfs-progs/btrfs rescue super-recover -y -v /home/adam/btrfs/btrfs-progs/tests//fuzz-tests/images/bko-200409.raw.restored.scratch mayfail: returned code 139 (SEGFAULT), not ignored test failed for case 007-simple-super-recover ------ [CAUSE] In __open_ctree_fd(), if we have valid @open_ctree_flags and btrfs_scan_fs_devices() successes without problem, no matter what happens we will call btrfs_close_devices(), thus free all related devices. In super-recover, before we call open_ctree(), we have called btrfs_scan_fs_devices() already, so btrfs_scan_fs_devices() should not fail in open_ctree(), fs_devices will always be freed in open_ctree() or close_ctree(). [FIX] So in super-recover.c, we should not call btrfs_close_devices(), or we will find fs_devices->list get poisoned, and trigger segfault when exiting. Signed-off-by: Qu Wenruo --- super-recover.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/super-recover.c b/super-recover.c index 880fd7712546..86b3df9867dc 100644 --- a/super-recover.c +++ b/super-recover.c @@ -292,9 +292,6 @@ int btrfs_recover_superblocks(const char *dname, no_recover: recover_err_str(ret); free_recover_superblock(&recover); - /* check if we have freed fs_devices in close_ctree() */ - if (!root) - btrfs_close_devices(recover.fs_devices); return ret; }