提交 e8340a8b 编写于 作者: T Taku Izumi 提交者: Eric Blake

setmem: introduce a new libvirt API (virDomainSetMemoryFlags)

This patch introduces a new libvirt API (virDomainSetMemoryFlags) and
a flag (virDomainMemoryModFlags).
Signed-off-by: NTaku Izumi <izumi.taku@jp.fujitsu.com>
上级 a236732e
...@@ -157,6 +157,7 @@ Patches have also been contributed by: ...@@ -157,6 +157,7 @@ Patches have also been contributed by:
Christophe Fergeau <teuf@gnome.org> Christophe Fergeau <teuf@gnome.org>
Markus Groß <gross@univention.de> Markus Groß <gross@univention.de>
Phil Petty <phpetty@cisco.com> Phil Petty <phpetty@cisco.com>
Taku Izumi <izumi.taku@jp.fujitsu.com>
[....send patches to get your name here....] [....send patches to get your name here....]
......
...@@ -780,6 +780,13 @@ int virDomainGetMemoryParameters(virDomainPtr domain, ...@@ -780,6 +780,13 @@ int virDomainGetMemoryParameters(virDomainPtr domain,
virMemoryParameterPtr params, virMemoryParameterPtr params,
int *nparams, unsigned int flags); int *nparams, unsigned int flags);
/* Memory size modification flags. */
typedef enum {
VIR_DOMAIN_MEM_LIVE = (1 << 0), /* affect active domain */
VIR_DOMAIN_MEM_CONFIG = (1 << 1), /* affect next boot */
} virDomainMemoryModFlags;
/* /*
* Dynamic control of domains * Dynamic control of domains
*/ */
...@@ -795,6 +802,9 @@ int virDomainSetMaxMemory (virDomainPtr domain, ...@@ -795,6 +802,9 @@ int virDomainSetMaxMemory (virDomainPtr domain,
unsigned long memory); unsigned long memory);
int virDomainSetMemory (virDomainPtr domain, int virDomainSetMemory (virDomainPtr domain,
unsigned long memory); unsigned long memory);
int virDomainSetMemoryFlags (virDomainPtr domain,
unsigned long memory,
unsigned int flags);
int virDomainGetMaxVcpus (virDomainPtr domain); int virDomainGetMaxVcpus (virDomainPtr domain);
int virDomainGetSecurityLabel (virDomainPtr domain, int virDomainGetSecurityLabel (virDomainPtr domain,
virSecurityLabelPtr seclabel); virSecurityLabelPtr seclabel);
......
...@@ -133,6 +133,10 @@ typedef int ...@@ -133,6 +133,10 @@ typedef int
typedef int typedef int
(*virDrvDomainSetMemory) (virDomainPtr domain, (*virDrvDomainSetMemory) (virDomainPtr domain,
unsigned long memory); unsigned long memory);
typedef int
(*virDrvDomainSetMemoryFlags) (virDomainPtr domain,
unsigned long memory,
unsigned int flags);
typedef int typedef int
(*virDrvDomainSetMemoryParameters) (*virDrvDomainSetMemoryParameters)
(virDomainPtr domain, (virDomainPtr domain,
...@@ -536,6 +540,7 @@ struct _virDriver { ...@@ -536,6 +540,7 @@ struct _virDriver {
virDrvDomainGetMaxMemory domainGetMaxMemory; virDrvDomainGetMaxMemory domainGetMaxMemory;
virDrvDomainSetMaxMemory domainSetMaxMemory; virDrvDomainSetMaxMemory domainSetMaxMemory;
virDrvDomainSetMemory domainSetMemory; virDrvDomainSetMemory domainSetMemory;
virDrvDomainSetMemoryFlags domainSetMemoryFlags;
virDrvDomainGetInfo domainGetInfo; virDrvDomainGetInfo domainGetInfo;
virDrvDomainSave domainSave; virDrvDomainSave domainSave;
virDrvDomainRestore domainRestore; virDrvDomainRestore domainRestore;
......
...@@ -4593,6 +4593,7 @@ static virDriver esxDriver = { ...@@ -4593,6 +4593,7 @@ static virDriver esxDriver = {
esxDomainGetMaxMemory, /* domainGetMaxMemory */ esxDomainGetMaxMemory, /* domainGetMaxMemory */
esxDomainSetMaxMemory, /* domainSetMaxMemory */ esxDomainSetMaxMemory, /* domainSetMaxMemory */
esxDomainSetMemory, /* domainSetMemory */ esxDomainSetMemory, /* domainSetMemory */
NULL, /* domainSetMemoryFlags */
esxDomainGetInfo, /* domainGetInfo */ esxDomainGetInfo, /* domainGetInfo */
NULL, /* domainSave */ NULL, /* domainSave */
NULL, /* domainRestore */ NULL, /* domainRestore */
......
...@@ -2846,6 +2846,68 @@ error: ...@@ -2846,6 +2846,68 @@ error:
return -1; return -1;
} }
/*
* virDomainSetMemoryFlags
* @domain: a domain object or NULL
* @memory: the memory size in kilobytes
* @flags: an OR'ed set of virDomainMemoryModFlags
*
* Dynamically change the target amount of physical memory allocated to a
* domain. If domain is NULL, then this change the amount of memory reserved
* to Domain0 i.e. the domain where the application runs.
* This funcation may requires privileged access to the hypervisor.
*
* @flags must include VIR_DOMAIN_MEM_LIVE to affect a running
* domain (which may fail if domain is not active), or
* VIR_DOMAIN_MEM_CONFIG to affect the next boot via the XML
* description of the domain. Both flags may be set.
*
* Returns 0 in case of success, -1 in case of failure.
*/
int
virDomainSetMemoryFlags(virDomainPtr domain, unsigned long memory,
unsigned int flags)
{
virConnectPtr conn;
VIR_DOMAIN_DEBUG(domain, "memory=%lu flags=%u", memory, flags);
virResetLastError();
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
if (domain->conn->flags & VIR_CONNECT_RO) {
virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
goto error;
}
if (memory < 4096 ||
(flags & (VIR_DOMAIN_MEM_LIVE | VIR_DOMAIN_MEM_CONFIG)) == 0) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
conn = domain->conn;
if (conn->driver->domainSetMemoryFlags) {
int ret;
ret = conn->driver->domainSetMemoryFlags(domain, memory, flags);
if (ret < 0)
goto error;
return ret;
}
error:
virDispatchError(domain->conn);
return -1;
}
/** /**
* virDomainSetMemoryParameters: * virDomainSetMemoryParameters:
* @domain: pointer to domain object * @domain: pointer to domain object
......
...@@ -426,6 +426,7 @@ LIBVIRT_0.8.8 { ...@@ -426,6 +426,7 @@ LIBVIRT_0.8.8 {
LIBVIRT_0.9.0 { LIBVIRT_0.9.0 {
global: global:
virDomainSetMemoryFlags;
virEventRegisterDefaultImpl; virEventRegisterDefaultImpl;
virEventRunDefaultImpl; virEventRunDefaultImpl;
} LIBVIRT_0.8.8; } LIBVIRT_0.8.8;
......
...@@ -2851,6 +2851,7 @@ static virDriver lxcDriver = { ...@@ -2851,6 +2851,7 @@ static virDriver lxcDriver = {
lxcDomainGetMaxMemory, /* domainGetMaxMemory */ lxcDomainGetMaxMemory, /* domainGetMaxMemory */
lxcDomainSetMaxMemory, /* domainSetMaxMemory */ lxcDomainSetMaxMemory, /* domainSetMaxMemory */
lxcDomainSetMemory, /* domainSetMemory */ lxcDomainSetMemory, /* domainSetMemory */
NULL, /* domainSetMemoryFlags */
lxcDomainGetInfo, /* domainGetInfo */ lxcDomainGetInfo, /* domainGetInfo */
NULL, /* domainSave */ NULL, /* domainSave */
NULL, /* domainRestore */ NULL, /* domainRestore */
......
...@@ -750,6 +750,7 @@ static virDriver oneDriver = { ...@@ -750,6 +750,7 @@ static virDriver oneDriver = {
NULL, /* domainGetMaxMemory */ NULL, /* domainGetMaxMemory */
NULL, /* domainSetMaxMemory */ NULL, /* domainSetMaxMemory */
NULL, /* domainSetMemory */ NULL, /* domainSetMemory */
NULL, /* domainSetMemoryFlags */
oneDomainGetInfo, /* domainGetInfo */ oneDomainGetInfo, /* domainGetInfo */
NULL, /* domainSave */ NULL, /* domainSave */
NULL, /* domainRestore */ NULL, /* domainRestore */
......
...@@ -1571,6 +1571,7 @@ static virDriver openvzDriver = { ...@@ -1571,6 +1571,7 @@ static virDriver openvzDriver = {
NULL, /* domainGetMaxMemory */ NULL, /* domainGetMaxMemory */
NULL, /* domainSetMaxMemory */ NULL, /* domainSetMaxMemory */
NULL, /* domainSetMemory */ NULL, /* domainSetMemory */
NULL, /* domainSetMemoryFlags */
openvzDomainGetInfo, /* domainGetInfo */ openvzDomainGetInfo, /* domainGetInfo */
NULL, /* domainSave */ NULL, /* domainSave */
NULL, /* domainRestore */ NULL, /* domainRestore */
......
...@@ -3973,6 +3973,7 @@ static virDriver phypDriver = { ...@@ -3973,6 +3973,7 @@ static virDriver phypDriver = {
NULL, /* domainGetMaxMemory */ NULL, /* domainGetMaxMemory */
NULL, /* domainSetMaxMemory */ NULL, /* domainSetMaxMemory */
NULL, /* domainSetMemory */ NULL, /* domainSetMemory */
NULL, /* domainSetMemoryFlags */
phypDomainGetInfo, /* domainGetInfo */ phypDomainGetInfo, /* domainGetInfo */
NULL, /* domainSave */ NULL, /* domainSave */
NULL, /* domainRestore */ NULL, /* domainRestore */
......
...@@ -6854,6 +6854,7 @@ static virDriver qemuDriver = { ...@@ -6854,6 +6854,7 @@ static virDriver qemuDriver = {
qemudDomainGetMaxMemory, /* domainGetMaxMemory */ qemudDomainGetMaxMemory, /* domainGetMaxMemory */
NULL, /* domainSetMaxMemory */ NULL, /* domainSetMaxMemory */
qemudDomainSetMemory, /* domainSetMemory */ qemudDomainSetMemory, /* domainSetMemory */
NULL, /* domainSetMemoryFlags */
qemudDomainGetInfo, /* domainGetInfo */ qemudDomainGetInfo, /* domainGetInfo */
qemudDomainSave, /* domainSave */ qemudDomainSave, /* domainSave */
qemudDomainRestore, /* domainRestore */ qemudDomainRestore, /* domainRestore */
......
...@@ -10876,6 +10876,7 @@ static virDriver remote_driver = { ...@@ -10876,6 +10876,7 @@ static virDriver remote_driver = {
remoteDomainGetMaxMemory, /* domainGetMaxMemory */ remoteDomainGetMaxMemory, /* domainGetMaxMemory */
remoteDomainSetMaxMemory, /* domainSetMaxMemory */ remoteDomainSetMaxMemory, /* domainSetMaxMemory */
remoteDomainSetMemory, /* domainSetMemory */ remoteDomainSetMemory, /* domainSetMemory */
NULL, /* domainSetMemoryFlags */
remoteDomainGetInfo, /* domainGetInfo */ remoteDomainGetInfo, /* domainGetInfo */
remoteDomainSave, /* domainSave */ remoteDomainSave, /* domainSave */
remoteDomainRestore, /* domainRestore */ remoteDomainRestore, /* domainRestore */
......
...@@ -5365,6 +5365,7 @@ static virDriver testDriver = { ...@@ -5365,6 +5365,7 @@ static virDriver testDriver = {
testGetMaxMemory, /* domainGetMaxMemory */ testGetMaxMemory, /* domainGetMaxMemory */
testSetMaxMemory, /* domainSetMaxMemory */ testSetMaxMemory, /* domainSetMaxMemory */
testSetMemory, /* domainSetMemory */ testSetMemory, /* domainSetMemory */
NULL, /* domainSetMemoryFlags */
testGetDomainInfo, /* domainGetInfo */ testGetDomainInfo, /* domainGetInfo */
testDomainSave, /* domainSave */ testDomainSave, /* domainSave */
testDomainRestore, /* domainRestore */ testDomainRestore, /* domainRestore */
......
...@@ -2167,6 +2167,7 @@ static virDriver umlDriver = { ...@@ -2167,6 +2167,7 @@ static virDriver umlDriver = {
umlDomainGetMaxMemory, /* domainGetMaxMemory */ umlDomainGetMaxMemory, /* domainGetMaxMemory */
umlDomainSetMaxMemory, /* domainSetMaxMemory */ umlDomainSetMaxMemory, /* domainSetMaxMemory */
umlDomainSetMemory, /* domainSetMemory */ umlDomainSetMemory, /* domainSetMemory */
NULL, /* domainSetMemoryFlags */
umlDomainGetInfo, /* domainGetInfo */ umlDomainGetInfo, /* domainGetInfo */
NULL, /* domainSave */ NULL, /* domainSave */
NULL, /* domainRestore */ NULL, /* domainRestore */
......
...@@ -8555,6 +8555,7 @@ virDriver NAME(Driver) = { ...@@ -8555,6 +8555,7 @@ virDriver NAME(Driver) = {
NULL, /* domainGetMaxMemory */ NULL, /* domainGetMaxMemory */
NULL, /* domainSetMaxMemory */ NULL, /* domainSetMaxMemory */
vboxDomainSetMemory, /* domainSetMemory */ vboxDomainSetMemory, /* domainSetMemory */
NULL, /* domainSetMemoryFlags */
vboxDomainGetInfo, /* domainGetInfo */ vboxDomainGetInfo, /* domainGetInfo */
vboxDomainSave, /* domainSave */ vboxDomainSave, /* domainSave */
NULL, /* domainRestore */ NULL, /* domainRestore */
......
...@@ -925,6 +925,7 @@ static virDriver vmwareDriver = { ...@@ -925,6 +925,7 @@ static virDriver vmwareDriver = {
NULL, /* domainGetMaxMemory */ NULL, /* domainGetMaxMemory */
NULL, /* domainSetMaxMemory */ NULL, /* domainSetMaxMemory */
NULL, /* domainSetMemory */ NULL, /* domainSetMemory */
NULL, /* domainSetMemoryFlags */
vmwareDomainGetInfo, /* domainGetInfo */ vmwareDomainGetInfo, /* domainGetInfo */
NULL, /* domainSave */ NULL, /* domainSave */
NULL, /* domainRestore */ NULL, /* domainRestore */
......
...@@ -2034,6 +2034,7 @@ static virDriver xenUnifiedDriver = { ...@@ -2034,6 +2034,7 @@ static virDriver xenUnifiedDriver = {
xenUnifiedDomainGetMaxMemory, /* domainGetMaxMemory */ xenUnifiedDomainGetMaxMemory, /* domainGetMaxMemory */
xenUnifiedDomainSetMaxMemory, /* domainSetMaxMemory */ xenUnifiedDomainSetMaxMemory, /* domainSetMaxMemory */
xenUnifiedDomainSetMemory, /* domainSetMemory */ xenUnifiedDomainSetMemory, /* domainSetMemory */
NULL, /*domainSetMemoryFlags */
xenUnifiedDomainGetInfo, /* domainGetInfo */ xenUnifiedDomainGetInfo, /* domainGetInfo */
xenUnifiedDomainSave, /* domainSave */ xenUnifiedDomainSave, /* domainSave */
xenUnifiedDomainRestore, /* domainRestore */ xenUnifiedDomainRestore, /* domainRestore */
......
...@@ -1803,6 +1803,7 @@ static virDriver xenapiDriver = { ...@@ -1803,6 +1803,7 @@ static virDriver xenapiDriver = {
xenapiDomainGetMaxMemory, /* domainGetMaxMemory */ xenapiDomainGetMaxMemory, /* domainGetMaxMemory */
xenapiDomainSetMaxMemory, /* domainSetMaxMemory */ xenapiDomainSetMaxMemory, /* domainSetMaxMemory */
NULL, /* domainSetMemory */ NULL, /* domainSetMemory */
NULL, /* domainSetMemoryFlags */
xenapiDomainGetInfo, /* domainGetInfo */ xenapiDomainGetInfo, /* domainGetInfo */
NULL, /* domainSave */ NULL, /* domainSave */
NULL, /* domainRestore */ NULL, /* domainRestore */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册