]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuBuildFloppyCommandLineControllerOptionsExplicit: Generate via JSON
authorPeter Krempa <pkrempa@redhat.com>
Mon, 11 Oct 2021 19:45:25 +0000 (21:45 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Oct 2021 18:54:53 +0000 (20:54 +0200)
QEMU declares the bootindex types as:

  bootindexA=<int32>
  bootindexB=<int32>

The driveA/driveB parameters were deprecated and removed in qemu-6.0.
We'll keep them for compatibility, but they are not used with -blockdev.

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

index 665cd739ec441596c3412ac8d1f0b44f7f7a7f5f..3b2f88bcb9d7b52fd822bf112bba2708ff6ca1f1 100644 (file)
@@ -2183,32 +2183,29 @@ qemuBuildFloppyCommandLineControllerOptionsImplicit(virCommand *cmd,
 }
 
 
-static void
+static int
 qemuBuildFloppyCommandLineControllerOptionsExplicit(virCommand *cmd,
                                                     unsigned int bootindexA,
                                                     unsigned int bootindexB,
                                                     const char *backendA,
-                                                    const char *backendB)
+                                                    const char *backendB,
+                                                    virQEMUCaps *qemuCaps)
 {
-    g_auto(virBuffer) fdc_opts = VIR_BUFFER_INITIALIZER;
-
-    virBufferAddLit(&fdc_opts, "isa-fdc,");
-
-    if (backendA)
-        virBufferAsprintf(&fdc_opts, "driveA=%s,", backendA);
-
-    if (bootindexA > 0)
-        virBufferAsprintf(&fdc_opts, "bootindexA=%u,", bootindexA);
+    g_autoptr(virJSONValue) props = NULL;
 
-    if (backendB)
-        virBufferAsprintf(&fdc_opts, "driveB=%s,", backendB);
+    if (virJSONValueObjectCreate(&props,
+                                 "s:driver", "isa-fdc",
+                                 "S:driveA", backendA,
+                                 "p:bootindexA", bootindexA,
+                                 "S:driveB", backendB,
+                                 "p:bootindexB", bootindexB,
+                                 NULL) < 0)
+        return -1;
 
-    if (bootindexB > 0)
-        virBufferAsprintf(&fdc_opts, "bootindexB=%u,", bootindexB);
+    if (qemuBuildDeviceCommandlineFromJSON(cmd, props, qemuCaps) < 0)
+        return -1;
 
-    virBufferTrim(&fdc_opts, ",");
-    virCommandAddArg(cmd, "-device");
-    virCommandAddArgBuffer(cmd, &fdc_opts);
+    return 0;
 }
 
 
@@ -2251,11 +2248,13 @@ qemuBuildFloppyCommandLineControllerOptions(virCommand *cmd,
         return 0;
 
     if (qemuDomainNeedsFDC(def)) {
-        qemuBuildFloppyCommandLineControllerOptionsExplicit(cmd,
-                                                            bootindexA,
-                                                            bootindexB,
-                                                            backendA,
-                                                            backendB);
+        if (qemuBuildFloppyCommandLineControllerOptionsExplicit(cmd,
+                                                                bootindexA,
+                                                                bootindexB,
+                                                                backendA,
+                                                                backendB,
+                                                                qemuCaps) < 0)
+            return -1;
     } else {
         qemuBuildFloppyCommandLineControllerOptionsImplicit(cmd,
                                                             bootindexA,