提交 30f1bccf 编写于 作者: P Peter Krempa

snapshot: qemu: Fix detection of external snapshots when deleting

This patch adds a helper to determine if snapshots are external and uses
the helper to fix detection of those in snapshot deletion code.

Snapshots are external if they have an external memory image or if the
disk locations are external. As mixed snapshots are forbidden for now
we need to check just one disk to know.
上级 e5aab47a
...@@ -1023,3 +1023,20 @@ cleanup: ...@@ -1023,3 +1023,20 @@ cleanup:
} }
return ret; return ret;
} }
bool
virDomainSnapshotIsExternal(virDomainSnapshotObjPtr snap)
{
int i;
if (snap->def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL)
return true;
for (i = 0; i < snap->def->ndisks; i++) {
if (snap->def->disks[i].snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL)
return true;
}
return false;
}
...@@ -155,6 +155,8 @@ int virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots, ...@@ -155,6 +155,8 @@ int virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots,
virDomainSnapshotPtr **snaps, virDomainSnapshotPtr **snaps,
unsigned int flags); unsigned int flags);
bool virDomainSnapshotIsExternal(virDomainSnapshotObjPtr snap);
VIR_ENUM_DECL(virDomainSnapshotLocation) VIR_ENUM_DECL(virDomainSnapshotLocation)
VIR_ENUM_DECL(virDomainSnapshotState) VIR_ENUM_DECL(virDomainSnapshotState)
......
...@@ -1083,6 +1083,7 @@ virDomainSnapshotFindByName; ...@@ -1083,6 +1083,7 @@ virDomainSnapshotFindByName;
virDomainSnapshotForEach; virDomainSnapshotForEach;
virDomainSnapshotForEachChild; virDomainSnapshotForEachChild;
virDomainSnapshotForEachDescendant; virDomainSnapshotForEachDescendant;
virDomainSnapshotIsExternal;
virDomainSnapshotLocationTypeFromString; virDomainSnapshotLocationTypeFromString;
virDomainSnapshotLocationTypeToString; virDomainSnapshotLocationTypeToString;
virDomainSnapshotObjListGetNames; virDomainSnapshotObjListGetNames;
......
...@@ -2025,7 +2025,7 @@ cleanup: ...@@ -2025,7 +2025,7 @@ cleanup:
} }
/* Count how many snapshots in a set have external disk snapshots. */ /* Count how many snapshots in a set are external snapshots or checkpoints. */
static void static void
qemuDomainSnapshotCountExternal(void *payload, qemuDomainSnapshotCountExternal(void *payload,
const void *name ATTRIBUTE_UNUSED, const void *name ATTRIBUTE_UNUSED,
...@@ -2034,7 +2034,7 @@ qemuDomainSnapshotCountExternal(void *payload, ...@@ -2034,7 +2034,7 @@ qemuDomainSnapshotCountExternal(void *payload,
virDomainSnapshotObjPtr snap = payload; virDomainSnapshotObjPtr snap = payload;
int *count = data; int *count = data;
if (snap->def->state == VIR_DOMAIN_DISK_SNAPSHOT) if (virDomainSnapshotIsExternal(snap))
(*count)++; (*count)++;
} }
...@@ -12512,7 +12512,7 @@ static int qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot, ...@@ -12512,7 +12512,7 @@ static int qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY)) { if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY)) {
if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) && if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) &&
snap->def->state == VIR_DOMAIN_DISK_SNAPSHOT) virDomainSnapshotIsExternal(snap))
external++; external++;
if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN)
virDomainSnapshotForEachDescendant(snap, virDomainSnapshotForEachDescendant(snap,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册