]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: virqemu: Introduce virQEMUBuildNetdevCommandlineFromJSON
authorPeter Krempa <pkrempa@redhat.com>
Thu, 14 May 2020 08:10:16 +0000 (10:10 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 20 May 2020 07:41:57 +0000 (09:41 +0200)
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>
Reviewed-by: Eric Blake <eblake@redhat.com>
src/libvirt_private.syms
src/util/virqemu.c
src/util/virqemu.h

index 1bd02fd8eeb46d9e90f238e8b4f8f7614d13eae0..fd04fcece3a876c0183ca267af166b59d57364f0 100644 (file)
@@ -2915,6 +2915,7 @@ virQEMUBuildCommandLineJSON;
 virQEMUBuildCommandLineJSONArrayBitmap;
 virQEMUBuildCommandLineJSONArrayNumbered;
 virQEMUBuildDriveCommandlineFromJSON;
+virQEMUBuildNetdevCommandlineFromJSON;
 virQEMUBuildObjectCommandlineFromJSON;
 virQEMUBuildQemuImgKeySecretOpts;
 
index 549f88fcd5c415d2da1357aa29a7125646a0b871..0f8cab29df215a348bfc68a4f50cbab33aa8b57e 100644 (file)
@@ -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,
index 67a5711613a982a14fda42a34aa9c9abd3ad3fb8..22f47851dfa4f1d8e3fe6353fd7b8af33de7cb57 100644 (file)
@@ -49,6 +49,9 @@ int virQEMUBuildCommandLineJSON(virJSONValuePtr value,
                                 bool onOff,
                                 virQEMUBuildCommandLineJSONArrayFormatFunc array);
 
+char *
+virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props);
+
 int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
                                           virJSONValuePtr objprops);