On 6/21/22 4:11 AM, Michal Prívozník wrote: > 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 <crobi...@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. >
Heh, it's your code :) https://listman.redhat.com/archives/libvir-list/2020-November/211844.html But yes I agree. domcaps can be a detriment to apps if it's not reliable, and duplicating the qemuCaps checking is always going to lead to issues like this. It would be nice if we could normalize adding domcaps coverage for basic qemuCaps validation cases like this. Thanks, Cole