[libvirt PATCH 0/3] firmware: Small fixes and cleanups

Andrea Bolognani (3): vmx: Declare support for firmware autoselection conf: Fix virDomainDefOSValidate() qemu: Simplify handling of virTristateBool values src/conf/domain_validate.c | 6 +++--- src/qemu/qemu_firmware.c | 38 ++++++++++++++++---------------------- src/vmx/vmx.c | 1 + 3 files changed, 20 insertions(+), 25 deletions(-) -- 2.35.3

The feature was implemented in commits b4e34d1083bc and 9bb6e4e739fa but the corresponding feature flag was not set in the driver, so other parts of of libvirt wouldn't be able to know about it. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/vmx/vmx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index c391caa910..57a1622445 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -639,6 +639,7 @@ static virDomainDefParserConfig virVMXDomainDefParserConfig = { .domainPostParseCallback = virVMXDomainDefPostParse, .features = (VIR_DOMAIN_DEF_FEATURE_WIDE_SCSI | VIR_DOMAIN_DEF_FEATURE_NAME_SLASH | + VIR_DOMAIN_DEF_FEATURE_FW_AUTOSELECT | VIR_DOMAIN_DEF_FEATURE_NO_BOOT_ORDER), .defArch = VIR_ARCH_I686, }; -- 2.35.3

Even when the os.loader element is absent, we still have to validate that the user is not attempting to use firmware autoselection with a driver that doesn't implement the feature. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/conf/domain_validate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index f3910f08a4..61d4586580 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -1586,9 +1586,6 @@ static int virDomainDefOSValidate(const virDomainDef *def, virDomainXMLOption *xmlopt) { - if (!def->os.loader) - return 0; - if (def->os.firmware && !(xmlopt->config.features & VIR_DOMAIN_DEF_FEATURE_FW_AUTOSELECT)) { virReportError(VIR_ERR_XML_DETAIL, "%s", @@ -1596,6 +1593,9 @@ virDomainDefOSValidate(const virDomainDef *def, return -1; } + if (!def->os.loader) + return 0; + if (!def->os.loader->path && def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_NONE) { virReportError(VIR_ERR_XML_DETAIL, "%s", -- 2.35.3

We explicitly check whether the value is YES or NO, which makes it unnecessary to make sure it's not ABSENT beforehand. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/qemu/qemu_firmware.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index 51223faadf..e459ed9a6c 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -1081,31 +1081,25 @@ qemuFirmwareMatchDomain(const virDomainDef *def, if (def->os.firmwareFeatures) { reqSecureBoot = def->os.firmwareFeatures[VIR_DOMAIN_OS_DEF_FIRMWARE_FEATURE_SECURE_BOOT]; - if (reqSecureBoot != VIR_TRISTATE_BOOL_ABSENT) { - if (reqSecureBoot == VIR_TRISTATE_BOOL_YES && !supportsSecureBoot) { - VIR_DEBUG("User requested Secure Boot, firmware '%s' doesn't support it", - path); - return false; - } - - if (reqSecureBoot == VIR_TRISTATE_BOOL_NO && supportsSecureBoot) { - VIR_DEBUG("User refused Secure Boot, firmware '%s' supports it", path); - return false; - } + if (reqSecureBoot == VIR_TRISTATE_BOOL_YES && !supportsSecureBoot) { + VIR_DEBUG("User requested Secure Boot, firmware '%s' doesn't support it", + path); + return false; + } + if (reqSecureBoot == VIR_TRISTATE_BOOL_NO && supportsSecureBoot) { + VIR_DEBUG("User refused Secure Boot, firmware '%s' supports it", path); + return false; } reqEnrolledKeys = def->os.firmwareFeatures[VIR_DOMAIN_OS_DEF_FIRMWARE_FEATURE_ENROLLED_KEYS]; - if (reqEnrolledKeys != VIR_TRISTATE_BOOL_ABSENT) { - if (reqEnrolledKeys == VIR_TRISTATE_BOOL_YES && !hasEnrolledKeys) { - VIR_DEBUG("User requested Enrolled keys, firmware '%s' doesn't have them", - path); - return false; - } - - if (reqEnrolledKeys == VIR_TRISTATE_BOOL_NO && hasEnrolledKeys) { - VIR_DEBUG("User refused Enrolled keys, firmware '%s' has them", path); - return false; - } + if (reqEnrolledKeys == VIR_TRISTATE_BOOL_YES && !hasEnrolledKeys) { + VIR_DEBUG("User requested Enrolled keys, firmware '%s' doesn't have them", + path); + return false; + } + if (reqEnrolledKeys == VIR_TRISTATE_BOOL_NO && hasEnrolledKeys) { + VIR_DEBUG("User refused Enrolled keys, firmware '%s' has them", path); + return false; } } -- 2.35.3

On a Friday in 2022, Andrea Bolognani wrote:
Andrea Bolognani (3): vmx: Declare support for firmware autoselection conf: Fix virDomainDefOSValidate() qemu: Simplify handling of virTristateBool values
src/conf/domain_validate.c | 6 +++--- src/qemu/qemu_firmware.c | 38 ++++++++++++++++---------------------- src/vmx/vmx.c | 1 + 3 files changed, 20 insertions(+), 25 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Andrea Bolognani
-
Ján Tomko