From patchwork Tue Dec 23 01:29:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 5529521 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 38FA1BEEA8 for ; Tue, 23 Dec 2014 01:29:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5483E2017D for ; Tue, 23 Dec 2014 01:29:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 426CE200FF for ; Tue, 23 Dec 2014 01:29:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753607AbaLWB3w (ORCPT ); Mon, 22 Dec 2014 20:29:52 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:40519 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753380AbaLWB3w (ORCPT ); Mon, 22 Dec 2014 20:29:52 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="45638135" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Dec 2014 09:26:29 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id sBN1TN1E032074 for ; Tue, 23 Dec 2014 09:29:23 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 23 Dec 2014 09:29:53 +0800 From: Qu Wenruo To: Subject: [PATCH] btrfs-progs: Fix a bug in reset_nlink() which may deletes the recovered file Date: Tue, 23 Dec 2014 09:29:44 +0800 Message-ID: <1419298184-8540-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.2.1 MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In reset_nlink(), we believe rec->found_link as accurate number of the valid links. However it only records the number of found DIR_ITEM, so we can't use it as reliable value. Before this patch, in some case, leaf corruption recovery will believe there is a valid backref but don't add_link() since it can't find any valid one and don't put it into the lost+found dir. So the recovered inode will be considered as an orphan item without orphan item and repair_inode_orphan_item() will add orphan item for it, causing all the filename/filetype we recovered being a waste of time. Signed-off-by: Qu Wenruo --- cmds-check.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmds-check.c b/cmds-check.c index aa47984..1bb95dc 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -1959,6 +1959,9 @@ static int reset_nlink(struct btrfs_trans_handle *trans, struct btrfs_inode_item *inode_item; int ret = 0; + /* We don't believe this either, reset it and iterate backref */ + rec->found_link = 0; + /* Remove all backref including the valid ones */ list_for_each_entry_safe(backref, tmp, &rec->backrefs, list) { ret = btrfs_unlink(trans, root, rec->ino, backref->dir, @@ -1973,7 +1976,8 @@ static int reset_nlink(struct btrfs_trans_handle *trans, backref->found_inode_ref)) { list_del(&backref->list); free(backref); - } + } else + rec->found_link++; } /* Set nlink to 0 */