From patchwork Wed Mar 1 03:13:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 9597381 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 08C2C60414 for ; Wed, 1 Mar 2017 03:25:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0EDD27F95 for ; Wed, 1 Mar 2017 03:25:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E5FD92818B; Wed, 1 Mar 2017 03:25:40 +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 9639927F95 for ; Wed, 1 Mar 2017 03:25:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751809AbdCADZj (ORCPT ); Tue, 28 Feb 2017 22:25:39 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:21599 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751800AbdCADZi (ORCPT ); Tue, 28 Feb 2017 22:25:38 -0500 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="16081008" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 01 Mar 2017 11:13:18 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id AA2E347D8B81 for ; Wed, 1 Mar 2017 11:13:17 +0800 (CST) Received: from localhost.localdomain (10.167.226.129) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 1 Mar 2017 11:13:17 +0800 From: Su Yue To: CC: Subject: [PATCH 13/20] btrfs-progs: cmds-check.c: repair_inode_item_missing Date: Wed, 1 Mar 2017 11:13:56 +0800 Message-ID: <20170301031403.23902-14-suy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170301031403.23902-1-suy.fnst@cn.fujitsu.com> References: <20170301031403.23902-1-suy.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.129] X-yoursite-MailScanner-ID: AA2E347D8B81.ADD3E X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: 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 Introduce 'repair_inode_item_missing' to fix INODE_ITEM_MISSING This patch is for further repair. Signed-off-by: Su Yue --- cmds-check.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index 256bfbc9..6dafbd7d 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -5463,6 +5463,49 @@ out: } /* + * Insert the missing inode item. + * + * Returns 0 means success. + * Returns <0 means error. + */ +static int repair_inode_item_missing(struct btrfs_root *root, u64 ino, + u8 filetype, int err) +{ + struct btrfs_key key; + struct btrfs_trans_handle *trans; + struct btrfs_path path; + int ret; + + if (!err) + return 0; + + key.objectid = ino; + key.type = BTRFS_INODE_ITEM_KEY; + key.offset = 0; + + btrfs_init_path(&path); + trans = btrfs_start_transaction(root, 1); + if (IS_ERR(trans)) { + ret = -EIO; + goto out; + } + + ret = btrfs_search_slot(trans, root, &key, &path, 1, 1); + if (ret < 0 || !ret) + goto out; + /* insert inode item */ + create_inode_item_lowmem(trans, root, ino, filetype); + ret = 0; + btrfs_commit_transaction(trans, root); +out: + if (ret) + error("Failed to repair root %llu INODE ITEM[%llu] missing", + root->objectid, ino); + btrfs_release_path(&path); + return ret; +} + +/* * check first root dir's inode_item, inde_ref * * returns 0 means no error