From patchwork Tue Nov 14 07:55:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10057105 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1535D602A7 for ; Tue, 14 Nov 2017 07:55:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07C8E29018 for ; Tue, 14 Nov 2017 07:55:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0C4A29016; Tue, 14 Nov 2017 07:55:47 +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=-5.9 required=2.0 tests=BAYES_00,HEXHASH_WORD, 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 5736429014 for ; Tue, 14 Nov 2017 07:55:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753323AbdKNHzp (ORCPT ); Tue, 14 Nov 2017 02:55:45 -0500 Received: from victor.provo.novell.com ([137.65.250.26]:49352 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751872AbdKNHzn (ORCPT ); Tue, 14 Nov 2017 02:55:43 -0500 Received: from adam-pc.lan (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (NOT encrypted); Tue, 14 Nov 2017 00:55:28 -0700 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, chris@colorremedies.com Subject: [PATCH 1/2] btrfs-progs: lowmem check: Fix false alerts of referencer count mismatch for snapshot Date: Tue, 14 Nov 2017 15:55:20 +0800 Message-Id: <20171114075521.24736-1-wqu@suse.com> X-Mailer: git-send-email 2.15.0 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 Btrfs lowmem check reports such false alerts: ------ ERROR: extent[366498091008, 134217728] referencer count mismatch (root: 827, owner: 73782, offset: 134217728) wanted: 4, have: 26 ERROR: extent[366498091008, 134217728] referencer count mismatch (root: 818, owner: 73782, offset: 134217728) wanted: 4, have: 26 ERROR: extent[366498091008, 134217728] referencer count mismatch (root: 870, owner: 73782, offset: 134217728) wanted: 4, have: 26 ------ While in extent tree, the extent has: ------ item 81 key (366498091008 EXTENT_ITEM 134217728) itemoff 9008 itemsize 169 refs 39 gen 224 flags DATA extent data backref root 827 objectid 73782 offset 134217728 count 4 extent data backref root 818 objectid 73782 offset 134217728 count 4 extent data backref root 259 objectid 73482 offset 134217728 count 1 extent data backref root 644 objectid 73782 offset 134217728 count 26 extent data backref root 870 objectid 73782 offset 134217728 count 4 ------ And in root 827, there is one leaf with 4 references to that extent which is owned by 827: ------ leaf 714964992 items 68 free space 10019 generation 641 owner 827 leaf 714964992 flags 0x1(WRITTEN) backref revision 1 ...... item 64 key (73782 EXTENT_DATA 134217728) itemoff 11878 itemsize 53 generation 224 type 1 (regular) extent data disk byte 366498091008 nr 134217728 extent data offset 0 nr 6410240 ram 134217728 extent compression 0 (none) item 65 key (73782 EXTENT_DATA 140627968) itemoff 11825 itemsize 53 generation 224 type 1 (regular) extent data disk byte 366498091008 nr 134217728 extent data offset 6410240 nr 5120000 ram 134217728 extent compression 0 (none) item 66 key (73782 EXTENT_DATA 145747968) itemoff 11772 itemsize 53 generation 224 type 1 (regular) extent data disk byte 366498091008 nr 134217728 extent data offset 11530240 nr 7675904 ram 134217728 extent compression 0 (none) item 67 key (73782 EXTENT_DATA 153423872) itemoff 11719 itemsize 53 generation 224 type 1 (regular) extent data disk byte 366498091008 nr 134217728 extent data offset 19206144 nr 6397952 ram 134217728 extent compression 0 (none) ------ And starts from next leaf, there are 22 references to the data extent: ------ leaf 894861312 items 208 free space 59 generation 261 owner 644 leaf 894861312 flags 0x1(WRITTEN) backref revision 1 item 0 key (73782 EXTENT_DATA 159821824) itemoff 16230 itemsize 53 generation 224 type 1 (regular) extent data disk byte 366498091008 nr 134217728 extent data offset 25604096 nr 8192 ram 134217728 extent compression 0 (none) item 1 key (73782 EXTENT_DATA 159830016) itemoff 16177 itemsize 53 generation 224 type 1 (regular) extent data disk byte 366498091008 nr 134217728 extent data offset 25612288 nr 7675904 ram 134217728 extent compression 0 (none) ...... ------ However the next leaf is owned by other subvolume, normally owned by (part of) the snapshot source. Fix it by also checking the leaf's owner before increasing the reference counter. Reported-by: Chris Murphy Signed-off-by: Qu Wenruo Signed-off-by: Qu Wenruo --- cmds-check.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmds-check.c b/cmds-check.c index 4805e11b752b..d782567c77ee 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -10909,11 +10909,17 @@ static int check_extent_data_backref(struct btrfs_fs_info *fs_info, * Except normal disk bytenr and disk num bytes, we still * need to do extra check on dbackref offset as * dbackref offset = file_offset - file_extent_offset + * + * Also, we must check the leaf owner. + * In case of shared tree blocks (snapshots) we can inherit + * leaves from source snapshot. + * In that case, reference from source snapshot should not + * count. */ if (btrfs_file_extent_disk_bytenr(leaf, fi) == bytenr && btrfs_file_extent_disk_num_bytes(leaf, fi) == len && (u64)(key.offset - btrfs_file_extent_offset(leaf, fi)) == - offset) + offset && btrfs_header_owner(leaf) == root_id) found_count++; next: