From patchwork Wed Dec 17 20:14:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 5509161 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7ECD99F1D4 for ; Wed, 17 Dec 2014 20:13:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7485E209DC for ; Wed, 17 Dec 2014 20:13:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 65BFB208BC for ; Wed, 17 Dec 2014 20:13:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751356AbaLQUNO (ORCPT ); Wed, 17 Dec 2014 15:13:14 -0500 Received: from mail-wi0-f170.google.com ([209.85.212.170]:45945 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751189AbaLQUNC (ORCPT ); Wed, 17 Dec 2014 15:13:02 -0500 Received: by mail-wi0-f170.google.com with SMTP id bs8so18194491wib.5 for ; Wed, 17 Dec 2014 12:13:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vdYthVnNHEvR9Midk1D+K3ToDRfslk2zvhlPpoMW1yo=; b=TzvA5JBKsWrCjbc4vvbK5q4cSNEBZpxydRD3D0nE414BEF5p6CuzP0ZUssDJkk+/Vd hxSiUToiWM4IElL2ZVmGAgQ9adMek4HvFVJ8uijti/N3vwJvf+ME4pFAGDd51SHf8IqE HyVV8gqIZqpnzvqlt1y7nnz6n0ofcaxiiBVjIaKtj+FnoiM4toHOOpL/chI1TibN67ma wEZG8rCSaWNPRUA0A3HNRmLTFFh/0vgdRlqXgLLH7q47621Z6f8HPfGaO61BIrtSBssL lApBIdmH/Lx97MqHfXFyfrguPQ3E9QxzXk+c0fjGQL93SMsztV2WnNyMh23HfWFDeaGQ ozjw== X-Received: by 10.180.104.9 with SMTP id ga9mr18084814wib.9.1418847180865; Wed, 17 Dec 2014 12:13:00 -0800 (PST) Received: from venice.bhome (ppp-133-85.24-151.libero.it. [151.24.85.133]) by mx.google.com with ESMTPSA id pu3sm6360357wjc.14.2014.12.17.12.12.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Dec 2014 12:13:00 -0800 (PST) From: Goffredo Baroncelli X-Google-Original-From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Goffredo Baroncelli Subject: [PATCH 6/8] Track the size of the chunk created Date: Wed, 17 Dec 2014 21:14:10 +0100 Message-Id: <1418847252-14184-7-git-send-email-kreijack@inwind.it> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1418847252-14184-1-git-send-email-kreijack@inwind.it> References: <1418847252-14184-1-git-send-email-kreijack@inwind.it> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Track the size of the chunk during the filesystem creation. These information are printed in a next patch. Signed-off-by: Goffredo Baroncelli --- mkfs.c | 54 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/mkfs.c b/mkfs.c index 70c88ea..2d7b2ca 100644 --- a/mkfs.c +++ b/mkfs.c @@ -57,7 +57,16 @@ struct directory_name_entry { struct list_head list; }; -static int make_root_dir(struct btrfs_root *root, int mixed) +struct block_group_allocation { + u64 data; + u64 metadata; + u64 mixed; + u64 system; +}; + + +static int make_root_dir(struct btrfs_root *root, int mixed, + struct block_group_allocation *allocation) { struct btrfs_trans_handle *trans; struct btrfs_key location; @@ -74,6 +83,7 @@ static int make_root_dir(struct btrfs_root *root, int mixed) BTRFS_BLOCK_GROUP_SYSTEM, BTRFS_FIRST_CHUNK_TREE_OBJECTID, 0, BTRFS_MKFS_SYSTEM_GROUP_SIZE); + allocation->system += BTRFS_MKFS_SYSTEM_GROUP_SIZE; BUG_ON(ret); if (mixed) { @@ -92,8 +102,8 @@ static int make_root_dir(struct btrfs_root *root, int mixed) BTRFS_BLOCK_GROUP_DATA, BTRFS_FIRST_CHUNK_TREE_OBJECTID, chunk_start, chunk_size); + allocation->mixed += chunk_size; BUG_ON(ret); - printf("Created a data/metadata chunk of size %llu\n", chunk_size); } else { ret = btrfs_alloc_chunk(trans, root->fs_info->extent_root, &chunk_start, &chunk_size, @@ -107,6 +117,7 @@ static int make_root_dir(struct btrfs_root *root, int mixed) BTRFS_BLOCK_GROUP_METADATA, BTRFS_FIRST_CHUNK_TREE_OBJECTID, chunk_start, chunk_size); + allocation->metadata += chunk_size; BUG_ON(ret); } @@ -128,6 +139,7 @@ static int make_root_dir(struct btrfs_root *root, int mixed) BTRFS_BLOCK_GROUP_DATA, BTRFS_FIRST_CHUNK_TREE_OBJECTID, chunk_start, chunk_size); + allocation->data += chunk_size; BUG_ON(ret); } @@ -187,7 +199,9 @@ static void recow_roots(struct btrfs_trans_handle *trans, } static int create_one_raid_group(struct btrfs_trans_handle *trans, - struct btrfs_root *root, u64 type) + struct btrfs_root *root, u64 type, + struct block_group_allocation *allocation) + { u64 chunk_start; u64 chunk_size; @@ -203,6 +217,18 @@ static int create_one_raid_group(struct btrfs_trans_handle *trans, ret = btrfs_make_block_group(trans, root->fs_info->extent_root, 0, type, BTRFS_FIRST_CHUNK_TREE_OBJECTID, chunk_start, chunk_size); + if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == BTRFS_BLOCK_GROUP_DATA) + allocation->data += chunk_size; + else if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == BTRFS_BLOCK_GROUP_METADATA) + allocation->metadata += chunk_size; + else if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == BTRFS_BLOCK_GROUP_SYSTEM) + allocation->system += chunk_size; + else if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == + (BTRFS_BLOCK_GROUP_METADATA|BTRFS_BLOCK_GROUP_DATA)) + allocation->mixed += chunk_size; + else + BUG_ON(1); + BUG_ON(ret); return ret; } @@ -210,7 +236,8 @@ static int create_one_raid_group(struct btrfs_trans_handle *trans, static int create_raid_groups(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 data_profile, int data_profile_opt, u64 metadata_profile, - int mixed) + int mixed, + struct block_group_allocation *allocation) { u64 num_devices = btrfs_super_num_devices(root->fs_info->super_copy); int ret; @@ -220,21 +247,21 @@ static int create_raid_groups(struct btrfs_trans_handle *trans, ret = create_one_raid_group(trans, root, BTRFS_BLOCK_GROUP_SYSTEM | - metadata_profile); + metadata_profile, allocation); BUG_ON(ret); if (mixed) meta_flags |= BTRFS_BLOCK_GROUP_DATA; ret = create_one_raid_group(trans, root, meta_flags | - metadata_profile); + metadata_profile, allocation); BUG_ON(ret); } if (!mixed && num_devices > 1 && data_profile) { ret = create_one_raid_group(trans, root, BTRFS_BLOCK_GROUP_DATA | - data_profile); + data_profile, allocation); BUG_ON(ret); } recow_roots(trans, root); @@ -920,7 +947,8 @@ static int open_target(char *output_name) static int create_chunks(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 num_of_meta_chunks, - u64 size_of_data) + u64 size_of_data, + struct block_group_allocation *allocation) { u64 chunk_start; u64 chunk_size; @@ -937,6 +965,7 @@ static int create_chunks(struct btrfs_trans_handle *trans, ret = btrfs_make_block_group(trans, root->fs_info->extent_root, 0, meta_type, BTRFS_FIRST_CHUNK_TREE_OBJECTID, chunk_start, chunk_size); + allocation->metadata += chunk_size; BUG_ON(ret); set_extent_dirty(&root->fs_info->free_space_cache, chunk_start, chunk_start + chunk_size - 1, 0); @@ -951,6 +980,7 @@ static int create_chunks(struct btrfs_trans_handle *trans, ret = btrfs_make_block_group(trans, root->fs_info->extent_root, 0, data_type, BTRFS_FIRST_CHUNK_TREE_OBJECTID, chunk_start, size_of_data); + allocation->data += size_of_data; BUG_ON(ret); set_extent_dirty(&root->fs_info->free_space_cache, chunk_start, chunk_start + size_of_data - 1, 0); @@ -1283,6 +1313,7 @@ int main(int ac, char **av) char estr[100]; char fs_uuid[BTRFS_UUID_UNPARSED_SIZE] = { 0 }; u64 features = DEFAULT_MKFS_FEATURES; + struct block_group_allocation allocation = { 0 }; while(1) { int c; @@ -1593,7 +1624,7 @@ int main(int ac, char **av) } root->fs_info->alloc_start = alloc_start; - ret = make_root_dir(root, mixed); + ret = make_root_dir(root, mixed, &allocation); if (ret) { fprintf(stderr, "failed to setup the root directory\n"); exit(1); @@ -1649,7 +1680,7 @@ raid_groups: if (!source_dir_set) { ret = create_raid_groups(trans, root, data_profile, data_profile_opt, metadata_profile, - mixed); + mixed, &allocation); BUG_ON(ret); } @@ -1666,7 +1697,8 @@ raid_groups: if (source_dir_set) { trans = btrfs_start_transaction(root, 1); ret = create_chunks(trans, root, - num_of_meta_chunks, size_of_data); + num_of_meta_chunks, size_of_data, + &allocation); BUG_ON(ret); btrfs_commit_transaction(trans, root);