From patchwork Tue Dec 1 07:11:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 7733291 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 9D259BEEE1 for ; Tue, 1 Dec 2015 07:14:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C7A182063E for ; Tue, 1 Dec 2015 07:14:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F3EE72045A for ; Tue, 1 Dec 2015 07:14:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755249AbbLAHOc (ORCPT ); Tue, 1 Dec 2015 02:14:32 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:27701 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1755218AbbLAHOa (ORCPT ); Tue, 1 Dec 2015 02:14:30 -0500 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="1025422" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by heian.cn.fujitsu.com with ESMTP; 01 Dec 2015 15:14:18 +0800 Received: from localhost.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 8800640444C7 for ; Tue, 1 Dec 2015 15:14:08 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 13/25] btrfs-progs: Introduce function to initialize csum tree Date: Tue, 1 Dec 2015 15:11:33 +0800 Message-Id: <1448953905-28673-14-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1448953905-28673-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1448953905-28673-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-Information: Please contact the ISP for more information X-yoursite-MailScanner-ID: 8800640444C7.ABA08 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com 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 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 Introduce new function, setup_temp_csum_tree(), to setup temporary csum tree for make_btrfs_v2(). Signed-off-by: Qu Wenruo --- utils.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/utils.c b/utils.c index 3251e18..43bc6cf 100644 --- a/utils.c +++ b/utils.c @@ -674,6 +674,28 @@ out: return ret; } +static int setup_temp_csum_tree(int fd, struct btrfs_mkfs_config *cfg, + u64 csum_bytenr) +{ + struct extent_buffer *buf = NULL; + int ret; + + buf = malloc(sizeof(*buf) + cfg->nodesize); + if (!buf) + return -ENOMEM; + ret = setup_temp_extent_buffer(buf, cfg, csum_bytenr, + BTRFS_CSUM_TREE_OBJECTID); + if (ret < 0) + goto out; + /* + * Temporary csum tree is completely empty. + */ + ret = write_temp_extent_buffer(fd, buf, csum_bytenr); +out: + free(buf); + return ret; +} + /* * Improved version of make_btrfs(). * @@ -773,6 +795,9 @@ static int make_convert_btrfs(int fd, struct btrfs_mkfs_config *cfg, if (ret < 0) goto out; ret = setup_temp_fs_tree(fd, cfg, fs_bytenr); + if (ret < 0) + goto out; + ret = setup_temp_csum_tree(fd, cfg, csum_bytenr); out: return ret;