]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_domain: Move TPM post parse code into qemuDomainTPMDefPostParse()
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 18 Jul 2022 07:10:12 +0000 (09:10 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 1 Aug 2022 15:35:51 +0000 (17:35 +0200)
In the qemuDomainDefPostParse() we aim to fill in top level
values, which require overall view of domain, or those parts of
configuration that are not a device in domain XML (e.g. vCPUs).
However, inside of qemuDomainDefTPMsPostParse(), which is called
from aforementioned function, we do two tings:

  1) fill in missing info (TPM version), and
  2) validate TPM definition.

Now, if 1) is moved into qemuDomainTPMDefPostParse() (the device
post parse callback), then 2) can be moved into validation step.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_domain.c

index 8d96d7b084f6464e9e5fc8f9007ef93312e9dc17..873b8b309c483987b19edbdb7494ccc17b9ab53e 100644 (file)
@@ -4593,17 +4593,6 @@ qemuDomainDefTPMsPostParse(virDomainDef *def)
     for (i = 0; i < def->ntpms; i++) {
         virDomainTPMDef *tpm = def->tpms[i];
 
-        /* TPM 1.2 and 2 are not compatible, so we choose a specific version here */
-        if (tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR &&
-            tpm->data.emulator.version == VIR_DOMAIN_TPM_VERSION_DEFAULT) {
-            if (tpm->model == VIR_DOMAIN_TPM_MODEL_SPAPR ||
-                tpm->model == VIR_DOMAIN_TPM_MODEL_CRB ||
-                qemuDomainIsARMVirt(def))
-                tpm->data.emulator.version = VIR_DOMAIN_TPM_VERSION_2_0;
-            else
-                tpm->data.emulator.version = VIR_DOMAIN_TPM_VERSION_1_2;
-        }
-
         if (tpm->model == VIR_DOMAIN_TPM_MODEL_SPAPR_PROXY) {
             if (proxyTPM) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -5807,15 +5796,26 @@ qemuDomainHostdevDefPostParse(virDomainHostdevDef *hostdev,
 
 static int
 qemuDomainTPMDefPostParse(virDomainTPMDef *tpm,
-                          virArch arch)
+                          const virDomainDef *def)
 {
     if (tpm->model == VIR_DOMAIN_TPM_MODEL_DEFAULT) {
-        if (ARCH_IS_PPC64(arch))
+        if (ARCH_IS_PPC64(def->os.arch))
             tpm->model = VIR_DOMAIN_TPM_MODEL_SPAPR;
         else
             tpm->model = VIR_DOMAIN_TPM_MODEL_TIS;
     }
 
+    /* TPM 1.2 and 2 are not compatible, so we choose a specific version here */
+    if (tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR &&
+        tpm->data.emulator.version == VIR_DOMAIN_TPM_VERSION_DEFAULT) {
+        if (tpm->model == VIR_DOMAIN_TPM_MODEL_SPAPR ||
+            tpm->model == VIR_DOMAIN_TPM_MODEL_CRB ||
+            qemuDomainIsARMVirt(def))
+            tpm->data.emulator.version = VIR_DOMAIN_TPM_VERSION_2_0;
+        else
+            tpm->data.emulator.version = VIR_DOMAIN_TPM_VERSION_1_2;
+    }
+
     return 0;
 }
 
@@ -5942,7 +5942,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDef *dev,
         break;
 
     case VIR_DOMAIN_DEVICE_TPM:
-        ret = qemuDomainTPMDefPostParse(dev->data.tpm, def->os.arch);
+        ret = qemuDomainTPMDefPostParse(dev->data.tpm, def);
         break;
 
     case VIR_DOMAIN_DEVICE_MEMORY: