]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: qemu: Introduce helper for formatting command line from new object props
authorPeter Krempa <pkrempa@redhat.com>
Fri, 18 May 2018 12:04:21 +0000 (14:04 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 5 Jun 2018 06:13:59 +0000 (08:13 +0200)
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/libvirt_private.syms
src/util/virqemu.c
src/util/virqemu.h

index 23d55910931690c85d19b615ea22d12f2f0b9224..db241c9e94d8dd9786f7b9d267cc94cbe05c15cb 100644 (file)
@@ -2601,6 +2601,7 @@ virQEMUBuildCommandLineJSON;
 virQEMUBuildCommandLineJSONArrayBitmap;
 virQEMUBuildCommandLineJSONArrayNumbered;
 virQEMUBuildDriveCommandlineFromJSON;
+virQEMUBuildObjectCommandlineFromJSON;
 virQEMUBuildObjectCommandlineFromJSONType;
 virQEMUBuildQemuImgKeySecretOpts;
 
index fc4727e126d204ea66ae116be9cc682b2e3e43f2..1390b68b865750bf6a4be5e2bc4d6cc7ff58e738 100644 (file)
@@ -241,6 +241,29 @@ virQEMUBuildCommandLineJSON(virJSONValuePtr value,
 }
 
 
+static int
+virQEMUBuildObjectCommandlineFromJSONInternal(virBufferPtr buf,
+                                              const char *type,
+                                              const char *alias,
+                                              virJSONValuePtr props)
+{
+    if (!type || !alias) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("missing 'type' or 'alias' field of QOM 'object'"));
+        return -1;
+    }
+
+    virBufferAsprintf(buf, "%s,id=%s,", type, alias);
+
+    if (props &&
+        virQEMUBuildCommandLineJSON(props, buf,
+                                    virQEMUBuildCommandLineJSONArrayBitmap) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 char *
 virQEMUBuildObjectCommandlineFromJSONType(const char *type,
                                           const char *alias,
@@ -249,10 +272,7 @@ virQEMUBuildObjectCommandlineFromJSONType(const char *type,
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     char *ret = NULL;
 
-    virBufferAsprintf(&buf, "%s,id=%s,", type, alias);
-
-    if (virQEMUBuildCommandLineJSON(props, &buf,
-                                    virQEMUBuildCommandLineJSONArrayBitmap) < 0)
+    if (virQEMUBuildObjectCommandlineFromJSONInternal(&buf, type, alias, props) < 0)
         goto cleanup;
 
     if (virBufferCheckError(&buf) < 0)
@@ -266,6 +286,18 @@ virQEMUBuildObjectCommandlineFromJSONType(const char *type,
 }
 
 
+int
+virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
+                                      virJSONValuePtr objprops)
+{
+    const char *type = virJSONValueObjectGetString(objprops, "qom-type");
+    const char *alias = virJSONValueObjectGetString(objprops, "id");
+    virJSONValuePtr props = virJSONValueObjectGetObject(objprops, "props");
+
+    return virQEMUBuildObjectCommandlineFromJSONInternal(buf, type, alias, props);
+}
+
+
 char *
 virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef)
 {
index 0ef8e8d31dd500eb561e9cdf6e38b9c4a04ffa6c..0a4f4468f2ca639a0824cbeb30d5358d25f75e9f 100644 (file)
@@ -47,6 +47,9 @@ char *virQEMUBuildObjectCommandlineFromJSONType(const char *type,
                                                 const char *alias,
                                                 virJSONValuePtr props);
 
+int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
+                                          virJSONValuePtr objprops);
+
 char *virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr src);
 
 void virQEMUBuildBufferEscapeComma(virBufferPtr buf, const char *str);