diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index fcb66955d4123d9a5d0a6687b0eeb744b15dfb62..f2ee1d6fda7329f497f2494e2f00e094ee3de1ec 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -3401,6 +3401,15 @@ virDomainSnapshotPtr virDomainSnapshotCurrent(virDomainPtr domain, virDomainSnapshotPtr virDomainSnapshotGetParent(virDomainSnapshotPtr snapshot, unsigned int flags); +/* Determine if a snapshot is the current snapshot of its domain. */ +int virDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot, + unsigned int flags); + +/* Determine if a snapshot has associated libvirt metadata that would + * prevent the deletion of its domain. */ +int virDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot, + unsigned int flags); + typedef enum { VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING = 1 << 0, /* Run after revert */ VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED = 1 << 1, /* Pause after revert */ diff --git a/src/driver.h b/src/driver.h index aa7a37795726a173994272e8b5298f860dbac865..94cc851d487d49a0f2b141c7a95a9521a232871d 100644 --- a/src/driver.h +++ b/src/driver.h @@ -649,6 +649,14 @@ typedef virDomainSnapshotPtr (*virDrvDomainSnapshotCurrent)(virDomainPtr domain, unsigned int flags); +typedef int + (*virDrvDomainSnapshotIsCurrent)(virDomainSnapshotPtr snapshot, + unsigned int flags); + +typedef int + (*virDrvDomainSnapshotHasMetadata)(virDomainSnapshotPtr snapshot, + unsigned int flags); + typedef int (*virDrvDomainRevertToSnapshot)(virDomainSnapshotPtr snapshot, unsigned int flags); @@ -986,6 +994,8 @@ struct _virDriver { virDrvDomainHasCurrentSnapshot domainHasCurrentSnapshot; virDrvDomainSnapshotGetParent domainSnapshotGetParent; virDrvDomainSnapshotCurrent domainSnapshotCurrent; + virDrvDomainSnapshotIsCurrent domainSnapshotIsCurrent; + virDrvDomainSnapshotHasMetadata domainSnapshotHasMetadata; virDrvDomainRevertToSnapshot domainRevertToSnapshot; virDrvDomainSnapshotDelete domainSnapshotDelete; virDrvDomainQemuMonitorCommand qemuDomainMonitorCommand; diff --git a/src/libvirt.c b/src/libvirt.c index 00358d68bbaeff457be0d335c3b1d0d77b324601..16afd586feb140af4d56560e5ce82042bca1394f 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -17330,6 +17330,91 @@ error: return NULL; } +/** + * virDomainSnapshotIsCurrent: + * @snapshot: a snapshot object + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Determine if the given snapshot is the domain's current snapshot. See + * also virDomainHasCurrentSnapshot(). + * + * Returns 1 if current, 0 if not current, or -1 on error. + */ +int virDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DEBUG("snapshot=%p, flags=%x", snapshot, flags); + + virResetLastError(); + + if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot)) { + virLibDomainSnapshotError(VIR_ERR_INVALID_DOMAIN_SNAPSHOT, + __FUNCTION__); + virDispatchError(NULL); + return -1; + } + + conn = snapshot->domain->conn; + + if (conn->driver->domainSnapshotIsCurrent) { + int ret; + ret = conn->driver->domainSnapshotIsCurrent(snapshot, flags); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__); +error: + virDispatchError(conn); + return -1; +} + +/** + * virDomainSnapshotHasMetadata: + * @snapshot: a snapshot object + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Determine if the given snapshot is associated with libvirt metadata + * that would prevent the deletion of the domain. + * + * Returns 1 if the snapshot has metadata, 0 if the snapshot exists without + * help from libvirt, or -1 on error. + */ +int virDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DEBUG("snapshot=%p, flags=%x", snapshot, flags); + + virResetLastError(); + + if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot)) { + virLibDomainSnapshotError(VIR_ERR_INVALID_DOMAIN_SNAPSHOT, + __FUNCTION__); + virDispatchError(NULL); + return -1; + } + + conn = snapshot->domain->conn; + + if (conn->driver->domainSnapshotHasMetadata) { + int ret; + ret = conn->driver->domainSnapshotHasMetadata(snapshot, flags); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__); +error: + virDispatchError(conn); + return -1; +} + /** * virDomainRevertToSnapshot: * @snapshot: a domain snapshot object diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index ba61595be758aab2cf9e0c4dfba84b814fccd864..96897decea72cf8cc012ed3214634b3cfea5943f 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -536,6 +536,8 @@ LIBVIRT_0.9.11 { LIBVIRT_0.9.13 { global: + virDomainSnapshotHasMetadata; + virDomainSnapshotIsCurrent; virDomainSnapshotRef; } LIBVIRT_0.9.11;