提交 66877835 编写于 作者: J Ján Tomko

qemu: move TPM vaildation to qemuDomainDeviceDefValidateTPM

Simplify the command line formatter by complicating the validator.
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 0dd8202d
......@@ -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;
......
......@@ -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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册