From patchwork Fri Oct 20 01:59:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10018585 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 E4E4A60234 for ; Fri, 20 Oct 2017 01:59:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5EEC28710 for ; Fri, 20 Oct 2017 01:59:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB0CD287AC; Fri, 20 Oct 2017 01:59:37 +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,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 7DC2328710 for ; Fri, 20 Oct 2017 01:59:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751915AbdJTB7e (ORCPT ); Thu, 19 Oct 2017 21:59:34 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:50737 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751796AbdJTB7c (ORCPT ); Thu, 19 Oct 2017 21:59:32 -0400 Received: from adam-pc.lan (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (NOT encrypted); Thu, 19 Oct 2017 19:59:16 -0600 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH 6/7] btrfs-progs: mkfs: Update allocation info before verbose output Date: Fri, 20 Oct 2017 09:59:06 +0800 Message-Id: <20171020015907.25430-7-wqu@suse.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171020015907.25430-1-wqu@suse.com> References: <20171020015907.25430-1-wqu@suse.com> 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 0866e40d155f..6aefb50a8033 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -670,6 +670,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; @@ -1164,6 +1196,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);