conf: domain: Clarify nvram/loader format logic

Restructure the code to assign first (as this is simpler to refactor in
the future) and avoid mixing implicit value checks with explicit ones by
checking for _NONE.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2024-08-19 16:57:55 +02:00
parent d57630c282
commit a448d4a18a

View File

@ -17153,15 +17153,16 @@ virDomainLoaderDefParseXMLNvram(virDomainLoaderDef *loader,
&format, VIR_STORAGE_FILE_NONE) < 0) {
return -1;
}
if (format &&
format != VIR_STORAGE_FILE_RAW &&
format != VIR_STORAGE_FILE_QCOW2) {
src->format = format;
if (src->format != VIR_STORAGE_FILE_NONE &&
src->format != VIR_STORAGE_FILE_RAW &&
src->format != VIR_STORAGE_FILE_QCOW2) {
virReportError(VIR_ERR_XML_ERROR,
_("Unsupported nvram format '%1$s'"),
virStorageFileFormatTypeToString(format));
virStorageFileFormatTypeToString(src->format));
return -1;
}
src->format = format;
if ((typePresent = virXMLPropEnum(nvramNode, "type",
virStorageTypeFromString, VIR_XML_PROP_NONE,
@ -17243,15 +17244,17 @@ virDomainLoaderDefParseXMLLoader(virDomainLoaderDef *loader,
&format, VIR_STORAGE_FILE_NONE) < 0) {
return -1;
}
if (format &&
format != VIR_STORAGE_FILE_RAW &&
format != VIR_STORAGE_FILE_QCOW2) {
loader->format = format;
if (loader->format != VIR_STORAGE_FILE_NONE &&
loader->format != VIR_STORAGE_FILE_RAW &&
loader->format != VIR_STORAGE_FILE_QCOW2) {
virReportError(VIR_ERR_XML_ERROR,
_("Unsupported loader format '%1$s'"),
virStorageFileFormatTypeToString(format));
virStorageFileFormatTypeToString(loader->format));
return -1;
}
loader->format = format;
return 0;
}