[PATCH 05/19] qemu: move TPM vaildation to qemuDomainDeviceDefValidateTPM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Simplify the command line formatter by complicating the validator.

Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/qemu/qemu_command.c | 15 +--------------
 src/qemu/qemu_domain.c  | 29 +++++++++++++++++++++++++++--
 2 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 5e05916b23..3a4acb3166 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -10004,7 +10004,6 @@ qemuBuildTPMOpenBackendFDs(const char *tpmdev,
 static char *
 qemuBuildTPMBackendStr(const virDomainDef *def,
                        virCommandPtr cmd,
-                       virQEMUCapsPtr qemuCaps,
                        int *tpmfd,
                        int *cancelfd,
                        char **chardev)
@@ -10033,9 +10032,6 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
 
     switch (tpm->type) {
     case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
-        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_TPM_PASSTHROUGH))
-            goto no_support;
-
         tpmdev = tpm->data.passthrough.source.data.file.path;
         if (!(cancel_path = virTPMCreateCancelPath(tpmdev)))
             goto error;
@@ -10062,9 +10058,6 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
 
         break;
     case VIR_DOMAIN_TPM_TYPE_EMULATOR:
-        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_TPM_EMULATOR))
-            goto no_support;
-
         virBufferAddLit(&buf, ",chardev=chrtpm");
 
         if (virAsprintf(chardev, "socket,id=chrtpm,path=%s",
@@ -10081,12 +10074,6 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
 
     return virBufferContentAndReset(&buf);
 
- no_support:
-    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                   _("The QEMU executable %s does not support TPM "
-                     "backend type %s"),
-                   def->emulator, type);
-
  error:
     VIR_FREE(devset);
     VIR_FREE(cancel_path);
@@ -10110,7 +10097,7 @@ qemuBuildTPMCommandLine(virCommandPtr cmd,
     if (!def->tpm)
         return 0;
 
-    if (!(optstr = qemuBuildTPMBackendStr(def, cmd, qemuCaps,
+    if (!(optstr = qemuBuildTPMBackendStr(def, cmd,
                                           &tpmfd, &cancelfd,
                                           &chardev)))
         return -1;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index a06672333c..e34d03191d 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6384,7 +6384,8 @@ qemuDomainDeviceDefValidateVsock(const virDomainVsockDef *vsock,
 
 static int
 qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm,
-                               const virDomainDef *def ATTRIBUTE_UNUSED)
+                               const virDomainDef *def,
+                               virQEMUCapsPtr qemuCaps)
 {
     /* TPM 1.2 and 2 are not compatible, so we choose a specific version here */
     if (tpm->version == VIR_DOMAIN_TPM_VERSION_DEFAULT)
@@ -6406,7 +6407,31 @@ qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm,
     case VIR_DOMAIN_TPM_VERSION_LAST:
         break;
     }
+
+    switch (tpm->type) {
+    case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_TPM_PASSTHROUGH))
+            goto no_support;
+        break;
+
+    case VIR_DOMAIN_TPM_TYPE_EMULATOR:
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_TPM_EMULATOR))
+            goto no_support;
+
+        break;
+    case VIR_DOMAIN_TPM_TYPE_LAST:
+        break;
+    }
+
     return 0;
+
+ no_support:
+    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                   _("The QEMU executable %s does not support TPM "
+                     "backend type %s"),
+                   def->emulator,
+                   virDomainTPMBackendTypeToString(tpm->type));
+    return -1;
 }
 
 
@@ -6847,7 +6872,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
         break;
 
     case VIR_DOMAIN_DEVICE_TPM:
-        ret = qemuDomainDeviceDefValidateTPM(dev->data.tpm, def);
+        ret = qemuDomainDeviceDefValidateTPM(dev->data.tpm, def, qemuCaps);
         break;
 
     case VIR_DOMAIN_DEVICE_GRAPHICS:
-- 
2.19.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux