]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuBuildIOMMUCommandLine: Generate via JSON
authorPeter Krempa <pkrempa@redhat.com>
Mon, 11 Oct 2021 14:29:49 +0000 (16:29 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Oct 2021 18:54:53 +0000 (20:54 +0200)
QEMU declares the following types for fields we control:

  intremap=<OnOffAuto>   - on/off/auto (default: "auto")
  caching-mode=<bool>    -  (default: false)
  eim=<OnOffAuto>        - on/off/auto (default: "auto")
  device-iotlb=<bool>    -  (default: false)
  aw-bits=<uint8>        -  (default: 39)

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

index 56bf17b6b408f86738d9f71cfb8ab33bdb643381..8913110b00a7c070c9b1263b265cb53fec5095b1 100644 (file)
@@ -6486,7 +6486,8 @@ qemuBuildBootCommandLine(virCommand *cmd,
 
 static int
 qemuBuildIOMMUCommandLine(virCommand *cmd,
-                          const virDomainDef *def)
+                          const virDomainDef *def,
+                          virQEMUCaps *qemuCaps)
 {
     const virDomainIOMMUDef *iommu = def->iommu;
 
@@ -6495,31 +6496,22 @@ qemuBuildIOMMUCommandLine(virCommand *cmd,
 
     switch (iommu->model) {
     case VIR_DOMAIN_IOMMU_MODEL_INTEL: {
-        g_auto(virBuffer) opts = VIR_BUFFER_INITIALIZER;
+        g_autoptr(virJSONValue) props = NULL;
 
-        virBufferAddLit(&opts, "intel-iommu");
-        if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT) {
-            virBufferAsprintf(&opts, ",intremap=%s",
-                              virTristateSwitchTypeToString(iommu->intremap));
-        }
-        if (iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT) {
-            virBufferAsprintf(&opts, ",caching-mode=%s",
-                              virTristateSwitchTypeToString(iommu->caching_mode));
-        }
-        if (iommu->eim != VIR_TRISTATE_SWITCH_ABSENT) {
-            virBufferAsprintf(&opts, ",eim=%s",
-                              virTristateSwitchTypeToString(iommu->eim));
-        }
-        if (iommu->iotlb != VIR_TRISTATE_SWITCH_ABSENT) {
-            virBufferAsprintf(&opts, ",device-iotlb=%s",
-                              virTristateSwitchTypeToString(iommu->iotlb));
-        }
-        if (iommu->aw_bits > 0)
-            virBufferAsprintf(&opts, ",aw-bits=%d", iommu->aw_bits);
+        if (virJSONValueObjectCreate(&props,
+                                     "s:driver", "intel-iommu",
+                                     "S:intremap", qemuOnOffAuto(iommu->intremap),
+                                     "T:caching-mode", iommu->caching_mode,
+                                     "S:eim", qemuOnOffAuto(iommu->eim),
+                                     "T:device-iotlb", iommu->iotlb,
+                                     "z:aw-bits", iommu->aw_bits,
+                                     NULL) < 0)
+            return -1;
 
-        virCommandAddArg(cmd, "-device");
-        virCommandAddArgBuffer(cmd, &opts);
-        break;
+        if (qemuBuildDeviceCommandlineFromJSON(cmd, props, qemuCaps) < 0)
+            return -1;
+
+        return 0;
     }
 
     case VIR_DOMAIN_IOMMU_MODEL_SMMUV3:
@@ -10705,7 +10697,7 @@ qemuBuildCommandLine(virQEMUDriver *driver,
     if (qemuBuildBootCommandLine(cmd, def) < 0)
         return NULL;
 
-    if (qemuBuildIOMMUCommandLine(cmd, def) < 0)
+    if (qemuBuildIOMMUCommandLine(cmd, def, qemuCaps) < 0)
         return NULL;
 
     if (qemuBuildGlobalControllerCommandLine(cmd, def) < 0)