To make it easier to know when undefine will fail because of existing
snapshot metadata, we need to know how many snapshots have metadata.
Also, it is handy to filter the list of snapshots to just those that
have no parents; document that flag now, but implement it in later patches.
* include/libvirt/libvirt.h.in (VIR_DOMAIN_SNAPSHOT_LIST_ROOTS)
(VIR_DOMAIN_SNAPSHOT_LIST_METADATA): New flags.
* src/libvirt.c (virDomainSnapshotNum)
(virDomainSnapshotListNames): Document them.
* src/esx/esx_driver.c (esxDomainSnapshotNum)
(esxDomainSnapshotListNames): Implement trivial flag.
* src/vbox/vbox_tmpl.c (vboxDomainSnapshotNum)
(vboxDomainSnapshotListNames): Likewise.
* src/qemu/qemu_driver.c (qemuDomainSnapshotNum)
(qemuDomainSnapshotListNames): Likewise.
---
include/libvirt/libvirt.h.in | 9 +++++++++
src/esx/esx_driver.c | 10 +++++++---
src/libvirt.c | 27 ++++++++++++++++++++++-----
src/qemu/qemu_driver.c | 8 ++++++--
src/vbox/vbox_tmpl.c | 15 +++++++++++++--
5 files changed, 57 insertions(+), 12 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 637145b..38a9058 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2561,6 +2561,15 @@ virDomainSnapshotPtr virDomainSnapshotCreateXML(virDomainPtr
domain,
char *virDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
unsigned int flags);
+/* Flags valid for both virDomainSnapshotNum() and
+ * virDomainSnapshotListNames(). */
+typedef enum {
+ VIR_DOMAIN_SNAPSHOT_LIST_ROOTS = (1 << 0), /* Filter by snapshots which
+ have no parents */
+ VIR_DOMAIN_SNAPSHOT_LIST_METADATA = (1 << 1), /* Filter by snapshots which
+ have metadata */
+} virDomainSnapshotListFlags;
+
/* Return the number of snapshots for this domain */
int virDomainSnapshotNum(virDomainPtr domain, unsigned int flags);
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index beeafbd..dbc7694 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -4329,12 +4329,16 @@ esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
esxPrivate *priv = domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
- virCheckFlags(0, -1);
+ virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
if (esxVI_EnsureSession(priv->primary) < 0) {
return -1;
}
+ /* ESX snapshots do not require libvirt to maintain any metadata. */
+ if (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA)
+ return 0;
+
if (esxVI_LookupRootSnapshotTreeList(priv->primary, domain->uuid,
&rootSnapshotTreeList) < 0) {
return -1;
@@ -4357,14 +4361,14 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int
nameslen,
esxPrivate *priv = domain->conn->privateData;
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
- virCheckFlags(0, -1);
+ virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
if (names == NULL || nameslen < 0) {
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument"));
return -1;
}
- if (nameslen == 0) {
+ if (nameslen == 0 || (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA)) {
return 0;
}
diff --git a/src/libvirt.c b/src/libvirt.c
index fdf8368..8870f47 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -15672,11 +15672,19 @@ error:
/**
* virDomainSnapshotNum:
* @domain: a domain object
- * @flags: unused flag parameters; callers should pass 0
+ * @flags: bitwise-or of supported virDomainSnapshotListFlags
+ *
+ * Provides the number of domain snapshots for this domain.
*
- * Provides the number of domain snapshots for this domain..
+ * If @flags includes VIR_DOMAIN_SNAPSHOT_LIST_ROOTS, then the result is
+ * filtered to the number of snapshots that have no parents.
*
- * Returns the number of domain snapshost found or -1 in case of error.
+ * If @flags includes VIR_DOMAIN_SNAPSHOT_LIST_METADATA, then the result is
+ * the number of snapshots that also include metadata that would prevent
+ * the removal of the last reference to a domain; this value will either
+ * be 0 or the same value as if the flag were not given.
+ *
+ * Returns the number of domain snapshots found or -1 in case of error.
*/
int
virDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
@@ -15712,11 +15720,20 @@ error:
* @domain: a domain object
* @names: array to collect the list of names of snapshots
* @nameslen: size of @names
- * @flags: unused flag parameters; callers should pass 0
+ * @flags: bitwise-or of supported virDomainSnapshotListFlags
*
* Collect the list of domain snapshots for the given domain, and store
* their names in @names. Caller is responsible for freeing each member
- * of the array.
+ * of the array. The value to use for @nameslen can be determined by
+ * virDomainSnapshotNum() with the same @flags.
+ *
+ * If @flags includes VIR_DOMAIN_SNAPSHOT_LIST_ROOTS, then the result is
+ * filtered to the number of snapshots that have no parents.
+ *
+ * If @flags includes VIR_DOMAIN_SNAPSHOT_LIST_METADATA, then the result is
+ * the number of snapshots that also include metadata that would prevent
+ * the removal of the last reference to a domain; this value will either
+ * be 0 or the same value as if the flag were not given.
*
* Returns the number of domain snapshots found or -1 in case of error.
*/
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 45dd582..dcb3661 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8676,7 +8676,7 @@ static int qemuDomainSnapshotListNames(virDomainPtr domain, char
**names,
virDomainObjPtr vm = NULL;
int n = -1;
- virCheckFlags(0, -1);
+ virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
@@ -8704,7 +8704,7 @@ static int qemuDomainSnapshotNum(virDomainPtr domain,
virDomainObjPtr vm = NULL;
int n = -1;
- virCheckFlags(0, -1);
+ virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
@@ -8716,6 +8716,10 @@ static int qemuDomainSnapshotNum(virDomainPtr domain,
goto cleanup;
}
+ /* All qemu snapshots have libvirt metadata, so
+ * VIR_DOMAIN_SNAPSHOT_LIST_METADATA makes no difference to our
+ * answer. */
+
n = virDomainSnapshotObjListNum(&vm->snapshots);
cleanup:
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 8de2bae..fc9739e 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -5861,7 +5861,7 @@ vboxDomainSnapshotNum(virDomainPtr dom,
nsresult rc;
PRUint32 snapshotCount;
- virCheckFlags(0, -1);
+ virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
vboxIIDFromUUID(&iid, dom->uuid);
rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
@@ -5871,6 +5871,12 @@ vboxDomainSnapshotNum(virDomainPtr dom,
goto cleanup;
}
+ /* VBox snapshots do not require libvirt to maintain any metadata. */
+ if (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA) {
+ ret = 0;
+ goto cleanup;
+ }
+
rc = machine->vtbl->GetSnapshotCount(machine, &snapshotCount);
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
@@ -5901,7 +5907,7 @@ vboxDomainSnapshotListNames(virDomainPtr dom,
int count = 0;
int i;
- virCheckFlags(0, -1);
+ virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
vboxIIDFromUUID(&iid, dom->uuid);
rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
@@ -5911,6 +5917,11 @@ vboxDomainSnapshotListNames(virDomainPtr dom,
goto cleanup;
}
+ if (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA) {
+ ret = 0;
+ goto cleanup;
+ }
+
if ((count = vboxDomainSnapshotGetAll(dom, machine, &snapshots)) < 0)
goto cleanup;
--
1.7.4.4