mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
conf: snapshot: Use proper types for snapshot location
Refactor the code to use proper types for the memory and disk snapshot location and fix the parsing code to be compatible with an unsigned type. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
5984e5e6fd
commit
238fef920f
@ -130,7 +130,6 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
|
||||
unsigned int flags,
|
||||
virDomainXMLOption *xmlopt)
|
||||
{
|
||||
g_autofree char *snapshot = NULL;
|
||||
g_autofree char *driver = NULL;
|
||||
g_autofree char *name = NULL;
|
||||
g_autoptr(virStorageSource) src = virStorageSourceNew();
|
||||
@ -145,16 +144,12 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
|
||||
return -1;
|
||||
}
|
||||
|
||||
snapshot = virXMLPropString(node, "snapshot");
|
||||
if (snapshot) {
|
||||
def->snapshot = virDomainSnapshotLocationTypeFromString(snapshot);
|
||||
if (def->snapshot <= 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("unknown disk snapshot setting '%s'"),
|
||||
snapshot);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (virXMLPropEnumDefault(node, "snapshot",
|
||||
virDomainSnapshotLocationTypeFromString,
|
||||
VIR_XML_PROP_NONZERO,
|
||||
&def->snapshot,
|
||||
VIR_DOMAIN_SNAPSHOT_LOCATION_DEFAULT) < 0)
|
||||
return -1;
|
||||
|
||||
if (virXMLPropEnumDefault(node, "type",
|
||||
virStorageTypeFromString,
|
||||
@ -196,7 +191,8 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!def->snapshot && (src->path || src->format))
|
||||
if (def->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_DEFAULT &&
|
||||
(src->path || src->format))
|
||||
def->snapshot = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
|
||||
|
||||
def->name = g_steal_pointer(&name);
|
||||
@ -220,7 +216,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
||||
g_autofree xmlNodePtr *diskNodes = NULL;
|
||||
size_t i;
|
||||
int n;
|
||||
g_autofree char *memorySnapshot = NULL;
|
||||
xmlNodePtr memoryNode = NULL;
|
||||
bool offline = !!(flags & VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE);
|
||||
virSaveCookieCallbacks *saveCookie = virDomainXMLOptionGetSaveCookie(xmlopt);
|
||||
int domainflags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
|
||||
@ -307,16 +303,15 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memorySnapshot = virXPathString("string(./memory/@snapshot)", ctxt);
|
||||
def->memorysnapshotfile = virXPathString("string(./memory/@file)", ctxt);
|
||||
if (memorySnapshot) {
|
||||
def->memory = virDomainSnapshotLocationTypeFromString(memorySnapshot);
|
||||
if (def->memory <= 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("unknown memory snapshot setting '%s'"),
|
||||
memorySnapshot);
|
||||
if ((memoryNode = virXPathNode("./memory", ctxt))) {
|
||||
def->memorysnapshotfile = virXMLPropString(memoryNode, "file");
|
||||
|
||||
if (virXMLPropEnumDefault(memoryNode, "snapshot",
|
||||
virDomainSnapshotLocationTypeFromString,
|
||||
VIR_XML_PROP_NONZERO,
|
||||
&def->memory,
|
||||
VIR_DOMAIN_SNAPSHOT_LOCATION_DEFAULT) < 0)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_DEFAULT) {
|
||||
|
@ -51,7 +51,7 @@ G_STATIC_ASSERT((int)VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT == VIR_DOMAIN_LAST);
|
||||
typedef struct _virDomainSnapshotDiskDef virDomainSnapshotDiskDef;
|
||||
struct _virDomainSnapshotDiskDef {
|
||||
char *name; /* name matching the <target dev='...' of the domain */
|
||||
int snapshot; /* virDomainSnapshotLocation */
|
||||
virDomainSnapshotLocation snapshot;
|
||||
|
||||
/* details of wrapper external file. src is always non-NULL.
|
||||
* XXX optimize this to allow NULL for internal snapshots? */
|
||||
@ -70,7 +70,7 @@ struct _virDomainSnapshotDef {
|
||||
/* Additional public XML. */
|
||||
int state; /* virDomainSnapshotState */
|
||||
|
||||
int memory; /* virDomainMemorySnapshot */
|
||||
virDomainSnapshotLocation memory;
|
||||
char *memorysnapshotfile; /* memory state file when snapshot is external */
|
||||
|
||||
size_t ndisks; /* should not exceed dom->ndisks */
|
||||
|
Loading…
x
Reference in New Issue
Block a user