[PATCH 13/21] util: virqemu: Introduce virQEMUBuildNetdevCommandlineFromJSON

Peter Krempa posted 21 patches 5 years, 8 months ago
[PATCH 13/21] util: virqemu: Introduce virQEMUBuildNetdevCommandlineFromJSON
Posted by Peter Krempa 5 years, 8 months ago
In preparation for converting the generator of -netdev to generate JSON
which will be used to do the command line rather than the other way
around we need to introduce a convertor which properly configures
virQEMUBuildCommandLineJSON for the quirks of -netdev.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/util/virqemu.c       | 22 ++++++++++++++++++++++
 src/util/virqemu.h       |  3 +++
 3 files changed, 26 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1bd02fd8ee..fd04fcece3 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2915,6 +2915,7 @@ virQEMUBuildCommandLineJSON;
 virQEMUBuildCommandLineJSONArrayBitmap;
 virQEMUBuildCommandLineJSONArrayNumbered;
 virQEMUBuildDriveCommandlineFromJSON;
+virQEMUBuildNetdevCommandlineFromJSON;
 virQEMUBuildObjectCommandlineFromJSON;
 virQEMUBuildQemuImgKeySecretOpts;

diff --git a/src/util/virqemu.c b/src/util/virqemu.c
index 549f88fcd5..0f8cab29df 100644
--- a/src/util/virqemu.c
+++ b/src/util/virqemu.c
@@ -252,6 +252,28 @@ virQEMUBuildCommandLineJSON(virJSONValuePtr value,
 }


+/**
+ * virQEMUBuildNetdevCommandlineFromJSON:
+ * @props: JSON properties describing a netdev
+ *
+ * Converts @props into arguments for -netdev including all the quirks and
+ * differences between the monitor and command line syntax.
+ */
+char *
+virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props)
+{
+    const char *type = virJSONValueObjectGetString(props, "type");
+    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+
+    virBufferAsprintf(&buf, "%s,", type);
+
+    if (virQEMUBuildCommandLineJSON(props, &buf, "type", true, NULL) < 0)
+        return NULL;
+
+    return virBufferContentAndReset(&buf);
+}
+
+
 static int
 virQEMUBuildObjectCommandlineFromJSONInternal(virBufferPtr buf,
                                               const char *type,
diff --git a/src/util/virqemu.h b/src/util/virqemu.h
index 67a5711613..22f47851df 100644
--- a/src/util/virqemu.h
+++ b/src/util/virqemu.h
@@ -49,6 +49,9 @@ int virQEMUBuildCommandLineJSON(virJSONValuePtr value,
                                 bool onOff,
                                 virQEMUBuildCommandLineJSONArrayFormatFunc array);

+char *
+virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props);
+
 int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
                                           virJSONValuePtr objprops);

-- 
2.26.2

Re: [PATCH 13/21] util: virqemu: Introduce virQEMUBuildNetdevCommandlineFromJSON
Posted by Eric Blake 5 years, 8 months ago
On 5/15/20 10:27 AM, Peter Krempa wrote:
> In preparation for converting the generator of -netdev to generate JSON
> which will be used to do the command line rather than the other way
> around we need to introduce a convertor which properly configures
> virQEMUBuildCommandLineJSON for the quirks of -netdev.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>   src/libvirt_private.syms |  1 +
>   src/util/virqemu.c       | 22 ++++++++++++++++++++++
>   src/util/virqemu.h       |  3 +++
>   3 files changed, 26 insertions(+)
> 

> +/**
> + * virQEMUBuildNetdevCommandlineFromJSON:
> + * @props: JSON properties describing a netdev
> + *
> + * Converts @props into arguments for -netdev including all the quirks and
> + * differences between the monitor and command line syntax.
> + */
> +char *
> +virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props)
> +{
> +    const char *type = virJSONValueObjectGetString(props, "type");
> +    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
> +
> +    virBufferAsprintf(&buf, "%s,", type);
> +
> +    if (virQEMUBuildCommandLineJSON(props, &buf, "type", true, NULL) < 0)
> +        return NULL;

Do we actually have to special-case "type"?

> +
> +    return virBufferContentAndReset(&buf);
> +}
> +
> +
>   static int
>   virQEMUBuildObjectCommandlineFromJSONInternal(virBufferPtr buf,
>                                                 const char *type,
> diff --git a/src/util/virqemu.h b/src/util/virqemu.h
> index 67a5711613..22f47851df 100644
> --- a/src/util/virqemu.h
> +++ b/src/util/virqemu.h
> @@ -49,6 +49,9 @@ int virQEMUBuildCommandLineJSON(virJSONValuePtr value,
>                                   bool onOff,
>                                   virQEMUBuildCommandLineJSONArrayFormatFunc array);
> 
> +char *
> +virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props);
> +
>   int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
>                                             virJSONValuePtr objprops);
> 

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Re: [PATCH 13/21] util: virqemu: Introduce virQEMUBuildNetdevCommandlineFromJSON
Posted by Peter Krempa 5 years, 8 months ago
On Mon, May 18, 2020 at 10:07:25 -0500, Eric Blake wrote:
> On 5/15/20 10:27 AM, Peter Krempa wrote:
> > In preparation for converting the generator of -netdev to generate JSON
> > which will be used to do the command line rather than the other way
> > around we need to introduce a convertor which properly configures
> > virQEMUBuildCommandLineJSON for the quirks of -netdev.
> > 
> > Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> > ---
> >   src/libvirt_private.syms |  1 +
> >   src/util/virqemu.c       | 22 ++++++++++++++++++++++
> >   src/util/virqemu.h       |  3 +++
> >   3 files changed, 26 insertions(+)
> > 
> 
> > +/**
> > + * virQEMUBuildNetdevCommandlineFromJSON:
> > + * @props: JSON properties describing a netdev
> > + *
> > + * Converts @props into arguments for -netdev including all the quirks and
> > + * differences between the monitor and command line syntax.
> > + */
> > +char *
> > +virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props)
> > +{
> > +    const char *type = virJSONValueObjectGetString(props, "type");
> > +    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
> > +
> > +    virBufferAsprintf(&buf, "%s,", type);
> > +
> > +    if (virQEMUBuildCommandLineJSON(props, &buf, "type", true, NULL) < 0)
> > +        return NULL;
> 
> Do we actually have to special-case "type"?

I'd have to go back and see since when we can use type= explicitly with
qemu and I didn't really feel doing that across all supported qemu
versions. Well, to be fair not even across the reasonable versions.