From: Peter Krempa Date: Wed, 9 Mar 2022 14:43:56 +0000 (+0100) Subject: virDomainSnapshotDefParse: Decouple parsing of memory snapshot config X-Git-Tag: v8.2.0-rc1~113 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5984e5e6fdf1dbeb5e67a1b9fe1e9ea5954ce7ce;p=thirdparty%2Flibvirt.git virDomainSnapshotDefParse: Decouple parsing of memory snapshot config 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 Reviewed-by: Ján Tomko --- diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 7f98ae6aec..594492ccd2 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -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 "