From patchwork Wed Nov 22 09:03: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: 10069947 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 C97AA60375 for ; Wed, 22 Nov 2017 09:04:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE43429B94 for ; Wed, 22 Nov 2017 09:04:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B340529BFA; Wed, 22 Nov 2017 09:04:37 +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=-6.9 required=2.0 tests=BAYES_00,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 4752529B94 for ; Wed, 22 Nov 2017 09:04:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751899AbdKVJEL (ORCPT ); Wed, 22 Nov 2017 04:04:11 -0500 Received: from prv3-mh.provo.novell.com ([137.65.250.26]:49689 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751882AbdKVJED (ORCPT ); Wed, 22 Nov 2017 04:04:03 -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); Wed, 22 Nov 2017 02:03:58 -0700 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH 06/11] btrfs-progs: backref: Allow backref walk to handle direct parent ref Date: Wed, 22 Nov 2017 17:03:20 +0800 Message-Id: <20171122090325.29458-7-wqu@suse.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171122090325.29458-1-wqu@suse.com> References: <20171122090325.29458-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] Btrfs lowmem mode fails with the following ASSERT() on certain valid image. ------ backref.c:466: __add_missing_keys: Assertion `ref->root_id` failed, value 0 ------ [REASON] Lowmem mode uses btrfs_find_all_roots() when walking down fs trees. However if a tree block with only shared parent backref like below, backref code from btrfs-progs doesn't handle it correct. ------ item 72 key (604653731840 METADATA_ITEM 0) itemoff 13379 itemsize 60 refs 4 gen 7198 flags TREE_BLOCK|FULL_BACKREF tree block skinny level 0 shared block backref parent 604498477056 shared block backref parent 604498460672 shared block backref parent 604498444288 shared block backref parent 604498411520 ------ Such shared block ref is *direct* ref, which means we don't need to solve its key, nor its rootid. As the objective of backref walk is to find all direct parents until it reaches tree root. So for such direct ref, it should be pended to pref_stat->pending, other than pending it to pref_stat->pending_missing_key. [FIX] For direct ref, pending it to pref_state->pending directly to solve the problem. Reported-by: Chris Murphy Signed-off-by: Qu Wenruo --- backref.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backref.c b/backref.c index 8615f6b8677a..27309e07a1e9 100644 --- a/backref.c +++ b/backref.c @@ -206,6 +206,9 @@ static int __add_prelim_ref(struct pref_state *prefstate, u64 root_id, if (key) { ref->key_for_search = *key; head = &prefstate->pending; + } else if (parent) { + memset(&ref->key_for_search, 0, sizeof(ref->key_for_search)); + head = &prefstate->pending; } else { memset(&ref->key_for_search, 0, sizeof(ref->key_for_search)); head = &prefstate->pending_missing_keys;