[PATCH 4/4] qemu: validate: use domcaps for tpm validation
Michal Prívozník
mprivozn at redhat.com
Tue Jun 21 08:11:42 UTC 2022
On 6/18/22 20:32, Cole Robinson wrote:
> Replace tpm->type and tpm->model qemuCaps validation with the
> similar logic in domcaps.
>
> Signed-off-by: Cole Robinson <crobinso at redhat.com>
> ---
> src/qemu/qemu_validate.c | 71 ++++++++++------------------------------
> 1 file changed, 17 insertions(+), 54 deletions(-)
>
> diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
> index db47fcaa9c..39210ba65b 100644
> --- a/src/qemu/qemu_validate.c
> +++ b/src/qemu/qemu_validate.c
> @@ -4750,7 +4750,7 @@ qemuValidateDomainDeviceDefTPM(virDomainTPMDef *tpm,
> const virDomainDef *def,
> virQEMUCaps *qemuCaps)
> {
> - virQEMUCapsFlags flag;
> + virDomainCapsDeviceTPM tpmCaps = { 0 };
>
> switch (tpm->version) {
> case VIR_DOMAIN_TPM_VERSION_1_2:
> @@ -4781,57 +4781,28 @@ qemuValidateDomainDeviceDefTPM(virDomainTPMDef *tpm,
> 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;
> + virQEMUCapsFillDomainDeviceTPMCaps(qemuCaps, &tpmCaps);
>
> - break;
> - case VIR_DOMAIN_TPM_TYPE_LAST:
> - break;
> + if (!VIR_DOMAIN_CAPS_ENUM_IS_SET(tpmCaps.backendModel, tpm->type)) {
> + virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> + _("The QEMU executable %s does not support TPM "
> + "backend type %s"),
> + def->emulator,
> + virDomainTPMBackendTypeToString(tpm->type));
Whoa, very nice idea! And looking around the file I can see it used
already. How could this slipped by me? I mean, the more I think about it
the more possibilities for code deduplication I see. And on the flip
side - we would be motivated to keep domcaps on the bleeding edge.
Michal
More information about the libvir-list
mailing list