mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-22 14:09:22 +00:00
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.
This commit is contained in:
parent
7afa6b4129
commit
9f5e53e211
@ -2563,6 +2563,15 @@ virDomainSnapshotPtr virDomainSnapshotCreateXML(virDomainPtr domain,
|
|||||||
char *virDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
|
char *virDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
|
||||||
unsigned int flags);
|
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 */
|
/* Return the number of snapshots for this domain */
|
||||||
int virDomainSnapshotNum(virDomainPtr domain, unsigned int flags);
|
int virDomainSnapshotNum(virDomainPtr domain, unsigned int flags);
|
||||||
|
|
||||||
|
@ -4329,12 +4329,16 @@ esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
|
|||||||
esxPrivate *priv = domain->conn->privateData;
|
esxPrivate *priv = domain->conn->privateData;
|
||||||
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
|
||||||
|
|
||||||
if (esxVI_EnsureSession(priv->primary) < 0) {
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
||||||
return -1;
|
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,
|
if (esxVI_LookupRootSnapshotTreeList(priv->primary, domain->uuid,
|
||||||
&rootSnapshotTreeList) < 0) {
|
&rootSnapshotTreeList) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -4357,14 +4361,14 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen,
|
|||||||
esxPrivate *priv = domain->conn->privateData;
|
esxPrivate *priv = domain->conn->privateData;
|
||||||
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
|
||||||
|
|
||||||
if (names == NULL || nameslen < 0) {
|
if (names == NULL || nameslen < 0) {
|
||||||
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument"));
|
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nameslen == 0) {
|
if (nameslen == 0 || (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15677,11 +15677,19 @@ error:
|
|||||||
/**
|
/**
|
||||||
* virDomainSnapshotNum:
|
* virDomainSnapshotNum:
|
||||||
* @domain: a domain object
|
* @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.
|
||||||
*
|
*
|
||||||
* Returns the number of domain snapshost found or -1 in case of error.
|
* 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.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
|
virDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
|
||||||
@ -15717,11 +15725,20 @@ error:
|
|||||||
* @domain: a domain object
|
* @domain: a domain object
|
||||||
* @names: array to collect the list of names of snapshots
|
* @names: array to collect the list of names of snapshots
|
||||||
* @nameslen: size of @names
|
* @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
|
* Collect the list of domain snapshots for the given domain, and store
|
||||||
* their names in @names. Caller is responsible for freeing each member
|
* 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.
|
* 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;
|
virDomainObjPtr vm = NULL;
|
||||||
int n = -1;
|
int n = -1;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
|
||||||
|
|
||||||
qemuDriverLock(driver);
|
qemuDriverLock(driver);
|
||||||
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
|
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
|
||||||
@ -8740,7 +8740,7 @@ static int qemuDomainSnapshotNum(virDomainPtr domain,
|
|||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
int n = -1;
|
int n = -1;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
|
||||||
|
|
||||||
qemuDriverLock(driver);
|
qemuDriverLock(driver);
|
||||||
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
|
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
|
||||||
@ -8752,6 +8752,10 @@ static int qemuDomainSnapshotNum(virDomainPtr domain,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* All qemu snapshots have libvirt metadata, so
|
||||||
|
* VIR_DOMAIN_SNAPSHOT_LIST_METADATA makes no difference to our
|
||||||
|
* answer. */
|
||||||
|
|
||||||
n = virDomainSnapshotObjListNum(&vm->snapshots);
|
n = virDomainSnapshotObjListNum(&vm->snapshots);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
@ -5861,7 +5861,7 @@ vboxDomainSnapshotNum(virDomainPtr dom,
|
|||||||
nsresult rc;
|
nsresult rc;
|
||||||
PRUint32 snapshotCount;
|
PRUint32 snapshotCount;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
|
||||||
|
|
||||||
vboxIIDFromUUID(&iid, dom->uuid);
|
vboxIIDFromUUID(&iid, dom->uuid);
|
||||||
rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
|
rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
|
||||||
@ -5871,6 +5871,12 @@ vboxDomainSnapshotNum(virDomainPtr dom,
|
|||||||
goto cleanup;
|
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);
|
rc = machine->vtbl->GetSnapshotCount(machine, &snapshotCount);
|
||||||
if (NS_FAILED(rc)) {
|
if (NS_FAILED(rc)) {
|
||||||
vboxError(VIR_ERR_INTERNAL_ERROR,
|
vboxError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -5901,7 +5907,7 @@ vboxDomainSnapshotListNames(virDomainPtr dom,
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
|
||||||
|
|
||||||
vboxIIDFromUUID(&iid, dom->uuid);
|
vboxIIDFromUUID(&iid, dom->uuid);
|
||||||
rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
|
rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
|
||||||
@ -5911,6 +5917,11 @@ vboxDomainSnapshotListNames(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA) {
|
||||||
|
ret = 0;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if ((count = vboxDomainSnapshotGetAll(dom, machine, &snapshots)) < 0)
|
if ((count = vboxDomainSnapshotGetAll(dom, machine, &snapshots)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user