qemu: Make firmware parsing failures non-fatal

At the moment, any kind of issue being detected in any of the
firmware descriptor files will result in the entire process
being aborted.

In particular, installing a build of edk2 for an architecture
that libvirt doesn't yet know about, for example loongarch64,
will break most firmware-related functionality: it will no
longer be possible to define new EFI VMs, start existing ones,
or even just obtain the domcapabilities for any architecture.

This is obviously unnecessarily harsh. Adopt a more relaxed
approach and simply ignore the firmware descriptors that we
are unable to parse correctly.

https://bugzilla.redhat.com/show_bug.cgi?id=2258946

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Andrea Bolognani 2024-02-29 15:43:45 +01:00
parent e0438b2e80
commit e4abb5f0fd

View File

@ -307,9 +307,7 @@ qemuFirmwareInterfaceParse(const char *path,
size_t i; size_t i;
if (!(interfacesJSON = virJSONValueObjectGetArray(doc, "interface-types"))) { if (!(interfacesJSON = virJSONValueObjectGetArray(doc, "interface-types"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("failed to get interface-types from '%s'", path);
_("failed to get interface-types from '%1$s'"),
path);
return -1; return -1;
} }
@ -323,9 +321,7 @@ qemuFirmwareInterfaceParse(const char *path,
int tmp; int tmp;
if ((tmp = qemuFirmwareOSInterfaceTypeFromString(tmpStr)) <= 0) { if ((tmp = qemuFirmwareOSInterfaceTypeFromString(tmpStr)) <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("unknown interface type: '%s'", tmpStr);
_("unknown interface type: '%1$s'"),
tmpStr);
return -1; return -1;
} }
@ -351,18 +347,14 @@ qemuFirmwareFlashFileParse(const char *path,
const char *format; const char *format;
if (!(filename = virJSONValueObjectGetString(doc, "filename"))) { if (!(filename = virJSONValueObjectGetString(doc, "filename"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("missing 'filename' in '%s'", path);
_("missing 'filename' in '%1$s'"),
path);
return -1; return -1;
} }
flash->filename = g_strdup(filename); flash->filename = g_strdup(filename);
if (!(format = virJSONValueObjectGetString(doc, "format"))) { if (!(format = virJSONValueObjectGetString(doc, "format"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("missing 'format' in '%s'", path);
_("missing 'format' in '%1$s'"),
path);
return -1; return -1;
} }
@ -388,24 +380,19 @@ qemuFirmwareMappingFlashParse(const char *path,
const char *modestr = virJSONValueGetString(mode); const char *modestr = virJSONValueGetString(mode);
int modeval; int modeval;
if (!modestr) { if (!modestr) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", VIR_DEBUG("Firmware flash mode value was malformed");
_("Firmware flash mode value was malformed"));
return -1; return -1;
} }
modeval = qemuFirmwareFlashModeTypeFromString(modestr); modeval = qemuFirmwareFlashModeTypeFromString(modestr);
if (modeval < 0) { if (modeval < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("Firmware flash mode value '%s' unexpected", modestr);
_("Firmware flash mode value '%1$s' unexpected"),
modestr);
return -1; return -1;
} }
flash->mode = modeval; flash->mode = modeval;
} }
if (!(executable = virJSONValueObjectGet(doc, "executable"))) { if (!(executable = virJSONValueObjectGet(doc, "executable"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("missing 'executable' in '%s'", path);
_("missing 'executable' in '%1$s'"),
path);
return -1; return -1;
} }
@ -414,9 +401,7 @@ qemuFirmwareMappingFlashParse(const char *path,
if (flash->mode == QEMU_FIRMWARE_FLASH_MODE_SPLIT) { if (flash->mode == QEMU_FIRMWARE_FLASH_MODE_SPLIT) {
if (!(nvram_template = virJSONValueObjectGet(doc, "nvram-template"))) { if (!(nvram_template = virJSONValueObjectGet(doc, "nvram-template"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("missing 'nvram-template' in '%s'", path);
_("missing 'nvram-template' in '%1$s'"),
path);
return -1; return -1;
} }
@ -436,9 +421,7 @@ qemuFirmwareMappingKernelParse(const char *path,
const char *filename; const char *filename;
if (!(filename = virJSONValueObjectGetString(doc, "filename"))) { if (!(filename = virJSONValueObjectGetString(doc, "filename"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("missing 'filename' in '%s'", path);
_("missing 'filename' in '%1$s'"),
path);
return -1; return -1;
} }
@ -456,9 +439,7 @@ qemuFirmwareMappingMemoryParse(const char *path,
const char *filename; const char *filename;
if (!(filename = virJSONValueObjectGetString(doc, "filename"))) { if (!(filename = virJSONValueObjectGetString(doc, "filename"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("missing 'filename' in '%s'", path);
_("missing 'filename' in '%1$s'"),
path);
return -1; return -1;
} }
@ -478,23 +459,17 @@ qemuFirmwareMappingParse(const char *path,
int tmp; int tmp;
if (!(mapping = virJSONValueObjectGet(doc, "mapping"))) { if (!(mapping = virJSONValueObjectGet(doc, "mapping"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("missing mapping in '%s'", path);
_("missing mapping in '%1$s'"),
path);
return -1; return -1;
} }
if (!(deviceStr = virJSONValueObjectGetString(mapping, "device"))) { if (!(deviceStr = virJSONValueObjectGetString(mapping, "device"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("missing device type in '%s'", path);
_("missing device type in '%1$s'"),
path);
return -1; return -1;
} }
if ((tmp = qemuFirmwareDeviceTypeFromString(deviceStr)) <= 0) { if ((tmp = qemuFirmwareDeviceTypeFromString(deviceStr)) <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("unknown device type in '%s'", path);
_("unknown device type in '%1$s'"),
path);
return -1; return -1;
} }
@ -535,9 +510,7 @@ qemuFirmwareTargetParse(const char *path,
int ret = -1; int ret = -1;
if (!(targetsJSON = virJSONValueObjectGetArray(doc, "targets"))) { if (!(targetsJSON = virJSONValueObjectGetArray(doc, "targets"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("failed to get targets from '%s'", path);
_("failed to get targets from '%1$s'"),
path);
return -1; return -1;
} }
@ -556,23 +529,17 @@ qemuFirmwareTargetParse(const char *path,
t = g_new0(qemuFirmwareTarget, 1); t = g_new0(qemuFirmwareTarget, 1);
if (!(architectureStr = virJSONValueObjectGetString(item, "architecture"))) { if (!(architectureStr = virJSONValueObjectGetString(item, "architecture"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("missing 'architecture' in '%s'", path);
_("missing 'architecture' in '%1$s'"),
path);
goto cleanup; goto cleanup;
} }
if ((t->architecture = virQEMUCapsArchFromString(architectureStr)) == VIR_ARCH_NONE) { if ((t->architecture = virQEMUCapsArchFromString(architectureStr)) == VIR_ARCH_NONE) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("unknown architecture '%s'", architectureStr);
_("unknown architecture '%1$s'"),
architectureStr);
goto cleanup; goto cleanup;
} }
if (!(machines = virJSONValueObjectGetArray(item, "machines"))) { if (!(machines = virJSONValueObjectGetArray(item, "machines"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("missing 'machines' in '%s'", path);
_("missing 'machines' in '%1$s'"),
path);
goto cleanup; goto cleanup;
} }
@ -617,9 +584,7 @@ qemuFirmwareFeatureParse(const char *path,
size_t i; size_t i;
if (!(featuresJSON = virJSONValueObjectGetArray(doc, "features"))) { if (!(featuresJSON = virJSONValueObjectGetArray(doc, "features"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("failed to get features from '%s'", path);
_("failed to get features from '%1$s'"),
path);
return -1; return -1;
} }
@ -661,9 +626,7 @@ qemuFirmwareParse(const char *path)
return NULL; return NULL;
if (!(doc = virJSONValueFromString(cont))) { if (!(doc = virJSONValueFromString(cont))) {
virReportError(VIR_ERR_INTERNAL_ERROR, VIR_DEBUG("unable to parse json file '%s'", path);
_("unable to parse json file '%1$s'"),
path);
return NULL; return NULL;
} }
@ -1579,7 +1542,7 @@ qemuFirmwareFetchParsedConfigs(bool privileged,
qemuFirmware *firmware = qemuFirmwareParse(*currentPath); qemuFirmware *firmware = qemuFirmwareParse(*currentPath);
if (!firmware) if (!firmware)
goto error; continue;
VIR_APPEND_ELEMENT(firmwares, nfirmwares, firmware); VIR_APPEND_ELEMENT(firmwares, nfirmwares, firmware);
@ -1597,15 +1560,6 @@ qemuFirmwareFetchParsedConfigs(bool privileged,
} }
return nfirmwares; return nfirmwares;
error:
while (nfirmwares > 0)
qemuFirmwareFree(firmwares[--nfirmwares]);
VIR_FREE(firmwares);
while (npaths > 0)
VIR_FREE(paths[--npaths]);
VIR_FREE(paths);
return -1;
} }