From patchwork Mon Sep 18 07:21:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9955609 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 D7AEF60385 for ; Mon, 18 Sep 2017 07:22:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C757828A52 for ; Mon, 18 Sep 2017 07:22:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC4E428AF5; Mon, 18 Sep 2017 07:22:25 +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.4 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM 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 5BBB828A52 for ; Mon, 18 Sep 2017 07:22:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751860AbdIRHVz (ORCPT ); Mon, 18 Sep 2017 03:21:55 -0400 Received: from mout.gmx.net ([212.227.17.22]:56804 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751284AbdIRHVw (ORCPT ); Mon, 18 Sep 2017 03:21:52 -0400 Received: from localhost.localdomain ([45.32.39.184]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LcmN9-1dA1Zi2Blf-00kBvF; Mon, 18 Sep 2017 09:21:50 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH v3 04/14] btrfs-progs: mkfs: Update allocation info before verbose output Date: Mon, 18 Sep 2017 16:21:29 +0900 Message-Id: <20170918072139.6300-5-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170918072139.6300-1-quwenruo.btrfs@gmx.com> References: <20170918072139.6300-1-quwenruo.btrfs@gmx.com> X-Provags-ID: V03:K0:x356OhsPMH6GEtIIRwYzoIMuH6em716XwkuoLULofZrTgj1m3WG rxzzRlirdwRCkvx4Dk9sUXKveXSAKbWwVuoy/eWGLoypNw9JDPMGebiXI+X5GpIvkIbHtOb j7qdMqIrZTCQXZECt8WIZpQklnlozMon6KGcwPAYR+UVsd8ls5jltrwCVZ4Gleohd0kE3ax ynhn15LEoKUB5HHU/H62g== X-UI-Out-Filterresults: notjunk:1; V01:K0:nc+gZiMNgpM=:MrHQhO9gf3mRpC+XHFc7CR ezCzOqHAN4pqwwc5TpWLl92aVcnZU1NhjYxzIPfIQ9y7YhK+QVgbn/SucT7a+KwymY8GuO8Kj gFLPXcNlAdXwlzt++dtiMKhV92q1IrldE1dEXhoxs6d0nZ5K7fKxslNadMG082pNhDqF2j6Ie OktbK6rPHTk5iW/j45Sso0o4inHwArmZhr8V6vVRB0ojQ6jacMwHvltklVM7t5/g6RUkU6KPr eLFedOBljLd+trp1MuoB6Yyl3f8KYirBdTUEFHgnbXbPIFF7E1NAThepnhkQ8Dx2xK5Fb0Jx/ 00kkeHqQ/0NPulZiGGX1dlNaUwVDSUhcsTOiZsddiPuXtau7ThZHoEUpcORSN7OuNNvmIopTi Jx9Yh24Yy2wZa1AVCAQE0XMJ2V8o7SXqA0KRcjbiLi0EUZiHp4B9aUbL7Hdy4HHiHlTn9NgrJ PxxIBZ0EgepmCymDRn1E3G+IYuYDd+VQE7tDf5RC7VlKsZpbBC/X0LZM8XWSbObroVA5IMbph N66Z34Jgy2dfoyg3ZLE3YDIhpAKMb/9MmXgc/CHazZYsFx7X4hDHZBrrN5btZXJvzch5h5Zhn vnn/c8M2k0kQtHIt4kV7guZRtmpyIQmetS3Nzip5mEUEWuh6ndHB5P3XlnG7Gv3sl/XGsmSGd fyFNKJKuilOPaRyJAS9mAEU5yTkDJL+ffjaqD/jLXb2XdOdN75dFEkhHrAEoVLvkah3kux+or 9AN70GqJxlIZMpQW6xkWJ55qq9xlHV7K3aW/q0/tXgdhQ5O4Bw17wZ7yBjAIIRW1iZfepEJN3 tAaFni2MPIzA4f2IwccfIb8TWKc9g== 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 0ce1ae26..6561ac52 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -1276,6 +1276,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; @@ -1733,6 +1765,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);