On Mon, Jun 28, 2021 at 12:05:03PM -0500, Eric Blake wrote:
On Sat, Jun 26, 2021 at 05:19:47PM +0100, Richard W.M. Jones wrote:
> This is similar to "qemu-img measure". Some examples:
>
> $ nbdkit -r file fedora-33.img --run 'nbdinfo --map --totals $uri'
> 1226113024 19.0 0 data
> 5216337920 81.0 3 hole,zero
Is it worth a human-legible header line? Or maybe a % character in
the second column?
We don't have headers on the other table and it may be too late to add
those now. But I think you're right it would be better to add a %
character after the percent field (ie. "%5.1f%%"). I think I'll make
this change.
> +++ b/info/info-map-totals-json.sh
> +
> +test $( jq -r '.[0].size' < $out ) -eq 65536
> +test $( jq -r '.[0].percent' < $out ) = "6.25"
> +test $( jq -r '.[0].type' < $out ) -eq 0
> +test $( jq -r '.[0].description' < $out ) = "data"
> +
> +test $( jq -r '.[1].size' < $out ) -eq 983040
> +test $( jq -r '.[1].percent' < $out ) = "93.75"
> +test $( jq -r '.[1].type' < $out ) -eq 3
> +test $( jq -r '.[1].description' < $out ) = "hole,zero"
...
> diff --git a/info/info-map-totals.sh b/info/info-map-totals.sh
> new file mode 100755
> index 0000000..12c1263
> --- /dev/null
> +++ b/info/info-map-totals.sh
> @@ -0,0 +1,43 @@
> +
> +cat $out
> +
> +if [ "$(tr -s ' ' < $out)" != " 65536 6.2 0 data
> + 983040 93.8 3 hole,zero" ]; then
So this is the human-readable counterpart of info-map-totals-json.sh.
I'm trying to figure out why 6.25 rounded down and 93.75 rounded up.
I guess it's related to round-to-even? But it's also fine if the
rounded values don't sum back up to 100%; I don't know if it's worth a
documentation disclaimer.
I don't know either.
> + $ nbdinfo --map --totals --json nbd://localhost/
> + [{ "size": 1048576, "percent": 50,
> + "type": 0, "description": "data" },
> + { "size": 1048576, "percent": 50,
> + "type": 3, "description": "hole,zero" }]
> +
> +As with the I<--map> option, by default this shows the
> +C<"base:allocation"> map, but you can show the summary for other
maps.
I'd still like to someday have a mode where we can read all advertised
maps at once, rather than making the command-line user have to
manually invoke nbdinfo once per map spelled by the user, but that can
still go on top of this.
Yes it should be possible using nbd_opt_list_meta_context.
Overall, looks good to me!
Thanks,
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html