From patchwork Wed Aug 23 02:33:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Fengqi X-Patchwork-Id: 9916491 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 4859B603F9 for ; Wed, 23 Aug 2017 02:34:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34E1928521 for ; Wed, 23 Aug 2017 02:34:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29C8228547; Wed, 23 Aug 2017 02:34:34 +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 CE91C28521 for ; Wed, 23 Aug 2017 02:34:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753266AbdHWCeb (ORCPT ); Tue, 22 Aug 2017 22:34:31 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:47372 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753057AbdHWCeB (ORCPT ); Tue, 22 Aug 2017 22:34:01 -0400 X-IronPort-AV: E=Sophos;i="5.41,415,1498492800"; d="scan'208";a="24527021" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Aug 2017 10:34:00 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 5993D472278F for ; Wed, 23 Aug 2017 10:34:02 +0800 (CST) Received: from localhost.localdomain (10.167.226.155) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 23 Aug 2017 10:34:00 +0800 From: Lu Fengqi To: CC: Su Yue Subject: [PATCH 4/6] btrfs-progs: check: Introduce repair_chunk_item() Date: Wed, 23 Aug 2017 10:33:48 +0800 Message-ID: <20170823023350.2940-5-lufq.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170823023350.2940-1-lufq.fnst@cn.fujitsu.com> References: <20170823023350.2940-1-lufq.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.155] X-yoursite-MailScanner-ID: 5993D472278F.AAA19 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 From: Su Yue Because this patchset concentrates on repair of extent tree, repair_chunk_item() now only inserts missed chunk group item into extent tree. There are some things left TODO, for example dev_item. Signed-off-by: Su Yue --- cmds-check.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index 0f26394..726e330 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -11543,6 +11543,50 @@ out: } /* + * Add block group item to the extent tree if @err contains + * REFERENCER_MISSING. + * TO DO: repair error about dev_item. + * + * Returns error after repair. + */ +static int repair_chunk_item(struct btrfs_trans_handle *trans, + struct btrfs_root *chunk_root, + struct btrfs_path *path, int err) +{ + struct btrfs_chunk *chunk; + struct btrfs_key chunk_key; + struct extent_buffer *eb = path->nodes[0]; + u64 length; + int slot = path->slots[0]; + u64 type; + int ret = 0; + + btrfs_item_key_to_cpu(eb, &chunk_key, slot); + if (chunk_key.type != BTRFS_CHUNK_ITEM_KEY) + return err; + chunk = btrfs_item_ptr(eb, slot, struct btrfs_chunk); + type = btrfs_chunk_type(path->nodes[0], chunk); + length = btrfs_chunk_length(eb, chunk); + + if (err & REFERENCER_MISSING) { + ret = btrfs_make_block_group(trans, chunk_root->fs_info, 0, + type, chunk_key.objectid, chunk_key.offset, length); + if (ret) { + error("fail to add block group item[%llu %llu]", + chunk_key.offset, length); + goto out; + } else { + err &= ~REFERENCER_MISSING; + printf("Added block group item[%llu %llu]\n", + chunk_key.offset, length); + } + } + +out: + return err; +} + +/* * Check a chunk item. * Including checking all referred dev_extents and block group */ @@ -11729,6 +11773,8 @@ again: break; case BTRFS_CHUNK_ITEM_KEY: ret = check_chunk_item(fs_info, eb, slot); + if (repair && ret) + ret = repair_chunk_item(trans, root, path, ret); err |= ret; break; case BTRFS_DEV_EXTENT_KEY: