]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: command: Generate commandline of 'masterKey0' secret via JSON
authorPeter Krempa <pkrempa@redhat.com>
Thu, 26 Nov 2020 18:07:03 +0000 (19:07 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 12 Mar 2021 15:15:05 +0000 (16:15 +0100)
While the 'masterKey0' secret object will never be hotplugged we want to
generate it through JSON so that we'll be able to validate all
parameters of '-object' against the QAPI schema once 'object-add' is
qapified in qemu.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c

index a28672e027441d08f7573648c218a69d2ed81c80..170d28f6fc94fad7bbec2ba21b8d6988381718b7 100644 (file)
@@ -210,6 +210,7 @@ qemuBuildMasterKeyCommandLine(virCommandPtr cmd,
     g_autofree char *alias = NULL;
     g_autofree char *path = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+    g_autoptr(virJSONValue) props = NULL;
 
     /* If the -object secret does not exist, then just return. This just
      * means the domain won't be able to use a secret master key and is
@@ -231,9 +232,16 @@ qemuBuildMasterKeyCommandLine(virCommandPtr cmd,
     if (!(path = qemuDomainGetMasterKeyFilePath(priv->libDir)))
         return -1;
 
+    if (qemuMonitorCreateObjectProps(&props, "secret", alias,
+                                     "s:format", "raw",
+                                     "s:file", path,
+                                     NULL) < 0)
+        return -1;
+
+    if (virQEMUBuildObjectCommandlineFromJSON(&buf, props) < 0)
+        return -1;
+
     virCommandAddArg(cmd, "-object");
-    virBufferAsprintf(&buf, "secret,id=%s,format=raw,file=", alias);
-    virQEMUBuildBufferEscapeComma(&buf, path);
     virCommandAddArgBuffer(cmd, &buf);
 
     return 0;