From 080bc4ea0242bce617cbec0e70968c63aab26c59 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Wed, 20 Jul 2011 17:02:48 +0200 Subject: [PATCH] destroy: Define new public API virDomainDestroyFlags This introduces new API virDomainDestroyFlags to allow domain destroying with flags, as the existing API virDomainDestroy misses flags. The set of flags is defined in virDomainDestroyFlagsValues enum, which is currently commented, because it is empty. Calling this API with no flags set (@flags == 0) is equivalent calling virDomainDestroy. --- include/libvirt/libvirt.h.in | 7 +++++ src/driver.h | 4 +++ src/libvirt.c | 52 ++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 1 + 4 files changed, 64 insertions(+) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 8fa7daec85..0b7e35f916 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -915,6 +915,11 @@ virConnectPtr virDomainGetConnect (virDomainPtr domain); /* * Domain creation and destruction */ + +/* + * typedef enum { + * } virDomainDestroyFlagsValues; + */ virDomainPtr virDomainCreateXML (virConnectPtr conn, const char *xmlDesc, unsigned int flags); @@ -931,6 +936,8 @@ int virDomainShutdown (virDomainPtr domain); int virDomainReboot (virDomainPtr domain, unsigned int flags); int virDomainDestroy (virDomainPtr domain); +int virDomainDestroyFlags (virDomainPtr domain, + unsigned int flags); int virDomainRef (virDomainPtr domain); int virDomainFree (virDomainPtr domain); diff --git a/src/driver.h b/src/driver.h index d931c9b9b7..4df54964dd 100644 --- a/src/driver.h +++ b/src/driver.h @@ -124,6 +124,9 @@ typedef int unsigned int flags); typedef int (*virDrvDomainDestroy) (virDomainPtr domain); +typedef int + (*virDrvDomainDestroyFlags) (virDomainPtr domain, + unsigned int flags); typedef char * (*virDrvDomainGetOSType) (virDomainPtr domain); typedef unsigned long @@ -711,6 +714,7 @@ struct _virDriver { virDrvDomainShutdown domainShutdown; virDrvDomainReboot domainReboot; virDrvDomainDestroy domainDestroy; + virDrvDomainDestroyFlags domainDestroyFlags; virDrvDomainGetOSType domainGetOSType; virDrvDomainGetMaxMemory domainGetMaxMemory; virDrvDomainSetMaxMemory domainSetMaxMemory; diff --git a/src/libvirt.c b/src/libvirt.c index 67041c6729..7fb1bc1dbc 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -2077,6 +2077,58 @@ error: return -1; } +/** + * virDomainDestroyFlags: + * @domain: a domain object + * @flags: an OR'ed set of virDomainDestroyFlagsValues + * + * Destroy the domain object. The running instance is shutdown if not down + * already and all resources used by it are given back to the hypervisor. + * This does not free the associated virDomainPtr object. + * This function may require privileged access. + * + * Calling this function with no @flags set (equal to zero) + * is equivalent to calling virDomainDestroy. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainDestroyFlags(virDomainPtr domain, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { + virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + virDispatchError(NULL); + return -1; + } + + conn = domain->conn; + if (conn->flags & VIR_CONNECT_RO) { + virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__); + goto error; + } + + if (conn->driver->domainDestroyFlags) { + int ret; + ret = conn->driver->domainDestroyFlags(domain, flags); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: + virDispatchError(conn); + return -1; +} + /** * virDomainFree: * @domain: a domain object diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 6935140df8..9336df4d63 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -471,6 +471,7 @@ LIBVIRT_0.9.4 { virDomainRestoreFlags; virDomainSaveFlags; virDomainUndefineFlags; + virDomainDestroyFlags; } LIBVIRT_0.9.3; # .... define new API here using predicted next version number .... -- GitLab