From patchwork Fri Jan 29 05:03:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 8158911 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 E0C499F9A0 for ; Fri, 29 Jan 2016 05:16:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1C5452035E for ; Fri, 29 Jan 2016 05:16:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 45039200DE for ; Fri, 29 Jan 2016 05:16:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751916AbcA2FQn (ORCPT ); Fri, 29 Jan 2016 00:16:43 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:34115 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751867AbcA2FQm (ORCPT ); Fri, 29 Jan 2016 00:16:42 -0500 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="304658" 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 CD52B405640A; 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 09/22] btrfs-progs: Introduce function to initialize fs tree Date: Fri, 29 Jan 2016 13:03:19 +0800 Message-Id: <1454043812-7893-10-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: CD52B405640A.AC6A9 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 Introudce new function, setup_temp_fs_tree(), to setup temporary fs tree for make_btrfs_v2(). Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- utils.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/utils.c b/utils.c index 4d29b1e..54085b0 100644 --- a/utils.c +++ b/utils.c @@ -654,6 +654,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(). * @@ -750,6 +772,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; }