]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuBuildControllerSCSIDevStr: Format via JSON properties
authorPeter Krempa <pkrempa@redhat.com>
Mon, 4 Oct 2021 20:53:48 +0000 (22:53 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Oct 2021 08:26:05 +0000 (10:26 +0200)
Internally format the SCSI controller properties into JSON, but convert
it back to a string so that we for now change just the SCSI controller.

The change in tests is expected as the 'reg' field for a spapr-vio
address is expected to be a number:

  $ qemu-system-ppc64 -device spapr-vscsi,help
  spapr-vscsi options:
    reg=<uint32>           -  (default: 4294967295)

The hand-rolled generator used hex representation but that will not be
possible on the monitor via JSON.

The properties of 'virtio-scsi' have following types according to QEMU:

  iothread=<link<iothread>>
  num_queues=<uint32>    -  (default: 4294967295)
  cmd_per_lun=<uint32>   -  (default: 128)
  max_sectors=<uint32>   -  (default: 65535)
  ioeventfd=<bool>       - on/off (default: true)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c
tests/qemuxml2argvdata/disk-scsi.x86_64-latest.args
tests/qemuxml2argvdata/pseries-vio-user-assigned.args
tests/qemuxml2argvdata/pseries-vio.args
tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args

index 6afa4b54e7148ea13cf63ae3da68f95d0df2f99b..a51dbcb742279efc962aebd57fcd577c1e08ef14 100644 (file)
@@ -1311,17 +1311,6 @@ qemuBuildRomProps(virJSONValue *props,
 }
 
 
-static int
-qemuBuildIoEventFdStr(virBuffer *buf,
-                      virTristateSwitch use,
-                      virQEMUCaps *qemuCaps G_GNUC_UNUSED)
-{
-    if (use)
-        virBufferAsprintf(buf, ",ioeventfd=%s",
-                          virTristateSwitchTypeToString(use));
-    return 0;
-}
-
 /**
  * qemuBuildSecretInfoProps:
  * @secinfo: pointer to the secret info object
@@ -2875,40 +2864,37 @@ qemuBuildUSBControllerDevStr(const virDomainDef *domainDef,
 }
 
 
-static char *
-qemuBuildControllerSCSIDevStr(const virDomainDef *domainDef,
-                              virDomainControllerDef *def,
-                              virQEMUCaps *qemuCaps)
+static virJSONValue *
+qemuBuildControllerSCSIDevProps(const virDomainDef *domainDef,
+                                virDomainControllerDef *def,
+                                virQEMUCaps *qemuCaps)
 {
-    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+    g_autoptr(virJSONValue) props = NULL;
+    g_autofree char *iothread = NULL;
     const char *driver = NULL;
 
     switch ((virDomainControllerModelSCSI) def->model) {
     case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI:
     case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_TRANSITIONAL:
     case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_NON_TRANSITIONAL:
-        if (qemuBuildVirtioDevStr(&buf, qemuCaps, VIR_DOMAIN_DEVICE_CONTROLLER, def) < 0) {
+        if (!(props = qemuBuildVirtioDevProps(VIR_DOMAIN_DEVICE_CONTROLLER, def,
+                                              qemuCaps)))
             return NULL;
-        }
-
-        if (def->iothread) {
-            virBufferAsprintf(&buf, ",iothread=iothread%u",
-                              def->iothread);
-        }
-
-        virBufferAsprintf(&buf, ",id=%s", def->info.alias);
 
-        if (def->queues)
-            virBufferAsprintf(&buf, ",num_queues=%u", def->queues);
+        if (def->iothread > 0)
+            iothread = g_strdup_printf("iothread%u", def->iothread);
 
-        if (def->cmd_per_lun)
-            virBufferAsprintf(&buf, ",cmd_per_lun=%u", def->cmd_per_lun);
-
-        if (def->max_sectors)
-            virBufferAsprintf(&buf, ",max_sectors=%u", def->max_sectors);
-
-        qemuBuildIoEventFdStr(&buf, def->ioeventfd, qemuCaps);
+        if (virJSONValueObjectAdd(props,
+                                  "S:iothread", iothread,
+                                  "s:id", def->info.alias,
+                                  "p:num_queues", def->queues,
+                                  "p:cmd_per_lun", def->cmd_per_lun,
+                                  "p:max_sectors", def->max_sectors,
+                                  "T:ioeventfd", def->ioeventfd,
+                                  NULL) < 0)
+            return NULL;
         break;
+
     case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC:
         driver = "lsi";
         break;
@@ -2945,13 +2931,18 @@ qemuBuildControllerSCSIDevStr(const virDomainDef *domainDef,
         return NULL;
     }
 
-    if (driver)
-        virBufferAsprintf(&buf, "%s,id=%s", driver, def->info.alias);
+    if (driver) {
+        if (virJSONValueObjectCreate(&props,
+                                     "s:driver", driver,
+                                     "s:id", def->info.alias,
+                                     NULL) < 0)
+            return NULL;
+    }
 
-    if (qemuBuildDeviceAddressStr(&buf, domainDef, &def->info) < 0)
+    if (qemuBuildDeviceAddressProps(props, domainDef, &def->info) < 0)
         return NULL;
 
-    return virBufferContentAndReset(&buf);
+    return g_steal_pointer(&props);
 }
 
 
@@ -3067,13 +3058,25 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
                           char **devstr)
 {
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+    g_autoptr(virJSONValue) props = NULL;
+    const char *driver = NULL;
 
     *devstr = NULL;
 
     switch ((virDomainControllerType)def->type) {
     case VIR_DOMAIN_CONTROLLER_TYPE_SCSI:
-        if (!(*devstr = qemuBuildControllerSCSIDevStr(domainDef, def, qemuCaps)))
+        if (!(props = qemuBuildControllerSCSIDevProps(domainDef, def, qemuCaps)))
+            return -1;
+
+        driver = virJSONValueObjectGetString(props, "driver");
+
+        virBufferAsprintf(&buf, "%s,", driver);
+
+        if (virQEMUBuildCommandLineJSON(props, &buf, "driver", NULL) < 0)
             return -1;
+
+        *devstr = virBufferContentAndReset(&buf);
+
         return 0;
 
     case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL:
index d9971582ac68529bac3110b35963ab5d324a613d..79b66da8812e0cc672989272dc06464d475a013b 100644 (file)
@@ -30,7 +30,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
 -device lsi,id=scsi0,bus=pci.0,addr=0x2 \
 -device megasas,id=scsi1,bus=pci.0,addr=0x3 \
 -device mptsas1068,id=scsi2,bus=pci.0,addr=0x4 \
--device spapr-vscsi,id=scsi3,reg=0x00002000 \
+-device spapr-vscsi,id=scsi3,reg=8192 \
 -device pvscsi,id=scsi4,bus=pci.0,addr=0x5 \
 -blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1","node-name":"libvirt-6-storage","auto-read-only":true,"discard":"unmap"}' \
 -blockdev '{"node-name":"libvirt-6-format","read-only":false,"driver":"raw","file":"libvirt-6-storage"}' \
index 5295cfaca4c2ab34dd6529c1712e6fcf10ea25f4..dfc3ad0d1bbba6b18e1d2a0bde7757fc5dafb6af 100644 (file)
@@ -24,8 +24,8 @@ QEMU_AUDIO_DRV=none \
 -rtc base=utc \
 -no-shutdown \
 -boot strict=on \
--device spapr-vscsi,id=scsi0,reg=0x00002000 \
--device spapr-vscsi,id=scsi1,reg=0x30000000 \
+-device spapr-vscsi,id=scsi0,reg=8192 \
+-device spapr-vscsi,id=scsi1,reg=805306368 \
 -usb \
 -drive file=/tmp/scsidisk.img,format=raw,if=none,id=drive-scsi1-0-0-0 \
 -device scsi-hd,bus=scsi1.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi1-0-0-0,id=scsi1-0-0-0,bootindex=1 \
index f179e89cd20ea1c9baf81a97e324818d62a51266..a8e18fae5a9d319e1d166792dfc3d57487c2671b 100644 (file)
@@ -24,8 +24,8 @@ QEMU_AUDIO_DRV=none \
 -rtc base=utc \
 -no-shutdown \
 -boot strict=on \
--device spapr-vscsi,id=scsi0,reg=0x00002000 \
--device spapr-vscsi,id=scsi1,reg=0x00003000 \
+-device spapr-vscsi,id=scsi0,reg=8192 \
+-device spapr-vscsi,id=scsi1,reg=12288 \
 -usb \
 -drive file=/tmp/scsidisk.img,format=raw,if=none,id=drive-scsi1-0-0-0 \
 -device scsi-hd,bus=scsi1.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi1-0-0-0,id=scsi1-0-0-0,bootindex=1 \
index 29151a0084454e5e32d165b4c210a686249728d9..04d632c091047f46fb8abad23e40df7eb2f813ed 100644 (file)
@@ -26,8 +26,8 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-TPM-VM/.config \
 -no-shutdown \
 -boot menu=on,strict=on \
 -device pci-ohci,id=usb,bus=pci.0,addr=0x1 \
--device spapr-vscsi,id=scsi0,reg=0x00002000 \
--device spapr-vscsi,id=scsi1,reg=0x00003000 \
+-device spapr-vscsi,id=scsi0,reg=8192 \
+-device spapr-vscsi,id=scsi1,reg=12288 \
 -blockdev '{"driver":"file","filename":"/tmp/scsidisk.img","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
 -blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}' \
 -device scsi-hd,bus=scsi1.0,channel=0,scsi-id=0,lun=0,device_id=drive-scsi1-0-0-0,drive=libvirt-1-format,id=scsi1-0-0-0,bootindex=1 \