mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
Adding virDomainSetMemoryParameters and virDomainGetMemoryParameters API
Public api to set/get memory tunables supported by the hypervisors. dv: * some cleanups in libvirt.c * adding extra checks in libvirt.c new entry points v4: * Move exporting public API to this patch * Add unsigned int flags to the public api for future extensions v3: * Add domainGetMemoryParamters and NULL in all the driver interface v2: * Initialize domainSetMemoryParameters to NULL in all the driver interface structure.
This commit is contained in:
parent
bf1b76ffaa
commit
0cd7823271
1
AUTHORS
1
AUTHORS
@ -129,6 +129,7 @@ Patches have also been contributed by:
|
||||
Aurelien Rougemont <beorn@binaries.fr>
|
||||
Patrick Dignan <pat_dignan@dell.com>
|
||||
Serge Hallyn <serge.hallyn@canonical.com>
|
||||
Nikunj A. Dadhania <nikunj@linux.vnet.ibm.com>
|
||||
|
||||
[....send patches to get your name here....]
|
||||
|
||||
|
14
src/driver.h
14
src/driver.h
@ -127,6 +127,18 @@ typedef int
|
||||
typedef int
|
||||
(*virDrvDomainSetMemory) (virDomainPtr domain,
|
||||
unsigned long memory);
|
||||
typedef int
|
||||
(*virDrvDomainSetMemoryParameters)
|
||||
(virDomainPtr domain,
|
||||
virMemoryParameterPtr params,
|
||||
int nparams,
|
||||
unsigned int flags);
|
||||
typedef int
|
||||
(*virDrvDomainGetMemoryParameters)
|
||||
(virDomainPtr domain,
|
||||
virMemoryParameterPtr params,
|
||||
int *nparams,
|
||||
unsigned int flags);
|
||||
typedef int
|
||||
(*virDrvDomainGetInfo) (virDomainPtr domain,
|
||||
virDomainInfoPtr info);
|
||||
@ -575,6 +587,8 @@ struct _virDriver {
|
||||
virDrvDomainRevertToSnapshot domainRevertToSnapshot;
|
||||
virDrvDomainSnapshotDelete domainSnapshotDelete;
|
||||
virDrvQemuDomainMonitorCommand qemuDomainMonitorCommand;
|
||||
virDrvDomainSetMemoryParameters domainSetMemoryParameters;
|
||||
virDrvDomainGetMemoryParameters domainGetMemoryParameters;
|
||||
};
|
||||
|
||||
typedef int
|
||||
|
@ -4217,6 +4217,8 @@ static virDriver esxDriver = {
|
||||
esxDomainRevertToSnapshot, /* domainRevertToSnapshot */
|
||||
esxDomainSnapshotDelete, /* domainSnapshotDelete */
|
||||
NULL, /* qemuDomainMonitorCommand */
|
||||
NULL, /* domainSetMemoryParameters */
|
||||
NULL, /* domainGetMemoryParameters */
|
||||
};
|
||||
|
||||
|
||||
|
112
src/libvirt.c
112
src/libvirt.c
@ -2999,6 +2999,118 @@ error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainSetMemoryParameters:
|
||||
* @domain: pointer to domain object
|
||||
* @params: pointer to memory parameter objects
|
||||
* @nparams: number of memory parameter (this value should be same or
|
||||
* less than the number of parameters supported)
|
||||
* @flags: currently unused, for future extension
|
||||
*
|
||||
* Change the memory tunables
|
||||
* This function requires privileged access to the hypervisor.
|
||||
*
|
||||
* Returns -1 in case of error, 0 in case of success.
|
||||
*/
|
||||
int
|
||||
virDomainSetMemoryParameters(virDomainPtr domain,
|
||||
virMemoryParameterPtr params,
|
||||
int nparams, unsigned int flags)
|
||||
{
|
||||
virConnectPtr conn;
|
||||
DEBUG("domain=%p, params=%p, nparams=%d, flags=%u", domain, params, nparams, flags);
|
||||
|
||||
virResetLastError();
|
||||
|
||||
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
||||
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
if (domain->conn->flags & VIR_CONNECT_RO) {
|
||||
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
||||
goto error;
|
||||
}
|
||||
if ((nparams <= 0) || (params == NULL)) {
|
||||
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
goto error;
|
||||
}
|
||||
conn = domain->conn;
|
||||
|
||||
if (conn->driver->domainSetMemoryParameters) {
|
||||
int ret;
|
||||
ret = conn->driver->domainSetMemoryParameters (domain, params, nparams, flags);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
return ret;
|
||||
}
|
||||
|
||||
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
||||
|
||||
error:
|
||||
virDispatchError(domain->conn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainGetMemoryParameters:
|
||||
* @domain: pointer to domain object
|
||||
* @params: pointer to memory parameter object
|
||||
* (return value, allocated by the caller)
|
||||
* @nparams: pointer to number of memory parameters
|
||||
* @flags: currently unused, for future extension
|
||||
*
|
||||
* Get the memory parameters, the @params array will be filled with the values
|
||||
* equal to the number of parameters suggested by @nparams
|
||||
*
|
||||
* As a special case, if @nparams is zero and @params is NULL, the API will
|
||||
* set the number of parameters supported by the HV in @nparams and return
|
||||
* SUCCESS.
|
||||
*
|
||||
* This function requires privileged access to the hypervisor. This function
|
||||
* expects the caller to allocate the @param
|
||||
*
|
||||
* Returns -1 in case of error, 0 in case of success.
|
||||
*/
|
||||
int
|
||||
virDomainGetMemoryParameters(virDomainPtr domain,
|
||||
virMemoryParameterPtr params,
|
||||
int *nparams, unsigned int flags)
|
||||
{
|
||||
virConnectPtr conn;
|
||||
DEBUG("domain=%p, params=%p, nparams=%d, flags=%u", domain, params, (nparams)?*nparams:-1, flags);
|
||||
|
||||
virResetLastError();
|
||||
|
||||
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
||||
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
if (domain->conn->flags & VIR_CONNECT_RO) {
|
||||
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
||||
goto error;
|
||||
}
|
||||
if ((nparams == NULL) || (*nparams < 0)) {
|
||||
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
goto error;
|
||||
}
|
||||
conn = domain->conn;
|
||||
|
||||
if (conn->driver->domainGetMemoryParameters) {
|
||||
int ret;
|
||||
ret = conn->driver->domainGetMemoryParameters (domain, params, nparams, flags);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
return ret;
|
||||
}
|
||||
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
||||
|
||||
error:
|
||||
virDispatchError(domain->conn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainGetInfo:
|
||||
* @domain: a domain object
|
||||
|
@ -405,4 +405,10 @@ LIBVIRT_0.8.2 {
|
||||
virDomainCreateWithFlags;
|
||||
} LIBVIRT_0.8.1;
|
||||
|
||||
LIBVIRT_0.8.5 {
|
||||
global:
|
||||
virDomainSetMemoryParameters;
|
||||
virDomainGetMemoryParameters;
|
||||
} LIBVIRT_0.8.2;
|
||||
|
||||
# .... define new API here using predicted next version number ....
|
||||
|
@ -2620,6 +2620,8 @@ static virDriver lxcDriver = {
|
||||
NULL, /* domainRevertToSnapshot */
|
||||
NULL, /* domainSnapshotDelete */
|
||||
NULL, /* qemuDomainMonitorCommand */
|
||||
NULL, /* domainSetMemoryParameters */
|
||||
NULL, /* domainGetMemoryParameters */
|
||||
};
|
||||
|
||||
static virStateDriver lxcStateDriver = {
|
||||
|
@ -1657,6 +1657,8 @@ static virDriver openvzDriver = {
|
||||
NULL, /* domainRevertToSnapshot */
|
||||
NULL, /* domainSnapshotDelete */
|
||||
NULL, /* qemuDomainMonitorCommand */
|
||||
NULL, /* domainSetMemoryParameters */
|
||||
NULL, /* domainGetMemoryParameters */
|
||||
};
|
||||
|
||||
int openvzRegister(void) {
|
||||
|
@ -4007,6 +4007,8 @@ static virDriver phypDriver = {
|
||||
NULL, /* domainRevertToSnapshot */
|
||||
NULL, /* domainSnapshotDelete */
|
||||
NULL, /* qemuMonitorCommand */
|
||||
NULL, /* domainSetMemoryParameters */
|
||||
NULL, /* domainGetMemoryParameters */
|
||||
};
|
||||
|
||||
static virStorageDriver phypStorageDriver = {
|
||||
|
@ -12710,6 +12710,8 @@ static virDriver qemuDriver = {
|
||||
qemuDomainRevertToSnapshot, /* domainRevertToSnapshot */
|
||||
qemuDomainSnapshotDelete, /* domainSnapshotDelete */
|
||||
qemuDomainMonitorCommand, /* qemuDomainMonitorCommand */
|
||||
NULL, /* domainSetMemoryParameters */
|
||||
NULL, /* domainGetMemoryParameters */
|
||||
};
|
||||
|
||||
|
||||
|
@ -10366,6 +10366,8 @@ static virDriver remote_driver = {
|
||||
remoteDomainRevertToSnapshot, /* domainRevertToSnapshot */
|
||||
remoteDomainSnapshotDelete, /* domainSnapshotDelete */
|
||||
remoteQemuDomainMonitorCommand, /* qemuDomainMonitorCommand */
|
||||
NULL, /* domainSetMemoryParameters */
|
||||
NULL, /* domainGetMemoryParameters */
|
||||
};
|
||||
|
||||
static virNetworkDriver network_driver = {
|
||||
|
@ -5327,6 +5327,8 @@ static virDriver testDriver = {
|
||||
NULL, /* domainRevertToSnapshot */
|
||||
NULL, /* domainSnapshotDelete */
|
||||
NULL, /* qemuDomainMonitorCommand */
|
||||
NULL, /* domainSetMemoryParameters */
|
||||
NULL, /* domainGetMemoryParameters */
|
||||
};
|
||||
|
||||
static virNetworkDriver testNetworkDriver = {
|
||||
|
@ -2196,6 +2196,8 @@ static virDriver umlDriver = {
|
||||
NULL, /* domainRevertToSnapshot */
|
||||
NULL, /* domainSnapshotDelete */
|
||||
NULL, /* qemuDomainMonitorCommand */
|
||||
NULL, /* domainSetMemoryParamters */
|
||||
NULL, /* domainGetMemoryParamters */
|
||||
};
|
||||
|
||||
static int
|
||||
|
@ -2018,6 +2018,8 @@ static virDriver xenUnifiedDriver = {
|
||||
NULL, /* domainRevertToSnapshot */
|
||||
NULL, /* domainSnapshotDelete */
|
||||
NULL, /* qemuDomainMonitorCommand */
|
||||
NULL, /* domainSetMemoryParameters */
|
||||
NULL, /* domainGetMemoryParameters */
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user