From patchwork Tue Mar 17 13:53:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 6032001 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 641CB9F314 for ; Tue, 17 Mar 2015 13:54:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 98A8020412 for ; Tue, 17 Mar 2015 13:54:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8C46C20411 for ; Tue, 17 Mar 2015 13:54:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932244AbbCQNyH (ORCPT ); Tue, 17 Mar 2015 09:54:07 -0400 Received: from cantor2.suse.de ([195.135.220.15]:49420 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753108AbbCQNyD (ORCPT ); Tue, 17 Mar 2015 09:54:03 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id ADE11AD28; Tue, 17 Mar 2015 13:54:01 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 66912DAA36; Tue, 17 Mar 2015 14:54:01 +0100 (CET) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: raffix@web.de, David Sterba Subject: [PATCH] btrfs-progs: fi usage, fix reporting space for degraded mounts Date: Tue, 17 Mar 2015 14:53:52 +0100 Message-Id: <1426600432-24635-1-git-send-email-dsterba@suse.cz> X-Mailer: git-send-email 2.1.3 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 The total size of devices was summed from raw partition size which is wrong in two ways: - if the device is missing, the size is 0 and it mismatches the size summed from chunks, leading to bogus numbers like Device unallocated: 16.00EiB Used: 1.88TiB Free (estimated): 8.00EiB (min: 8.00EiB) - we should really account the device size that's occupied by btrfs, not the real partition size altough it's the same most of the time The sum of missing devices is now printed in the summary and any missing device path is replaced with 'missing' instead of blank: Data,RAID1: Size:972.00GiB, Used:962.15GiB 972.00GiB /dev/sdb1 972.00GiB Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=94911 Reported-by: Signed-off-by: David Sterba --- cmds-fi-disk_usage.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cmds-fi-disk_usage.c b/cmds-fi-disk_usage.c index 27f9a4c8f213..27b989df45f2 100644 --- a/cmds-fi-disk_usage.c +++ b/cmds-fi-disk_usage.c @@ -324,6 +324,7 @@ static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo, u64 r_total_chunks = 0; /* sum of chunks sizes on disk(s) */ u64 r_total_used = 0; u64 r_total_unused = 0; + u64 r_total_missing = 0; /* sum of missing devices size */ u64 r_data_used = 0; u64 r_data_chunks = 0; u64 l_data_chunks = 0; @@ -350,8 +351,11 @@ static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo, } r_total_size = 0; - for (i = 0; i < devcount; i++) - r_total_size += devinfo[i].device_size; + for (i = 0; i < devcount; i++) { + r_total_size += devinfo[i].size; + if (!devinfo[i].device_size) + r_total_missing += devinfo[i].size; + } if (r_total_size == 0) { fprintf(stderr, @@ -461,6 +465,8 @@ static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo, pretty_size_mode(r_total_chunks, unit_mode)); printf(" Device unallocated:\t\t%*s\n", width, pretty_size_mode(r_total_unused, unit_mode)); + printf(" Device missing:\t\t%*s\n", width, + pretty_size_mode(r_total_missing, unit_mode)); printf(" Used:\t\t\t%*s\n", width, pretty_size_mode(r_total_used, unit_mode)); printf(" Free (estimated):\t\t%*s\t(", @@ -538,8 +544,13 @@ static int load_device_info(int fd, struct device_info **device_info_ptr, } info[ndevs].devid = dev_info.devid; - strcpy(info[ndevs].path, (char *)dev_info.path); - info[ndevs].device_size = get_partition_size((char *)dev_info.path); + if (!dev_info.path[0]) { + strcpy(info[ndevs].path, "missing"); + } else { + strcpy(info[ndevs].path, (char *)dev_info.path); + info[ndevs].device_size = + get_partition_size((char *)dev_info.path); + } info[ndevs].size = dev_info.total_bytes; ++ndevs; }