From 6c14439e51ff51492263f46c803d3e8df167c240 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 8 Sep 2011 12:19:25 +0100 Subject: [PATCH] snapshot: new APIs for inspecting snapshot object These functions access internals of the opaque object, and do not need any rpc counterpart. It could be argued that we should have provided these when snapshot objects were first introduced, since all the other vir*Ptr objects have at least a GetName accessor. * include/libvirt/libvirt.h.in (virDomainSnapshotGetName) (virDomainSnapshotGetDomain, virDomainSnapshotGetConnect): Declare. * src/libvirt.c (virDomainSnapshotGetName) (virDomainSnapshotGetDomain, virDomainSnapshotGetConnect): New functions. * src/libvirt_public.syms: Export them. --- include/libvirt/libvirt.h.in | 4 ++ src/libvirt.c | 73 ++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 5 ++- 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 5fa489ea46..ea7b3fc448 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -2656,6 +2656,10 @@ typedef struct _virDomainSnapshot virDomainSnapshot; */ typedef virDomainSnapshot *virDomainSnapshotPtr; +const char *virDomainSnapshotGetName(virDomainSnapshotPtr snapshot); +virDomainPtr virDomainSnapshotGetDomain(virDomainSnapshotPtr snapshot); +virConnectPtr virDomainSnapshotGetConnect(virDomainSnapshotPtr snapshot); + typedef enum { VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE = (1 << 0), /* Restore or alter metadata */ diff --git a/src/libvirt.c b/src/libvirt.c index dc082a60ae..c32c7a6eef 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -15664,6 +15664,79 @@ error: return -1; } +/** + * virDomainSnapshotGetName: + * @snapshot: a snapshot object + * + * Get the public name for that snapshot + * + * Returns a pointer to the name or NULL, the string need not be deallocated + * as its lifetime will be the same as the snapshot object. + */ +const char * +virDomainSnapshotGetName(virDomainSnapshotPtr snapshot) +{ + VIR_DEBUG("snapshot=%p", snapshot); + + virResetLastError(); + + if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot)) { + virLibDomainSnapshotError(VIR_ERR_INVALID_DOMAIN_SNAPSHOT, + __FUNCTION__); + virDispatchError(NULL); + return NULL; + } + return snapshot->name; +} + +/** + * virDomainSnapshotGetDomain: + * @snapshot: a snapshot object + * + * Get the domain that a snapshot was created for + * + * Returns the domain or NULL. + */ +virDomainPtr +virDomainSnapshotGetDomain(virDomainSnapshotPtr snapshot) +{ + VIR_DEBUG("snapshot=%p", snapshot); + + virResetLastError(); + + if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot)) { + virLibDomainSnapshotError(VIR_ERR_INVALID_DOMAIN_SNAPSHOT, + __FUNCTION__); + virDispatchError(NULL); + return NULL; + } + return snapshot->domain; +} + +/** + * virDomainSnapshotGetConnect: + * @snapshot: a snapshot object + * + * Get the connection that owns the domain that a snapshot was created for + * + * Returns the connection or NULL. + */ +virConnectPtr +virDomainSnapshotGetConnect(virDomainSnapshotPtr snapshot) +{ + VIR_DEBUG("snapshot=%p", snapshot); + + virResetLastError(); + + if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot)) { + virLibDomainSnapshotError(VIR_ERR_INVALID_DOMAIN_SNAPSHOT, + __FUNCTION__); + virDispatchError(NULL); + return NULL; + } + return snapshot->domain->conn; +} + /** * virDomainSnapshotCreateXML: * @domain: a domain object diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index dc5a80b610..8a6d55a34b 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -482,8 +482,11 @@ LIBVIRT_0.9.4 { LIBVIRT_0.9.5 { global: - virDomainMigrateGetMaxSpeed; virDomainBlockStatsFlags; + virDomainMigrateGetMaxSpeed; + virDomainSnapshotGetConnect; + virDomainSnapshotGetDomain; + virDomainSnapshotGetName; } LIBVIRT_0.9.4; # .... define new API here using predicted next version number .... -- GitLab