mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
qemu: move TPM vaildation to qemuDomainDeviceDefValidateTPM
Simplify the command line formatter by complicating the validator. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
0dd8202d35
commit
66877835ec
@ -10004,7 +10004,6 @@ qemuBuildTPMOpenBackendFDs(const char *tpmdev,
|
|||||||
static char *
|
static char *
|
||||||
qemuBuildTPMBackendStr(const virDomainDef *def,
|
qemuBuildTPMBackendStr(const virDomainDef *def,
|
||||||
virCommandPtr cmd,
|
virCommandPtr cmd,
|
||||||
virQEMUCapsPtr qemuCaps,
|
|
||||||
int *tpmfd,
|
int *tpmfd,
|
||||||
int *cancelfd,
|
int *cancelfd,
|
||||||
char **chardev)
|
char **chardev)
|
||||||
@ -10033,9 +10032,6 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
|
|||||||
|
|
||||||
switch (tpm->type) {
|
switch (tpm->type) {
|
||||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
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;
|
tpmdev = tpm->data.passthrough.source.data.file.path;
|
||||||
if (!(cancel_path = virTPMCreateCancelPath(tpmdev)))
|
if (!(cancel_path = virTPMCreateCancelPath(tpmdev)))
|
||||||
goto error;
|
goto error;
|
||||||
@ -10062,9 +10058,6 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||||
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_TPM_EMULATOR))
|
|
||||||
goto no_support;
|
|
||||||
|
|
||||||
virBufferAddLit(&buf, ",chardev=chrtpm");
|
virBufferAddLit(&buf, ",chardev=chrtpm");
|
||||||
|
|
||||||
if (virAsprintf(chardev, "socket,id=chrtpm,path=%s",
|
if (virAsprintf(chardev, "socket,id=chrtpm,path=%s",
|
||||||
@ -10081,12 +10074,6 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
|
|||||||
|
|
||||||
return virBufferContentAndReset(&buf);
|
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:
|
error:
|
||||||
VIR_FREE(devset);
|
VIR_FREE(devset);
|
||||||
VIR_FREE(cancel_path);
|
VIR_FREE(cancel_path);
|
||||||
@ -10110,7 +10097,7 @@ qemuBuildTPMCommandLine(virCommandPtr cmd,
|
|||||||
if (!def->tpm)
|
if (!def->tpm)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(optstr = qemuBuildTPMBackendStr(def, cmd, qemuCaps,
|
if (!(optstr = qemuBuildTPMBackendStr(def, cmd,
|
||||||
&tpmfd, &cancelfd,
|
&tpmfd, &cancelfd,
|
||||||
&chardev)))
|
&chardev)))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -6367,7 +6367,8 @@ qemuDomainDeviceDefValidateVsock(const virDomainVsockDef *vsock,
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm,
|
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 */
|
/* TPM 1.2 and 2 are not compatible, so we choose a specific version here */
|
||||||
if (tpm->version == VIR_DOMAIN_TPM_VERSION_DEFAULT)
|
if (tpm->version == VIR_DOMAIN_TPM_VERSION_DEFAULT)
|
||||||
@ -6389,7 +6390,31 @@ qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm,
|
|||||||
case VIR_DOMAIN_TPM_VERSION_LAST:
|
case VIR_DOMAIN_TPM_VERSION_LAST:
|
||||||
break;
|
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;
|
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;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_DEVICE_TPM:
|
case VIR_DOMAIN_DEVICE_TPM:
|
||||||
ret = qemuDomainDeviceDefValidateTPM(dev->data.tpm, def);
|
ret = qemuDomainDeviceDefValidateTPM(dev->data.tpm, def, qemuCaps);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_DEVICE_GRAPHICS:
|
case VIR_DOMAIN_DEVICE_GRAPHICS:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user