On 10/7/23 11:27, Richard W.M. Jones wrote: > On Fri, Oct 06, 2023 at 10:18:09AM -0500, Eric Blake wrote: >> Adding a human-readable size for block constraints is useful. For: >> >> $ ./run nbdinfo -- [ nbdkit memory \ >> --filter=blocksize-policy blocksize-preferred=32k 1M ] | grep pref >> >> this changes pre-patch: >> block_size_preferred: 32768 >> to post-patch: >> block_size_preferred: 32768 (32K) > > I think info/nbdinfo.pod needs to be updated.
Good catch! With that: series Reviewed-by: Laszlo Ersek <ler...@redhat.com> > > Rich. > >> Signed-off-by: Eric Blake <ebl...@redhat.com> >> --- >> info/show.c | 26 +++++++++++++++++++------- >> 1 file changed, 19 insertions(+), 7 deletions(-) >> >> diff --git a/info/show.c b/info/show.c >> index 6aeffb54..ac483f34 100644 >> --- a/info/show.c >> +++ b/info/show.c >> @@ -35,6 +35,7 @@ >> #include "nbdinfo.h" >> >> static void show_boolean (const char *name, bool cond); >> +static void show_size (const char *name, int64_t size); >> static int collect_context (void *opaque, const char *name); >> static char *get_content (struct nbd_handle *, int64_t size); >> >> @@ -181,13 +182,9 @@ show_one_export (struct nbd_handle *nbd, const char >> *desc, >> show_boolean ("can_trim", can_trim); >> if (can_zero >= 0) >> show_boolean ("can_zero", can_zero); >> - if (block_minimum > 0) >> - fprintf (fp, "\t%s: %" PRId64 "\n", "block_size_minimum", >> block_minimum); >> - if (block_preferred > 0) >> - fprintf (fp, "\t%s: %" PRId64 "\n", "block_size_preferred", >> - block_preferred); >> - if (block_maximum > 0) >> - fprintf (fp, "\t%s: %" PRId64 "\n", "block_size_maximum", >> block_maximum); >> + show_size ("block_size_minimum", block_minimum); >> + show_size ("block_size_preferred", block_preferred); >> + show_size ("block_size_maximum", block_maximum); >> } >> else { >> if (first) >> @@ -304,6 +301,21 @@ show_boolean (const char *name, bool cond) >> ansi_restore (fp); >> } >> >> +/* Used for displaying sizes in non-JSON output. */ >> +void show_size (const char *name, int64_t size) >> +{ >> + char size_str[HUMAN_SIZE_LONGEST]; >> + bool human_size_flag = false; >> + >> + if (size > 0) { >> + human_size (size_str, size, &human_size_flag); >> + if (human_size_flag) >> + fprintf (fp, "\t%s: %" PRId64 " (%s)\n", name, size, size_str); >> + else >> + fprintf (fp, "\t%s: %" PRId64 "\n", name, size); >> + } >> +} >> + >> static int >> collect_context (void *opaque, const char *name) >> { >> -- >> 2.41.0 >> >> _______________________________________________ >> Libguestfs mailing list >> Libguestfs@redhat.com >> https://listman.redhat.com/mailman/listinfo/libguestfs > _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs