]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virDomainSnapshotDefParse: Decouple parsing of memory snapshot config
authorPeter Krempa <pkrempa@redhat.com>
Wed, 9 Mar 2022 14:43:56 +0000 (15:43 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 11 Mar 2022 12:55:50 +0000 (13:55 +0100)
Separate the steps of parsing the memory snapshot config from the
post-processing and validation code. The upcoming patch refactoring the
parsing will be simpler.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/snapshot_conf.c

index 7f98ae6aecf557f66be487ba8ab99c804f4b2992..594492ccd2210e908a863c73c861359851ab3514 100644 (file)
@@ -317,27 +317,37 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
                            memorySnapshot);
             return NULL;
         }
-        if (def->memorysnapshotfile &&
-            def->memory != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("memory filename '%s' requires external snapshot"),
-                           def->memorysnapshotfile);
-            return NULL;
-        }
-        if (!def->memorysnapshotfile &&
-            def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("external memory snapshots require a filename"));
-            return NULL;
+    }
+
+    if (def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_DEFAULT) {
+        if (def->memorysnapshotfile) {
+            def->memory = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
+        } else if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE) {
+            if (offline) {
+                def->memory = VIR_DOMAIN_SNAPSHOT_LOCATION_NO;
+            } else {
+                def->memory = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
+            }
         }
-    } else if (def->memorysnapshotfile) {
-        def->memory = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
-    } else if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE) {
-        def->memory = (offline ?
-                       VIR_DOMAIN_SNAPSHOT_LOCATION_NO :
-                       VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL);
-    }
-    if (offline && def->memory &&
+    }
+
+    if (def->memorysnapshotfile &&
+        def->memory != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("memory filename '%s' requires external snapshot"),
+                       def->memorysnapshotfile);
+        return NULL;
+    }
+
+    if (!def->memorysnapshotfile &&
+        def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("external memory snapshots require a filename"));
+        return NULL;
+    }
+
+    if (offline &&
+        def->memory != VIR_DOMAIN_SNAPSHOT_LOCATION_DEFAULT &&
         def->memory != VIR_DOMAIN_SNAPSHOT_LOCATION_NO) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("memory state cannot be saved with offline or "