From patchwork Mon Feb 5 06:47:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10199909 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 3CDB060247 for ; Mon, 5 Feb 2018 06:47:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AAAD28450 for ; Mon, 5 Feb 2018 06:47:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C15828459; Mon, 5 Feb 2018 06:47: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=-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 857AB28450 for ; Mon, 5 Feb 2018 06:47:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752031AbeBEGrV (ORCPT ); Mon, 5 Feb 2018 01:47:21 -0500 Received: from victor.provo.novell.com ([137.65.250.26]:45678 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750943AbeBEGrU (ORCPT ); Mon, 5 Feb 2018 01:47:20 -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); Sun, 04 Feb 2018 23:47:18 -0700 From: Qu Wenruo To: linux-btrfs@vger.kernel.org, dsterba@suse.cz Subject: [PATCH 1/4] btrfs-progs: mode-lowmem: Fix false alert about orphan inode Date: Mon, 5 Feb 2018 14:47:11 +0800 Message-Id: <20180205064714.15659-1-wqu@suse.com> X-Mailer: git-send-email 2.16.1 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 can delay inode deletion and in that case btrfs will unlink the victim inode from its parent dir, and insert a marker to info btrfs to delete it later. In that case, such victim inode will have nlinks == 0, but is still completely valid. Original mode won't report such problem, but lowmem mode doesn't check the ORPHAN_ITEM key for such inode, and can report false alert like: ------ ERROR: root 257 INODE[28891726] is orphan item ------ Fix such false alert by checking orphan item for inode whose nlink is 0. Signed-off-by: Qu Wenruo Reviewed-by: Su Yue --- check/mode-lowmem.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c index 62bcf3d2e126..b11a6d77d102 100644 --- a/check/mode-lowmem.c +++ b/check/mode-lowmem.c @@ -1861,6 +1861,24 @@ out: return ret; } +static bool has_orphan_item(struct btrfs_root *root, u64 ino) +{ + struct btrfs_path path; + struct btrfs_key key; + int ret; + + btrfs_init_path(&path); + key.objectid = BTRFS_ORPHAN_OBJECTID; + key.type = BTRFS_ORPHAN_ITEM_KEY; + key.offset = ino; + + ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); + btrfs_release_path(&path); + if (ret == 0) + return true; + return false; +} + /* * Check INODE_ITEM and related ITEMs (the same inode number) * 1. check link count @@ -1890,6 +1908,7 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path, u64 extent_size = 0; unsigned int dir; unsigned int nodatasum; + bool is_orphan = false; int slot; int ret; int err = 0; @@ -2040,10 +2059,11 @@ out: root->objectid, inode_id, nlink, refs); } } else if (!nlink) { - if (repair) + is_orphan = has_orphan_item(root, inode_id); + if (!is_orphan && repair) ret = repair_inode_orphan_item_lowmem(root, path, inode_id); - if (!repair || ret) { + if (!is_orphan && (!repair || ret)) { err |= ORPHAN_ITEM; error("root %llu INODE[%llu] is orphan item", root->objectid, inode_id);