This introduces new API virDomainDestroyWithFlags to allow domain destroying with flags, as the existing API virDomainDestroy misses flags. The set of flags is defined in virDomainDestroyFlags 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(+), 0 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 6afd591..0a06684 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -913,6 +913,11 @@ virConnectPtr virDomainGetConnect (virDomainPtr domain); /* * Domain creation and destruction */ + +/* + * typedef enum { + * } virDomainDestroyFlags; + */ virDomainPtr virDomainCreateXML (virConnectPtr conn, const char *xmlDesc, unsigned int flags); @@ -929,6 +934,8 @@ int virDomainShutdown (virDomainPtr domain); int virDomainReboot (virDomainPtr domain, unsigned int flags); int virDomainDestroy (virDomainPtr domain); +int virDomainDestroyWithFlags(virDomainPtr domain, + unsigned int flags); int virDomainRef (virDomainPtr domain); int virDomainFree (virDomainPtr domain); diff --git a/src/driver.h b/src/driver.h index 4c4955f..f23a71b 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 + (*virDrvDomainDestroyWithFlags) (virDomainPtr domain, + unsigned int flags); typedef char * (*virDrvDomainGetOSType) (virDomainPtr domain); typedef unsigned long @@ -701,6 +704,7 @@ struct _virDriver { virDrvDomainShutdown domainShutdown; virDrvDomainReboot domainReboot; virDrvDomainDestroy domainDestroy; + virDrvDomainDestroyWithFlags domainDestroyWithFlags; virDrvDomainGetOSType domainGetOSType; virDrvDomainGetMaxMemory domainGetMaxMemory; virDrvDomainSetMaxMemory domainSetMaxMemory; diff --git a/src/libvirt.c b/src/libvirt.c index 16a9a02..44cb019 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -2078,6 +2078,58 @@ error: } /** + * virDomainDestroyWithFlags: + * @domain: a domain object + * @flags: an OR'ed set of virDomainDestroyFlags + * + * 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 zero) + * is equivalent calling virDomainDestroy. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainDestroyWithFlags(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->domainDestroyWithFlags) { + int ret; + ret = conn->driver->domainDestroyWithFlags(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 5cc480e..63ff0da 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -469,6 +469,7 @@ LIBVIRT_0.9.3 { LIBVIRT_0.9.4 { global: virDomainUndefineFlags; + virDomainDestroyWithFlags; } LIBVIRT_0.9.3; # .... define new API here using predicted next version number .... -- 1.7.5.rc3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list