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);
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;
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;
}
/**
* 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)
* @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.
*/
virDomainObjPtr vm = NULL;
int n = -1;
- virCheckFlags(0, -1);
+ virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
virDomainObjPtr vm = NULL;
int n = -1;
- virCheckFlags(0, -1);
+ virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
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:
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);
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,
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);
goto cleanup;
}
+ if (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA) {
+ ret = 0;
+ goto cleanup;
+ }
+
if ((count = vboxDomainSnapshotGetAll(dom, machine, &snapshots)) < 0)
goto cleanup;