From f49fb67a2552c14e4194b97ce34d3fbf5389a1ce Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 3 Jan 2017 18:26:43 +0100 Subject: [PATCH] btrfs-progs: enable negative numbers for unallocated device space The unallocated space is not calculated correctly when a device deltion/replace is in progress. This appears as huge number, EiB-sized. It's really a negative number, because we don't have entire information available and mixing numbers that do and don't take the deleted device size into account. We have to query search ioctl to retrieve the missing information, also this requires root access for the ioctl, so we still need a workaround for non-root case. Here the negative numbers seem to be a bit more practical than EiB numbers. Signed-off-by: David Sterba --- cmds-fi-usage.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c index 8764fef..88e346a 100644 --- a/cmds-fi-usage.c +++ b/cmds-fi-usage.c @@ -471,7 +471,7 @@ static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo, printf(" Device allocated:\t\t%*s\n", width, pretty_size_mode(r_total_chunks, unit_mode)); printf(" Device unallocated:\t\t%*s\n", width, - pretty_size_mode(r_total_unused, unit_mode)); + pretty_size_mode(r_total_unused, unit_mode | UNITS_NEGATIVE)); printf(" Device missing:\t\t%*s\n", width, pretty_size_mode(r_total_missing, unit_mode)); printf(" Used:\t\t\t%*s\n", width, @@ -736,8 +736,8 @@ static void _cmd_filesystem_usage_tabular(unsigned unit_mode, unused = get_partition_size(device_info_ptr[i].path) - total_allocated; - table_printf(matrix, unallocated_col, vhdr_skip + i, - ">%s", pretty_size_mode(unused, unit_mode)); + table_printf(matrix, unallocated_col, vhdr_skip + i, ">%s", + pretty_size_mode(unused, unit_mode | UNITS_NEGATIVE)); total_unused += unused; } @@ -771,7 +771,8 @@ static void _cmd_filesystem_usage_tabular(unsigned unit_mode, } table_printf(matrix, unallocated_col, vhdr_skip + device_info_count + 1, - ">%s", pretty_size_mode(total_unused, unit_mode)); + ">%s", + pretty_size_mode(total_unused, unit_mode | UNITS_NEGATIVE)); table_printf(matrix, 1, vhdr_skip + device_info_count + 2, "total_spaces; i++) { @@ -884,7 +885,7 @@ static void _cmd_filesystem_usage_linear(unsigned unit_mode, printf("Unallocated:\n"); print_unused(info_ptr, info_count, device_info_ptr, device_info_count, - unit_mode); + unit_mode | UNITS_NEGATIVE); } static int print_filesystem_usage_by_chunk(int fd, @@ -1027,7 +1028,8 @@ void print_device_chunks(int fd, struct device_info *devinfo, } printf(" Unallocated: %*s%10s\n", (int)(20 - strlen("Unallocated")), "", - pretty_size_mode(devinfo->size - allocated, unit_mode)); + pretty_size_mode(devinfo->size - allocated, + unit_mode | UNITS_NEGATIVE)); } void print_device_sizes(int fd, struct device_info *devinfo, unsigned unit_mode) -- 2.7.4