From patchwork Mon Sep 4 06:41:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9936727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 15FCE60237 for ; Mon, 4 Sep 2017 06:41:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07A5F2871E for ; Mon, 4 Sep 2017 06:41:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0DB72872E; Mon, 4 Sep 2017 06:41:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9197E2871E for ; Mon, 4 Sep 2017 06:41:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753240AbdIDGl1 (ORCPT ); Mon, 4 Sep 2017 02:41:27 -0400 Received: from mout.gmx.net ([212.227.15.18]:55951 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753246AbdIDGlY (ORCPT ); Mon, 4 Sep 2017 02:41:24 -0400 Received: from localhost.localdomain ([45.32.39.184]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0MWSwU-1e0CM70n74-00XaFR; Mon, 04 Sep 2017 08:41:21 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH 4/5] btrfs-progs: mkfs: Update allocation info before verbose output Date: Mon, 4 Sep 2017 15:41:09 +0900 Message-Id: <20170904064110.25951-5-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170904064110.25951-1-quwenruo.btrfs@gmx.com> References: <20170904064110.25951-1-quwenruo.btrfs@gmx.com> X-Provags-ID: V03:K0:nI91K3SeGtDYsgK5AXqrqY/WFLhjN+5zYYC+46VTdG8RlvnLk12 7MY3U3Ek9vkkOSTBToEQzYhKeT7fglirRpq8luvjWlbjQFrkYycsC2O3I0alhiIJMRhkUBl FrQltOFZuzJ5EEMnNgdKZ6aivlpxnHJikLzoJSIrq0N5Fq7nuNSWYcBnwfcOpMeNolCnzz7 jrMoAfRXcbej8WEIWYLtA== X-UI-Out-Filterresults: notjunk:1; V01:K0:iWN+wELAAUs=:E4VoDh8FHSL3G+tssZElJ+ RA4PqjCYVD0J6jfnT+6IQcC4Xy032qVgeMEqvLqjSYeSAPPAk+aZwUM2cuI01Hy6mbQOccYbi 0oEebhKfqRgcjIHoqYEs+Y2ymRh3PHSzatFQrgkeAPt9ulDBV7IrW3K+LwXgSXrNvNaOPMXtZ vLR1IvRmeGkB4VJ+ufNj4EoAoMov0fTcCi8Y/YX13f0nKyL99OX2RzXjcn8WiOgyNHKwmBZ61 XAje/gzE9XYSrPjr8tHXSVMKj65NJW1jxHFKqVuHGpjWYMp0Ye9UF5YY5SZ0A7VOnbVih89eO Z0QphuN5Cyva8luAS+NwWCINYelR+nN/yqaMfMgUtmuuqTqAEWt7pL0Apv+GGKHZKVNs8/KEl zOknJGbFMKol2Oz2/tfFkqdW9FA4P+2xQa3uoOgCCHtw+MYf8H6M9Z2ypVQ7AC+o3NoaqLR6r tVQadbO38ClqV5/COYZ/eUiKQPYf1LMgFo9HbEdTrsqcj8z3TtcGgQbPOiqBtWDXK3T5icmtP Tu1KDE9eURk4Ix7Um8Yofa7EMDQDoXqyRTtvzXryE95EeitAe5xU51oq1bG1WIbUqvaYj1KZ5 lu3CxvF5NvqmknPKhZbXYGwKXLhnhc3eYXB+rvw9/VJuqkbgAqEix6SKWFHjTFfvL7dkCXmlO KDJ9v2sH//shF850wn6vXRHBWqDUEiUU+ncz4ZeKgGUvcAtbeZjgMWsr+TUUKfmwWnYdtBgLh 4claZEJGCFg4ssd7y3WgEbjUS40mz1v1vVCOupHdO45g3ogS4O3beMvFgMavvo0U0SPvnHx+W hzE4ULNR8Wszdbf0WSwFuimy+906w== Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since new --rootdir can allocate chunk, it will modify the chunk allocation result. This patch will update allocation info before verbose output to reflect such info. Signed-off-by: Qu Wenruo --- mkfs/main.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/mkfs/main.c b/mkfs/main.c index c43ce18d..873aec83 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -1380,6 +1380,38 @@ out: return ret; } +/* + * Just update chunk allocation info, since --rootdir may allocate new + * chunks which is not updated in @allocation structure. + */ +static void update_chunk_allocation(struct btrfs_fs_info *fs_info, + struct mkfs_allocation *allocation) +{ + struct btrfs_block_group_cache *bg_cache; + u64 mixed_flag = BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_METADATA; + u64 search_start = 0; + + allocation->mixed = 0; + allocation->data = 0; + allocation->metadata = 0; + allocation->system = 0; + while (1) { + bg_cache = btrfs_lookup_first_block_group(fs_info, + search_start); + if (!bg_cache) + break; + if ((bg_cache->flags & mixed_flag) == mixed_flag) + allocation->mixed += bg_cache->key.offset; + else if (bg_cache->flags & BTRFS_BLOCK_GROUP_DATA) + allocation->data += bg_cache->key.offset; + else if (bg_cache->flags & BTRFS_BLOCK_GROUP_METADATA) + allocation->metadata += bg_cache->key.offset; + else + allocation->system += bg_cache->key.offset; + search_start = bg_cache->key.objectid + bg_cache->key.offset; + } +} + int main(int argc, char **argv) { char *file; @@ -1842,6 +1874,7 @@ raid_groups: if (verbose) { char features_buf[64]; + update_chunk_allocation(fs_info, &allocation); printf("Label: %s\n", label); printf("UUID: %s\n", mkfs_cfg.fs_uuid); printf("Node size: %u\n", nodesize);