From patchwork Thu Jul 28 07:08:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Fengqi X-Patchwork-Id: 9250759 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 13E0860869 for ; Thu, 28 Jul 2016 07:09:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04B1D2094D for ; Thu, 28 Jul 2016 07:09:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDC0626D06; Thu, 28 Jul 2016 07:09: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 6C7A32094D for ; Thu, 28 Jul 2016 07:09:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163683AbcG1HJ3 (ORCPT ); Thu, 28 Jul 2016 03:09:29 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:44034 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1163652AbcG1HJM (ORCPT ); Thu, 28 Jul 2016 03:09:12 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="9211868" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 28 Jul 2016 15:08:52 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 4CC1742BA383 for ; Thu, 28 Jul 2016 15:08:50 +0800 (CST) Received: from luke.localdomain (10.167.226.118) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.279.2; Thu, 28 Jul 2016 15:08:49 +0800 From: Lu Fengqi To: CC: Lu Fengqi , Qu Wenruo Subject: [PATCH 09/13] btrfs-progs: check: introduce function to check fs root Date: Thu, 28 Jul 2016 15:08:21 +0800 Message-ID: <1469689705-26836-10-git-send-email-lufq.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1469689705-26836-1-git-send-email-lufq.fnst@cn.fujitsu.com> References: <1469689705-26836-1-git-send-email-lufq.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.118] X-yoursite-MailScanner-ID: 4CC1742BA383.AC0FA X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: lufq.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 a new function check_fs_root_v2() to check fs root, and call check_inode_item to check the items in the tree. Signed-off-by: Lu Fengqi Signed-off-by: Qu Wenruo --- cmds-check.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index a9a5c08..756e7a1 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -3892,6 +3892,7 @@ out: #define NBYTES_ERROR (1<<11) /* INODE_ITEM nbytes count error */ #define ISIZE_ERROR (1<<12) /* INODE_ITEM size count error */ #define ORPHAN_ITEM (1<<13) /* INODE_ITEM no reference */ +#define NO_INODE_ITEM (1<<14) /* no inode_item */ #define LAST_ITEM (1<<15) /* Complete this tree traversal */ /* @@ -4725,6 +4726,81 @@ out: return err; } +/* + * Iterate all item on the tree and call check_inode_item() to check. + * + * @root: the root of the tree to be checked. + * @ext_ref: the EXTENDED_IREF feature + * + * Return 0 if no error found. + */ +static int check_fs_root_v2(struct btrfs_root *root, unsigned int ext_ref) +{ + struct btrfs_path *path; + struct btrfs_key key; + u64 inode_id; + int ret, err = 0; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + key.objectid = 0; + key.type = 0; + key.offset = 0; + + ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); + if (ret < 0) { + err = ret; + goto out; + } + + while (1) { + btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); + + /* + * All check must start with inode item, skip if not + */ + if (btrfs_key_type(&key) == BTRFS_INODE_ITEM_KEY) { + ret = check_inode_item(root, path, ext_ref); + if (ret == -EIO) + goto out; + err |= ret; + if (err & LAST_ITEM) + goto out; + } else { + error( + "root %llu ITEM[%llu %u %llu] isn't INODE_ITEM, skip to next inode", + root->objectid, key.objectid, key.type, key.offset); + goto skip; + } + + continue; + +skip: + err |= NO_INODE_ITEM; + inode_id = key.objectid; + + /* skip to next inode */ + do { + ret = btrfs_next_item(root, path); + if (ret > 0) { + goto out; + } else if (ret < 0) { + err = ret; + goto out; + } + btrfs_item_key_to_cpu(path->nodes[0], &key, + path->slots[0]); + } while (inode_id == key.objectid); + } + +out: + err &= ~LAST_ITEM; + btrfs_free_path(path); + return err; +} + static int all_backpointers_checked(struct extent_record *rec, int print_errs) { struct rb_node *n;