[Libguestfs] [PATCH nbdinfo v2 3/3] copy: Print debug information with human sizes

Richard W.M. Jones rjones at redhat.com
Mon Sep 20 11:04:48 UTC 2021


---
 copy/main.c          | 6 +++++-
 copy/test-verbose.sh | 4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/copy/main.c b/copy/main.c
index 70534b5a..15a64544 100644
--- a/copy/main.c
+++ b/copy/main.c
@@ -39,6 +39,7 @@
 #include <libnbd.h>
 
 #include "ispowerof2.h"
+#include "human-size.h"
 #include "version.h"
 #include "nbdcopy.h"
 
@@ -508,8 +509,11 @@ open_local (const char *filename, direction d)
 static void
 print_rw (struct rw *rw, const char *prefix, FILE *fp)
 {
+  char buf[HUMAN_SIZE_LONGEST];
+
   fprintf (fp, "%s: %s \"%s\"\n", prefix, rw->ops->ops_name, rw->name);
-  fprintf (fp, "%s: size=%" PRIi64 "\n", prefix, rw->size);
+  fprintf (fp, "%s: size=%" PRIi64 " (%s)\n",
+           prefix, rw->size, human_size (buf, rw->size, NULL));
 }
 
 /* Default implementation of rw->ops->get_extents for backends which
diff --git a/copy/test-verbose.sh b/copy/test-verbose.sh
index afd57580..4cc67d37 100755
--- a/copy/test-verbose.sh
+++ b/copy/test-verbose.sh
@@ -28,11 +28,11 @@ requires nbdkit --version
 file=test-verbose.out
 cleanup_fn rm -f $file
 
-$VG nbdcopy -v -- [ nbdkit null ] null: 2>$file
+$VG nbdcopy -v -- [ nbdkit memory 1M ] null: 2>$file
 
 cat $file
 
 # Check some known strings appear in the output.
 grep '^nbdcopy: src: nbd_ops' $file
-grep '^nbdcopy: src: size=0' $file
+grep '^nbdcopy: src: size=1048576 (1M)' $file
 grep '^nbdcopy: dst: null_ops' $file
-- 
2.32.0




More information about the Libguestfs mailing list