From patchwork Wed Sep 12 19:20:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 10597389 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 C3B6F14E5 for ; Wed, 12 Sep 2018 11:21:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B10E429BB2 for ; Wed, 12 Sep 2018 11:21:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A584329BB7; Wed, 12 Sep 2018 11:21:23 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 5188D29BB9 for ; Wed, 12 Sep 2018 11:21:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726912AbeILQZ1 (ORCPT ); Wed, 12 Sep 2018 12:25:27 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36624 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726082AbeILQZ1 (ORCPT ); Wed, 12 Sep 2018 12:25:27 -0400 Received: by mail-pg1-f196.google.com with SMTP id d1-v6so907948pgo.3 for ; Wed, 12 Sep 2018 04:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2lgbWTPOvhCAsaKaygFcTZYRMWFYqV5/XIukbiosfa0=; b=J19mP0336IX8vADwrJZFdtqLm2sSUykn2f8POVftshlOfizHZsNHLO0zX8F2rnDiJ+ rcpKFrTUv17jBKRJH1z7Se79CFJgLqoq/npVJnoPrnU6BWMs6kAMTku/x2lhiuGoFjo+ udjmAp0tnlgAZhRmZvHg2+2TeUpk08ai9ga4ulfcuxsUQQ6YVEH1DwEWcxiJ2DvZPmex 6NXmzr+0SJ3O4KZzPgr9c9HyL4fZUx1IKhbQGJH0+lmurJanD4nJkaCVOXlwUpfd6vP0 GY4UIuAPm9q94hVdlcJmzHiVhK61tiCBfa+AvqW8cUDd5tOpfXWOdYjGp9RUyw/tmJpH nysQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2lgbWTPOvhCAsaKaygFcTZYRMWFYqV5/XIukbiosfa0=; b=Y35w7FAluds2tW3FARpz4dB9gYeVvzqup7isXzqrpUwHn9r+wdhM7uRC1qd6rr7PDy GVJ8GMFUA/wNxkqVXXrBpy4cy3BSaT5i9DLLv6YhHl/E77oE2IiPkDA2tsumwEMjubKb iYd83Ivtfzqtg8vj29JDZecgEi0hBqi/blv7iT+P4iernd6uDNC9Ci3+FRbqh0f13Nff 7As5iwTMpIV9yqk/4g0WoN4kKNJHugocDKwuWG61nkGpmqvgjupxZnZvQtSDW7tiYzRn 6yzu/hIt+yUP40cPdAqBqmMLHmrCRPqKxO/C1+oMbuZKNKlSmxXxI/GPUqUgfjV847ap InBQ== X-Gm-Message-State: APzg51AIqS0j+SF2+NzEuvUjjtHEBNpcdZopCP0m+tL+p3NblIRWsHNu 1z6ETXx0KuhaO0nQGQ6K5KjJG+9S X-Google-Smtp-Source: ANB0VdaUrZVjXTZJae2rblOlp21tw2qr1Xq1yHpj+EENSilc54lJTdUoAJM6Vra99xHe194kfWk7gg== X-Received: by 2002:a65:448a:: with SMTP id l10-v6mr1711386pgq.382.1536751281194; Wed, 12 Sep 2018 04:21:21 -0700 (PDT) Received: from cat-arch.lan (li1862-137.members.linode.com. [172.105.208.137]) by smtp.gmail.com with ESMTPSA id h12-v6sm1267826pfo.135.2018.09.12.04.21.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 04:21:20 -0700 (PDT) From: damenly.su@gmail.com X-Google-Original-From: suy.fnst@cn.fujitsu.com To: linux-btrfs@vger.kernel.org Cc: suy.fnst@cn.fujitsu.com Subject: [PATCH 4/6] btrfs-progs: lowmem: search key of root again after check_fs_root() under repair Date: Wed, 12 Sep 2018 19:20:41 +0000 Message-Id: <20180912192046.5861-5-suy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180912192046.5861-1-suy.fnst@cn.fujitsu.com> References: <20180912192046.5861-1-suy.fnst@cn.fujitsu.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 From: Su Yue In check_fs_roots_lowmem(), we do search and follow the resulted path to call check_fs_root(), then call btrfs_next_item() to check next root. However, if repair is enabled, the root tree can be cowed, the existed path can cause strange errors. Solution: If repair, save the key before calling check_fs_root, search the saved key again before checking next root. Signed-off-by: Su Yue --- check/mode-lowmem.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c index 89a304bbdd69..8fc9edab1d66 100644 --- a/check/mode-lowmem.c +++ b/check/mode-lowmem.c @@ -4967,9 +4967,13 @@ int check_fs_roots_lowmem(struct btrfs_fs_info *fs_info) } while (1) { + struct btrfs_key saved_key; + node = path.nodes[0]; slot = path.slots[0]; btrfs_item_key_to_cpu(node, &key, slot); + if (repair) + saved_key = key; if (key.objectid > BTRFS_LAST_FREE_OBJECTID) goto out; if (key.type == BTRFS_ROOT_ITEM_KEY && @@ -5000,6 +5004,17 @@ int check_fs_roots_lowmem(struct btrfs_fs_info *fs_info) err |= ret; } next: + /* + * Since root tree can be cowed during repair, + * here search the saved key again. + */ + if (repair) { + btrfs_release_path(&path); + ret = btrfs_search_slot(NULL, fs_info->tree_root, + &saved_key, &path, 0, 0); + /* Repair never deletes trees, search must succeed. */ + BUG_ON(ret); + } ret = btrfs_next_item(tree_root, &path); if (ret > 0) goto out;