mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
maxmem: implement virDomainSetMaxMemory API of the qemu driver
This patch implements the code to support virDomainSetMaxMemory API, and to support VIR_DOMAIN_MEM_MAXIMUM flag in qemudDomainSetMemoryFlags function. As a result, we can change the maximum memory size of inactive QEMU guests. Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
This commit is contained in:
parent
e3b4ca21b2
commit
c1795c5204
@ -2714,8 +2714,9 @@ error:
|
|||||||
* to Domain0 i.e. the domain where the application runs.
|
* to Domain0 i.e. the domain where the application runs.
|
||||||
* This function requires privileged access to the hypervisor.
|
* This function requires privileged access to the hypervisor.
|
||||||
*
|
*
|
||||||
* This command only changes the runtime configuration of the domain,
|
* This command is hypervisor-specific for whether active, persistent,
|
||||||
* so can only be called on an active domain.
|
* or both configurations are changed; for more control, use
|
||||||
|
* virDomainSetMemoryFlags().
|
||||||
*
|
*
|
||||||
* Returns 0 in case of success and -1 in case of failure.
|
* Returns 0 in case of success and -1 in case of failure.
|
||||||
*/
|
*/
|
||||||
|
@ -1580,7 +1580,8 @@ static int qemudDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
|||||||
bool isActive;
|
bool isActive;
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_MEM_LIVE |
|
virCheckFlags(VIR_DOMAIN_MEM_LIVE |
|
||||||
VIR_DOMAIN_MEM_CONFIG, -1);
|
VIR_DOMAIN_MEM_CONFIG |
|
||||||
|
VIR_DOMAIN_MEM_MAXIMUM, -1);
|
||||||
|
|
||||||
qemuDriverLock(driver);
|
qemuDriverLock(driver);
|
||||||
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||||
@ -1593,12 +1594,6 @@ static int qemudDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newmem > vm->def->mem.max_balloon) {
|
|
||||||
qemuReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
"%s", _("cannot set memory higher than max memory"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qemuDomainObjBeginJob(vm) < 0)
|
if (qemuDomainObjBeginJob(vm) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -1610,6 +1605,12 @@ static int qemudDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
|||||||
else
|
else
|
||||||
flags = VIR_DOMAIN_MEM_CONFIG;
|
flags = VIR_DOMAIN_MEM_CONFIG;
|
||||||
}
|
}
|
||||||
|
if (flags == VIR_DOMAIN_MEM_MAXIMUM) {
|
||||||
|
if (isActive)
|
||||||
|
flags = VIR_DOMAIN_MEM_LIVE | VIR_DOMAIN_MEM_MAXIMUM;
|
||||||
|
else
|
||||||
|
flags = VIR_DOMAIN_MEM_CONFIG | VIR_DOMAIN_MEM_MAXIMUM;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isActive && (flags & VIR_DOMAIN_MEM_LIVE)) {
|
if (!isActive && (flags & VIR_DOMAIN_MEM_LIVE)) {
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
@ -1627,27 +1628,56 @@ static int qemudDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_MEM_LIVE) {
|
if (flags & VIR_DOMAIN_MEM_MAXIMUM) {
|
||||||
priv = vm->privateData;
|
/* resize the maximum memory */
|
||||||
qemuDomainObjEnterMonitor(vm);
|
|
||||||
r = qemuMonitorSetBalloon(priv->mon, newmem);
|
|
||||||
qemuDomainObjExitMonitor(vm);
|
|
||||||
qemuAuditMemory(vm, vm->def->mem.cur_balloon, newmem, "update", r == 1);
|
|
||||||
if (r < 0)
|
|
||||||
goto endjob;
|
|
||||||
|
|
||||||
/* Lack of balloon support is a fatal error */
|
if (flags & VIR_DOMAIN_MEM_LIVE) {
|
||||||
if (r == 0) {
|
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
_("cannot resize the maximum memory on an "
|
||||||
"%s", _("cannot set memory of an active domain"));
|
"active domain"));
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (flags& VIR_DOMAIN_MEM_CONFIG) {
|
if (flags & VIR_DOMAIN_MEM_CONFIG) {
|
||||||
persistentDef->mem.cur_balloon = newmem;
|
persistentDef->mem.max_balloon = newmem;
|
||||||
ret = virDomainSaveConfig(driver->configDir, persistentDef);
|
if (persistentDef->mem.cur_balloon > newmem)
|
||||||
goto endjob;
|
persistentDef->mem.cur_balloon = newmem;
|
||||||
|
ret = virDomainSaveConfig(driver->configDir, persistentDef);
|
||||||
|
goto endjob;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/* resize the current memory */
|
||||||
|
|
||||||
|
if (newmem > vm->def->mem.max_balloon) {
|
||||||
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
|
_("cannot set memory higher than max memory"));
|
||||||
|
goto endjob;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & VIR_DOMAIN_MEM_LIVE) {
|
||||||
|
priv = vm->privateData;
|
||||||
|
qemuDomainObjEnterMonitor(vm);
|
||||||
|
r = qemuMonitorSetBalloon(priv->mon, newmem);
|
||||||
|
qemuDomainObjExitMonitor(vm);
|
||||||
|
qemuAuditMemory(vm, vm->def->mem.cur_balloon, newmem, "update",
|
||||||
|
r == 1);
|
||||||
|
if (r < 0)
|
||||||
|
goto endjob;
|
||||||
|
|
||||||
|
/* Lack of balloon support is a fatal error */
|
||||||
|
if (r == 0) {
|
||||||
|
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("cannot set memory of an active domain"));
|
||||||
|
goto endjob;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & VIR_DOMAIN_MEM_CONFIG) {
|
||||||
|
persistentDef->mem.cur_balloon = newmem;
|
||||||
|
ret = virDomainSaveConfig(driver->configDir, persistentDef);
|
||||||
|
goto endjob;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -1661,12 +1691,19 @@ cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
|
static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem)
|
||||||
|
{
|
||||||
return qemudDomainSetMemoryFlags(dom, newmem, VIR_DOMAIN_MEM_LIVE);
|
return qemudDomainSetMemoryFlags(dom, newmem, VIR_DOMAIN_MEM_LIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int qemudDomainSetMaxMemory(virDomainPtr dom, unsigned long memory)
|
||||||
|
{
|
||||||
|
return qemudDomainSetMemoryFlags(dom, memory, VIR_DOMAIN_MEM_MAXIMUM);
|
||||||
|
}
|
||||||
|
|
||||||
static int qemudDomainGetInfo(virDomainPtr dom,
|
static int qemudDomainGetInfo(virDomainPtr dom,
|
||||||
virDomainInfoPtr info) {
|
virDomainInfoPtr info)
|
||||||
|
{
|
||||||
struct qemud_driver *driver = dom->conn->privateData;
|
struct qemud_driver *driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -6849,7 +6886,7 @@ static virDriver qemuDriver = {
|
|||||||
qemudDomainDestroy, /* domainDestroy */
|
qemudDomainDestroy, /* domainDestroy */
|
||||||
qemudDomainGetOSType, /* domainGetOSType */
|
qemudDomainGetOSType, /* domainGetOSType */
|
||||||
qemudDomainGetMaxMemory, /* domainGetMaxMemory */
|
qemudDomainGetMaxMemory, /* domainGetMaxMemory */
|
||||||
NULL, /* domainSetMaxMemory */
|
qemudDomainSetMaxMemory, /* domainSetMaxMemory */
|
||||||
qemudDomainSetMemory, /* domainSetMemory */
|
qemudDomainSetMemory, /* domainSetMemory */
|
||||||
qemudDomainSetMemoryFlags, /* domainSetMemoryFlags */
|
qemudDomainSetMemoryFlags, /* domainSetMemoryFlags */
|
||||||
qemuDomainSetMemoryParameters, /* domainSetMemoryParameters */
|
qemuDomainSetMemoryParameters, /* domainSetMemoryParameters */
|
||||||
|
Loading…
Reference in New Issue
Block a user