From patchwork Tue Dec 1 07:11:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 7733271 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 B645E9F39D for ; Tue, 1 Dec 2015 07:14:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DAC4A2063E for ; Tue, 1 Dec 2015 07:14:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1A3B52045A for ; Tue, 1 Dec 2015 07:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755198AbbLAHO2 (ORCPT ); Tue, 1 Dec 2015 02:14:28 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:25708 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1755111AbbLAHO1 (ORCPT ); Tue, 1 Dec 2015 02:14:27 -0500 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="1025421" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by heian.cn.fujitsu.com with ESMTP; 01 Dec 2015 15:14:16 +0800 Received: from localhost.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 8B76440444D6 for ; Tue, 1 Dec 2015 15:14:07 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 12/25] btrfs-progs: Introduce function to initialize fs tree Date: Tue, 1 Dec 2015 15:11:32 +0800 Message-Id: <1448953905-28673-13-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: 8B76440444D6.ABBE7 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 Introudce new function, setup_temp_fs_tree(), to setup temporary fs tree for make_btrfs_v2(). Signed-off-by: Qu Wenruo --- utils.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/utils.c b/utils.c index 4861caa..3251e18 100644 --- a/utils.c +++ b/utils.c @@ -652,6 +652,28 @@ out: return ret; } +static int setup_temp_fs_tree(int fd, struct btrfs_mkfs_config *cfg, + u64 fs_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, fs_bytenr, + BTRFS_FS_TREE_OBJECTID); + if (ret < 0) + goto out; + /* + * Temporary fs tree is completely empty. + */ + ret = write_temp_extent_buffer(fd, buf, fs_bytenr); +out: + free(buf); + return ret; +} + /* * Improved version of make_btrfs(). * @@ -748,6 +770,10 @@ static int make_convert_btrfs(int fd, struct btrfs_mkfs_config *cfg, goto out; ret = setup_temp_dev_tree(fd, cfg, sys_chunk_start, meta_chunk_start, dev_bytenr); + if (ret < 0) + goto out; + ret = setup_temp_fs_tree(fd, cfg, fs_bytenr); + out: return ret; }