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.
This commit is contained in:
Michal Privoznik 2011-07-20 17:02:48 +02:00
parent b6fe647b60
commit 080bc4ea02
4 changed files with 64 additions and 0 deletions

View File

@ -915,6 +915,11 @@ virConnectPtr virDomainGetConnect (virDomainPtr domain);
/* /*
* Domain creation and destruction * Domain creation and destruction
*/ */
/*
* typedef enum {
* } virDomainDestroyFlagsValues;
*/
virDomainPtr virDomainCreateXML (virConnectPtr conn, virDomainPtr virDomainCreateXML (virConnectPtr conn,
const char *xmlDesc, const char *xmlDesc,
unsigned int flags); unsigned int flags);
@ -931,6 +936,8 @@ int virDomainShutdown (virDomainPtr domain);
int virDomainReboot (virDomainPtr domain, int virDomainReboot (virDomainPtr domain,
unsigned int flags); unsigned int flags);
int virDomainDestroy (virDomainPtr domain); int virDomainDestroy (virDomainPtr domain);
int virDomainDestroyFlags (virDomainPtr domain,
unsigned int flags);
int virDomainRef (virDomainPtr domain); int virDomainRef (virDomainPtr domain);
int virDomainFree (virDomainPtr domain); int virDomainFree (virDomainPtr domain);

View File

@ -124,6 +124,9 @@ typedef int
unsigned int flags); unsigned int flags);
typedef int typedef int
(*virDrvDomainDestroy) (virDomainPtr domain); (*virDrvDomainDestroy) (virDomainPtr domain);
typedef int
(*virDrvDomainDestroyFlags) (virDomainPtr domain,
unsigned int flags);
typedef char * typedef char *
(*virDrvDomainGetOSType) (virDomainPtr domain); (*virDrvDomainGetOSType) (virDomainPtr domain);
typedef unsigned long typedef unsigned long
@ -711,6 +714,7 @@ struct _virDriver {
virDrvDomainShutdown domainShutdown; virDrvDomainShutdown domainShutdown;
virDrvDomainReboot domainReboot; virDrvDomainReboot domainReboot;
virDrvDomainDestroy domainDestroy; virDrvDomainDestroy domainDestroy;
virDrvDomainDestroyFlags domainDestroyFlags;
virDrvDomainGetOSType domainGetOSType; virDrvDomainGetOSType domainGetOSType;
virDrvDomainGetMaxMemory domainGetMaxMemory; virDrvDomainGetMaxMemory domainGetMaxMemory;
virDrvDomainSetMaxMemory domainSetMaxMemory; virDrvDomainSetMaxMemory domainSetMaxMemory;

View File

@ -2077,6 +2077,58 @@ error:
return -1; 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: * virDomainFree:
* @domain: a domain object * @domain: a domain object

View File

@ -471,6 +471,7 @@ LIBVIRT_0.9.4 {
virDomainRestoreFlags; virDomainRestoreFlags;
virDomainSaveFlags; virDomainSaveFlags;
virDomainUndefineFlags; virDomainUndefineFlags;
virDomainDestroyFlags;
} LIBVIRT_0.9.3; } LIBVIRT_0.9.3;
# .... define new API here using predicted next version number .... # .... define new API here using predicted next version number ....