From patchwork Fri Jan 29 05:03:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 8159041 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0768B9F9A0 for ; Fri, 29 Jan 2016 05:18:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3B05D2035D for ; Fri, 29 Jan 2016 05:18:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6A95C20351 for ; Fri, 29 Jan 2016 05:18:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752393AbcA2FSA (ORCPT ); Fri, 29 Jan 2016 00:18:00 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:31409 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751116AbcA2FR7 (ORCPT ); Fri, 29 Jan 2016 00:17:59 -0500 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="304668" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 29 Jan 2016 13:05:46 +0800 Received: from localhost.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id EF8AA405640B; Fri, 29 Jan 2016 13:05:33 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, David Sterba Subject: [PATCH v3 10/22] btrfs-progs: Introduce function to initialize csum tree Date: Fri, 29 Jan 2016 13:03:20 +0800 Message-Id: <1454043812-7893-11-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1454043812-7893-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1454043812-7893-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: EF8AA405640B.AEB0A 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, 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 Signed-off-by: David Sterba --- utils.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/utils.c b/utils.c index 54085b0..51daad9 100644 --- a/utils.c +++ b/utils.c @@ -676,6 +676,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(). * @@ -775,6 +797,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;