From patchwork Fri Apr 29 07:18:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 8977851 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6451EBF29F for ; Fri, 29 Apr 2016 07:20:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 810862024C for ; Fri, 29 Apr 2016 07:20:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9341220220 for ; Fri, 29 Apr 2016 07:20:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752693AbcD2HUK (ORCPT ); Fri, 29 Apr 2016 03:20:10 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:12940 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752654AbcD2HUI (ORCPT ); Fri, 29 Apr 2016 03:20:08 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="462502" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 29 Apr 2016 15:19:19 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id F3C504043CEF; Fri, 29 Apr 2016 15:19:14 +0800 (CST) From: Qu Wenruo To: jbacik@fb.com, linux-btrfs@vger.kernel.org Cc: Lu Fengqi Subject: [PATCH RFC v2 05/16] btrfs-progs: fsck: Introduce function to check shared block ref Date: Fri, 29 Apr 2016 15:18:59 +0800 Message-Id: <1461914350-19875-6-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1461914350-19875-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1461914350-19875-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: F3C504043CEF.ADB55 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lu Fengqi Introduce function check_shared_block_backref() to check shared block ref. Signed-off-by: Lu Fengqi Signed-off-by: Qu Wenruo --- cmds-check.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index fae4c26..de3c2e1 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -8889,6 +8889,48 @@ out: return err; } +/* + * Check referencer for shared block backref + * If level == -1, this function will resolve the level. + */ +static int check_shared_block_backref(struct btrfs_fs_info *fs_info, + u64 parent, u64 bytenr, int level) +{ + struct extent_buffer *eb; + u32 nodesize = btrfs_super_nodesize(fs_info->super_copy); + u32 nr; + int found_parent = 0; + int i; + + eb = read_tree_block_fs_info(fs_info, parent, nodesize, 0); + if (!extent_buffer_uptodate(eb)) + goto out; + + if (level == -1) + level = query_tree_block_level(fs_info, bytenr); + if (level < 0) + goto out; + + if (level + 1 != btrfs_header_level(eb)) + goto out; + + nr = btrfs_header_nritems(eb); + for (i = 0; i < nr; i++) { + if (bytenr == btrfs_node_blockptr(eb, i)) { + found_parent = 1; + break; + } + } +out: + free_extent_buffer(eb); + if (!found_parent) { + error("Shared extent[%llu %u] lost its parent(parent: %llu, level: %u)", + bytenr, nodesize, parent, level); + return REFERENCER_MISSING; + } + return 0; +} + static int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, int overwrite) {