[PATCH 04/13] conf: domain: Clarify nvram/loader format logic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6d7dee7956..4dda943c73 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -17129,15 +17129,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,
@@ -17219,15 +17220,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;
 }
-- 
2.47.0




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux