libnbd/0011-info-Add-percentage-after-field-in-map-totals.patch
Richard W.M. Jones 323edc9d03 Fix nbdcopy progress bar.
Add nbdinfo --map --totals and --can/--is options.
resolves: rhbz#1950630
2021-07-30 18:34:46 +01:00

67 lines
2.1 KiB
Diff

From f4e3a9ac3d80c0e73e3b92fdb1faa704595fe61e Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 28 Jun 2021 18:54:21 +0100
Subject: [PATCH] info: Add percentage after field in --map --totals
Add % sign after the percentage field in plain output (not JSON).
$ nbdkit -r file fedora-33.img --run 'nbdinfo --map --totals $uri'
1226113024 19.0% 0 data
5216337920 81.0% 3 hole,zero
Thanks: Eric Blake
Updates: commit 7968bfe328e86574276283b159a594eeebeaf32a
(cherry picked from commit 8d39d388cc18b2e16a01ba2b64f51672b5b91389)
---
info/info-map-totals.sh | 4 ++--
info/map.c | 2 +-
info/nbdinfo.pod | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/info/info-map-totals.sh b/info/info-map-totals.sh
index 12c1263..c637ff5 100755
--- a/info/info-map-totals.sh
+++ b/info/info-map-totals.sh
@@ -36,8 +36,8 @@ nbdkit -U - data data='1 @131072 2' size=1M \
cat $out
-if [ "$(tr -s ' ' < $out)" != " 65536 6.2 0 data
- 983040 93.8 3 hole,zero" ]; then
+if [ "$(tr -s ' ' < $out)" != " 65536 6.2% 0 data
+ 983040 93.8% 3 hole,zero" ]; then
echo "$0: unexpected output from nbdinfo --map"
exit 1
fi
diff --git a/info/map.c b/info/map.c
index 628033c..de7b7ab 100644
--- a/info/map.c
+++ b/info/map.c
@@ -241,7 +241,7 @@ print_totals (uint32_vector *entries, int64_t size)
double percent = 100.0 * c / size;
if (!json_output) {
- fprintf (fp, "%10" PRIu64 " %5.1f %3" PRIu32,
+ fprintf (fp, "%10" PRIu64 " %5.1f%% %3" PRIu32,
c, percent, type);
if (descr)
fprintf (fp, " %s", descr);
diff --git a/info/nbdinfo.pod b/info/nbdinfo.pod
index fb20f0e..1699712 100644
--- a/info/nbdinfo.pod
+++ b/info/nbdinfo.pod
@@ -195,8 +195,8 @@ In the example below, half (50.0%) of the disk is allocated data and
half is unallocated:
$ nbdinfo --map --totals nbd://localhost/
- 1048576 50.0 0 data
- 1048576 50.0 3 hole,zero
+ 1048576 50.0% 0 data
+ 1048576 50.0% 3 hole,zero
The fields are: total size in bytes, percentage of the virtual size,
type, description (optional).
--
2.31.1