From: Nikunj A. Dadhania <nikunj(a)linux.vnet.ibm.com>
Public api to set/get memory tunables supported by the hypervisors.
RFC:
https://www.redhat.com/archives/libvir-list/2010-August/msg00607.html
v3:
* Add domainGetMemoryParamters and NULL in all the driver interface
v2:
* Initialize domainSetMemoryParameters to NULL in all the driver interface
structure.
Signed-off-by: Nikunj A. Dadhania <nikunj(a)linux.vnet.ibm.com>
---
src/driver.h | 12 +++++
src/esx/esx_driver.c | 2 +
src/libvirt.c | 103 ++++++++++++++++++++++++++++++++++++++++++++
src/lxc/lxc_driver.c | 2 +
src/openvz/openvz_driver.c | 2 +
src/phyp/phyp_driver.c | 2 +
src/qemu/qemu_driver.c | 2 +
src/remote/remote_driver.c | 2 +
src/test/test_driver.c | 2 +
src/uml/uml_driver.c | 2 +
src/xen/xen_driver.c | 2 +
11 files changed, 133 insertions(+), 0 deletions(-)
diff --git a/src/driver.h b/src/driver.h
index e443c1c..0580bee 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -128,6 +128,16 @@ typedef int
(*virDrvDomainSetMemory) (virDomainPtr domain,
unsigned long memory);
typedef int
+ (*virDrvDomainSetMemoryParameters)
+ (virDomainPtr domain,
+ virMemoryParameterPtr params,
+ int nparams);
+typedef int
+ (*virDrvDomainGetMemoryParameters)
+ (virDomainPtr domain,
+ virMemoryParameterPtr params,
+ int *nparams);
+typedef int
(*virDrvDomainGetInfo) (virDomainPtr domain,
virDomainInfoPtr info);
typedef int
@@ -575,6 +585,8 @@ struct _virDriver {
virDrvDomainRevertToSnapshot domainRevertToSnapshot;
virDrvDomainSnapshotDelete domainSnapshotDelete;
virDrvQemuDomainMonitorCommand qemuDomainMonitorCommand;
+ virDrvDomainSetMemoryParameters domainSetMemoryParameters;
+ virDrvDomainGetMemoryParameters domainGetMemoryParameters;
};
typedef int
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index e382950..e959be2 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -4217,6 +4217,8 @@ static virDriver esxDriver = {
esxDomainRevertToSnapshot, /* domainRevertToSnapshot */
esxDomainSnapshotDelete, /* domainSnapshotDelete */
NULL, /* qemuDomainMonitorCommand */
+ NULL, /* domainSetMemoryParameters */
+ NULL, /* domainGetMemoryParameters */
};
diff --git a/src/libvirt.c b/src/libvirt.c
index ca383ba..0708e36 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -3000,6 +3000,109 @@ error:
}
/**
+ * 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)
+ *
+ * Change the memory tunables
+ * This function requires privileged access to the hypervisor.
+ * FIXME: Should we make changes to the domain configuration file as well?
+ *
+ * Returns -1 in case of error, 0 in case of success.
+ */
+int
+virDomainSetMemoryParameters(virDomainPtr domain,
+ virMemoryParameterPtr params,
+ int nparams)
+{
+ virConnectPtr conn;
+ DEBUG("domain=%p, params=%p, nparams=%d", domain, params, nparams);
+
+ 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;
+ }
+ conn = domain->conn;
+
+ if (conn->driver->domainSetMemoryParameters) {
+ int ret;
+ ret = conn->driver->domainSetMemoryParameters (domain, params, nparams);
+ 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
+ *
+ * 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
+ *
+ * Returns -1 in case of error, 0 in case of success.
+ */
+int
+virDomainGetMemoryParameters(virDomainPtr domain,
+ virMemoryParameterPtr params,
+ int *nparams)
+{
+ virConnectPtr conn;
+ DEBUG("domain=%p, params=%p, nparams=%d", domain, params,
(nparams)?*nparams:-1);
+
+ 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;
+ }
+ conn = domain->conn;
+
+ if (conn->driver->domainGetMemoryParameters) {
+ int ret;
+ ret = conn->driver->domainGetMemoryParameters (domain, params, nparams);
+ 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
* @info: pointer to a virDomainInfo structure allocated by the user
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 326fee6..a240e6d 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2620,6 +2620,8 @@ static virDriver lxcDriver = {
NULL, /* domainRevertToSnapshot */
NULL, /* domainSnapshotDelete */
NULL, /* qemuDomainMonitorCommand */
+ NULL, /* domainSetMemoryParameters */
+ NULL, /* domainGetMemoryParameters */
};
static virStateDriver lxcStateDriver = {
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 1ad93d9..4247e0a 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1657,6 +1657,8 @@ static virDriver openvzDriver = {
NULL, /* domainRevertToSnapshot */
NULL, /* domainSnapshotDelete */
NULL, /* qemuDomainMonitorCommand */
+ NULL, /* domainSetMemoryParameters */
+ NULL, /* domainGetMemoryParameters */
};
int openvzRegister(void) {
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 8eeba73..ec47289 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -3980,6 +3980,8 @@ static virDriver phypDriver = {
NULL, /* domainRevertToSnapshot */
NULL, /* domainSnapshotDelete */
NULL, /* qemuMonitorCommand */
+ NULL, /* domainSetMemoryParameters */
+ NULL, /* domainGetMemoryParameters */
};
static virStorageDriver phypStorageDriver = {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 25695df..f44a18f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12710,6 +12710,8 @@ static virDriver qemuDriver = {
qemuDomainRevertToSnapshot, /* domainRevertToSnapshot */
qemuDomainSnapshotDelete, /* domainSnapshotDelete */
qemuDomainMonitorCommand, /* qemuDomainMonitorCommand */
+ NULL, /* domainSetMemoryParameters */
+ NULL, /* domainGetMemoryParameters */
};
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index a945710..c1051a1 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -10358,6 +10358,8 @@ static virDriver remote_driver = {
remoteDomainRevertToSnapshot, /* domainRevertToSnapshot */
remoteDomainSnapshotDelete, /* domainSnapshotDelete */
remoteQemuDomainMonitorCommand, /* qemuDomainMonitorCommand */
+ NULL, /* domainSetMemoryParameters */
+ NULL, /* domainGetMemoryParameters */
};
static virNetworkDriver network_driver = {
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 9d22339..906211c 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5327,6 +5327,8 @@ static virDriver testDriver = {
NULL, /* domainRevertToSnapshot */
NULL, /* domainSnapshotDelete */
NULL, /* qemuDomainMonitorCommand */
+ NULL, /* domainSetMemoryParameters */
+ NULL, /* domainGetMemoryParameters */
};
static virNetworkDriver testNetworkDriver = {
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 9101928..1236abb 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -2196,6 +2196,8 @@ static virDriver umlDriver = {
NULL, /* domainRevertToSnapshot */
NULL, /* domainSnapshotDelete */
NULL, /* qemuDomainMonitorCommand */
+ NULL, /* domainSetMemoryParamters */
+ NULL, /* domainGetMemoryParamters */
};
static int
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 56ba41b..f958354 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2006,6 +2006,8 @@ static virDriver xenUnifiedDriver = {
NULL, /* domainRevertToSnapshot */
NULL, /* domainSnapshotDelete */
NULL, /* qemuDomainMonitorCommand */
+ NULL, /* domainSetMemoryParameters */
+ NULL, /* domainGetMemoryParameters */
};
/**