Eric Blake
2020-Oct-16 15:23 UTC
[Libguestfs] [libnbd PATCH] info: Add support for new 'qemu-nbd -A' qemu:allocation-depth
A rather trivial decoding; we may enhance it further if qemu extends things to give an integer depth alongside its tri-state encoding. --- I'll wait to push this to libnbd until the counterpart qemu patches land upstream, although it looks like I've got positive review. info/nbdinfo.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/info/nbdinfo.c b/info/nbdinfo.c index 24ec129..1afdf98 100644 --- a/info/nbdinfo.c +++ b/info/nbdinfo.c @@ -780,6 +780,13 @@ extent_description (const char *metacontext, uint32_t type) case 1: return "dirty"; } } + else if (strcmp (metacontext, "qemu:allocation-depth") == 0) { + switch (type & 3) { + case 0: return "unallocated"; + case 1: return "local"; + case 2: return "backing"; + } + } return NULL; /* Don't know - description field will be omitted. */ } -- 2.29.0.rc1
Richard W.M. Jones
2020-Oct-17 10:34 UTC
Re: [Libguestfs] [libnbd PATCH] info: Add support for new 'qemu-nbd -A' qemu:allocation-depth
On Fri, Oct 16, 2020 at 10:23:18AM -0500, Eric Blake wrote:> A rather trivial decoding; we may enhance it further if qemu extends > things to give an integer depth alongside its tri-state encoding. > --- > > I'll wait to push this to libnbd until the counterpart qemu patches > land upstream, although it looks like I've got positive review. > > info/nbdinfo.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/info/nbdinfo.c b/info/nbdinfo.c > index 24ec129..1afdf98 100644 > --- a/info/nbdinfo.c > +++ b/info/nbdinfo.c > @@ -780,6 +780,13 @@ extent_description (const char *metacontext, uint32_t type) > case 1: return "dirty"; > } > } > + else if (strcmp (metacontext, "qemu:allocation-depth") == 0) { > + switch (type & 3) { > + case 0: return "unallocated"; > + case 1: return "local"; > + case 2: return "backing"; > + } > + } > > return NULL; /* Don't know - description field will be omitted. */ > }ACK Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Eric Blake
2020-Oct-27 15:33 UTC
Re: [Libguestfs] [libnbd PATCH] info: Add support for new 'qemu-nbd -A' qemu:allocation-depth
On 10/16/20 10:23 AM, Eric Blake wrote:> A rather trivial decoding; we may enhance it further if qemu extends > things to give an integer depth alongside its tri-state encoding. > --- > > I'll wait to push this to libnbd until the counterpart qemu patches > land upstream, although it looks like I've got positive review.Whoops, I accidentally pushed this before qemu stuff landed upstream, and in the meantime, we changed our minds on what to expose over qemu:allocation-depth to be a bare integer rather than a tri-state. I'll push this followup (but this time, wait for the actual qemu patch to land). In fact, I should probably add test-suite coverage...>From eba8734654e6fd340e18b3e07c3213ed1a0ab9e8 Mon Sep 17 00:00:00 2001From: Eric Blake <eblake@redhat.com> Date: Tue, 27 Oct 2020 10:27:25 -0500 Subject: [libnbd PATCH] info: Adjust to actual 'qemu-nbd -A' semantics Review on the qemu list has led to an altered definition of what 'qemu:allocation-depth' should report: rather than a tri-state value, it is an actual depth. It's time to match what actually got committed into qemu, which in turn means a slight refactoring to use a malloc'd string for a description. Fixes: 71455c021 --- info/nbdinfo.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/info/nbdinfo.c b/info/nbdinfo.c index 2b22f51..b152f28 100644 --- a/info/nbdinfo.c +++ b/info/nbdinfo.c @@ -767,28 +767,30 @@ get_content (struct nbd_handle *nbd, int64_t size) } /* Callback handling --map. */ -static const char * +static char * extent_description (const char *metacontext, uint32_t type) { + char *ret; + if (strcmp (metacontext, "base:allocation") == 0) { switch (type) { - case 0: return "allocated"; - case 1: return "hole"; - case 2: return "zero"; - case 3: return "hole,zero"; + case 0: return strdup ("allocated"); + case 1: return strdup ("hole"); + case 2: return strdup ("zero"); + case 3: return strdup ("hole,zero"); } } else if (strncmp (metacontext, "qemu:dirty-bitmap:", 18) == 0) { switch (type) { - case 0: return "clean"; - case 1: return "dirty"; + case 0: return strdup ("clean"); + case 1: return strdup ("dirty"); } } else if (strcmp (metacontext, "qemu:allocation-depth") == 0) { - switch (type & 3) { - case 0: return "unallocated"; - case 1: return "local"; - case 2: return "backing"; + switch (type) { + case 0: return strdup ("unallocated"); + case 1: return strdup ("local"); + case 2: asprintf (&ret, "backing depth %d", type); return ret; } } @@ -810,7 +812,7 @@ extent_callback (void *user_data, const char *metacontext, /* Print the entries received. */ for (i = 0; i < nr_entries; i += 2) { - const char *descr = extent_description (map, entries[i+1]); + char *descr = extent_description (map, entries[i+1]); if (!json_output) { fprintf (fp, "%10" PRIu64 " " @@ -837,6 +839,7 @@ extent_callback (void *user_data, const char *metacontext, comma = true; } + free (descr); offset += entries[i]; } -- 2.29.0 -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Richard W.M. Jones
2020-Oct-27 19:40 UTC
Re: [Libguestfs] [libnbd PATCH] info: Add support for new 'qemu-nbd -A' qemu:allocation-depth
On Tue, Oct 27, 2020 at 10:33:48AM -0500, Eric Blake wrote:> On 10/16/20 10:23 AM, Eric Blake wrote: > > A rather trivial decoding; we may enhance it further if qemu extends > > things to give an integer depth alongside its tri-state encoding. > > --- > > > > I'll wait to push this to libnbd until the counterpart qemu patches > > land upstream, although it looks like I've got positive review. > > Whoops, I accidentally pushed this before qemu stuff landed upstream, > and in the meantime, we changed our minds on what to expose over > qemu:allocation-depth to be a bare integer rather than a tri-state. > I'll push this followup (but this time, wait for the actual qemu patch > to land). In fact, I should probably add test-suite coverage...ACK. I have a patch which touches this file but it's a simple merge to combine the two changes. Rich.> >From eba8734654e6fd340e18b3e07c3213ed1a0ab9e8 Mon Sep 17 00:00:00 2001 > From: Eric Blake <eblake@redhat.com> > Date: Tue, 27 Oct 2020 10:27:25 -0500 > Subject: [libnbd PATCH] info: Adjust to actual 'qemu-nbd -A' semantics > > Review on the qemu list has led to an altered definition of what > 'qemu:allocation-depth' should report: rather than a tri-state value, > it is an actual depth. It's time to match what actually got committed > into qemu, which in turn means a slight refactoring to use a malloc'd > string for a description. > > Fixes: 71455c021 > --- > info/nbdinfo.c | 27 +++++++++++++++------------ > 1 file changed, 15 insertions(+), 12 deletions(-) > > diff --git a/info/nbdinfo.c b/info/nbdinfo.c > index 2b22f51..b152f28 100644 > --- a/info/nbdinfo.c > +++ b/info/nbdinfo.c > @@ -767,28 +767,30 @@ get_content (struct nbd_handle *nbd, int64_t size) > } > > /* Callback handling --map. */ > -static const char * > +static char * > extent_description (const char *metacontext, uint32_t type) > { > + char *ret; > + > if (strcmp (metacontext, "base:allocation") == 0) { > switch (type) { > - case 0: return "allocated"; > - case 1: return "hole"; > - case 2: return "zero"; > - case 3: return "hole,zero"; > + case 0: return strdup ("allocated"); > + case 1: return strdup ("hole"); > + case 2: return strdup ("zero"); > + case 3: return strdup ("hole,zero"); > } > } > else if (strncmp (metacontext, "qemu:dirty-bitmap:", 18) == 0) { > switch (type) { > - case 0: return "clean"; > - case 1: return "dirty"; > + case 0: return strdup ("clean"); > + case 1: return strdup ("dirty"); > } > } > else if (strcmp (metacontext, "qemu:allocation-depth") == 0) { > - switch (type & 3) { > - case 0: return "unallocated"; > - case 1: return "local"; > - case 2: return "backing"; > + switch (type) { > + case 0: return strdup ("unallocated"); > + case 1: return strdup ("local"); > + case 2: asprintf (&ret, "backing depth %d", type); return ret; > } > } > > @@ -810,7 +812,7 @@ extent_callback (void *user_data, const char > *metacontext, > > /* Print the entries received. */ > for (i = 0; i < nr_entries; i += 2) { > - const char *descr = extent_description (map, entries[i+1]); > + char *descr = extent_description (map, entries[i+1]); > > if (!json_output) { > fprintf (fp, "%10" PRIu64 " " > @@ -837,6 +839,7 @@ extent_callback (void *user_data, const char > *metacontext, > comma = true; > } > > + free (descr); > offset += entries[i]; > } > > -- > 2.29.0 > > > > -- > Eric Blake, Principal Software Engineer > Red Hat, Inc. +1-919-301-3226 > Virtualization: qemu.org | libvirt.org > > _______________________________________________ > Libguestfs mailing list > Libguestfs@redhat.com > https://www.redhat.com/mailman/listinfo/libguestfs-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Maybe Matching Threads
- [PATCH nbdinfo proposal] info: Add a --map option for displaying allocation metadata
- [PATCH libnbd 0/5] info: --map: Coalesce adjacent extents of the same type.
- [PATCH nbdinfo v2] info: Add a --map option for displaying allocation metadata.
- Re: [libnbd PATCH] info: Add support for new 'qemu-nbd -A' qemu:allocation-depth
- [libnbd PATCH] info: Keep request within 4G bound