diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 5e05916b2308abcede91e6e27480ebb621d66699..3a4acb31665533fef26e551b9db5e68ff8243aee 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 8a3755c6fef6ad842816d8c534daf633db8b6665..d0722f8761b108278f6ef5a34ec5ac5c088cb94e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -6367,7 +6367,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) @@ -6389,7 +6390,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; } @@ -6830,7 +6855,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: