qemuBuildTPMDevStr() does TPM model validation that can be moved to
qemu_domain.c, allowing validation in domain define time. This patch
moves it to the existing qemuDomainDeviceDefValidateTPM() function.
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/qemu/qemu_command.c | 32 ++++----------------------------
src/qemu/qemu_domain.c | 24 ++++++++++++++++++++++++
2 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d1befdab90..b77003d1b1 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9029,34 +9029,11 @@ qemuBuildDomainLoaderCommandLine(virCommandPtr cmd,
static char *
-qemuBuildTPMDevStr(const virDomainDef *def,
- virQEMUCapsPtr qemuCaps)
+qemuBuildTPMDevStr(const virDomainDef *def)
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
const virDomainTPMDef *tpm = def->tpm;
const char *model = virDomainTPMModelTypeToString(tpm->model);
- virQEMUCapsFlags flag;
-
- switch (tpm->model) {
- case VIR_DOMAIN_TPM_MODEL_TIS:
- flag = QEMU_CAPS_DEVICE_TPM_TIS;
- break;
- case VIR_DOMAIN_TPM_MODEL_CRB:
- flag = QEMU_CAPS_DEVICE_TPM_CRB;
- break;
- case VIR_DOMAIN_TPM_MODEL_LAST:
- default:
- virReportEnumRangeError(virDomainTPMModel, tpm->model);
- return NULL;
- }
-
- if (!virQEMUCapsGet(qemuCaps, flag)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("The QEMU executable %s does not support TPM "
- "model %s"),
- def->emulator, model);
- return NULL;
- }
virBufferAsprintf(&buf, "%s,tpmdev=tpm-%s,id=%s",
model, tpm->info.alias, tpm->info.alias);
@@ -9150,8 +9127,7 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
static int
qemuBuildTPMCommandLine(virCommandPtr cmd,
- const virDomainDef *def,
- virQEMUCapsPtr qemuCaps)
+ const virDomainDef *def)
{
char *optstr;
g_autofree char *chardev = NULL;
@@ -9191,7 +9167,7 @@ qemuBuildTPMCommandLine(virCommandPtr cmd,
VIR_FREE(fdset);
}
- if (!(optstr = qemuBuildTPMDevStr(def, qemuCaps)))
+ if (!(optstr = qemuBuildTPMDevStr(def)))
return -1;
virCommandAddArgList(cmd, "-device", optstr, NULL);
@@ -9915,7 +9891,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
chardevStdioLogd) < 0)
return NULL;
- if (qemuBuildTPMCommandLine(cmd, def, qemuCaps) < 0)
+ if (qemuBuildTPMCommandLine(cmd, def) < 0)
return NULL;
if (qemuBuildInputCommandLine(cmd, def, qemuCaps) < 0)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3dba074c5c..f5369f5b36 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -7600,6 +7600,8 @@ qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
+ virQEMUCapsFlags flag;
+
/* TPM 1.2 and 2 are not compatible, so we choose a specific version here */
if (tpm->version == VIR_DOMAIN_TPM_VERSION_DEFAULT)
tpm->version = VIR_DOMAIN_TPM_VERSION_1_2;
@@ -7636,6 +7638,28 @@ qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm,
break;
}
+ switch (tpm->model) {
+ case VIR_DOMAIN_TPM_MODEL_TIS:
+ flag = QEMU_CAPS_DEVICE_TPM_TIS;
+ break;
+ case VIR_DOMAIN_TPM_MODEL_CRB:
+ flag = QEMU_CAPS_DEVICE_TPM_CRB;
+ break;
+ case VIR_DOMAIN_TPM_MODEL_LAST:
+ default:
+ virReportEnumRangeError(virDomainTPMModel, tpm->model);
+ return -1;
+ }
+
+ if (!virQEMUCapsGet(qemuCaps, flag)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("The QEMU executable %s does not support TPM "
+ "model %s"),
+ def->emulator,
+ virDomainTPMModelTypeToString(tpm->model));
+ return -1;
+ }
+
return 0;
no_support:
--
2.23.0