提交 9f5e53e2 编写于 作者: E Eric Blake

snapshot: identify which snapshots have metadata

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.
上级 7afa6b41
......@@ -2563,6 +2563,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);
......
......@@ -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;
}
......
......@@ -15677,11 +15677,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)
......@@ -15717,11 +15725,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.
*/
......
......@@ -8712,7 +8712,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);
......@@ -8740,7 +8740,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);
......@@ -8752,6 +8752,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:
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册