mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-18 10:35:20 +00:00
setmem: implement the code to address the new API in the qemu driver
This patch implements the code to address the new API in the qemu driver. Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
This commit is contained in:
parent
e8340a8b79
commit
cad769001c
@ -1568,12 +1568,22 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
|
||||
static int qemudDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
||||
unsigned int flags) {
|
||||
struct qemud_driver *driver = dom->conn->privateData;
|
||||
qemuDomainObjPrivatePtr priv;
|
||||
virDomainObjPtr vm;
|
||||
virDomainDefPtr persistentDef = NULL;
|
||||
int ret = -1, r;
|
||||
|
||||
virCheckFlags(VIR_DOMAIN_MEM_LIVE |
|
||||
VIR_DOMAIN_MEM_CONFIG, -1);
|
||||
|
||||
if ((flags & (VIR_DOMAIN_MEM_LIVE | VIR_DOMAIN_MEM_CONFIG)) == 0) {
|
||||
qemuReportError(VIR_ERR_INVALID_ARG,
|
||||
_("invalid flag combination: (0x%x)"), flags);
|
||||
}
|
||||
|
||||
qemuDriverLock(driver);
|
||||
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||
qemuDriverUnlock(driver);
|
||||
@ -1594,12 +1604,23 @@ static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
|
||||
if (qemuDomainObjBeginJob(vm) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!virDomainObjIsActive(vm)) {
|
||||
if (!virDomainObjIsActive(vm) && (flags & VIR_DOMAIN_MEM_LIVE)) {
|
||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
||||
"%s", _("domain is not running"));
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_MEM_CONFIG) {
|
||||
if (!vm->persistent) {
|
||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||
_("cannot change persistent config of a transient domain"));
|
||||
goto endjob;
|
||||
}
|
||||
if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_MEM_LIVE) {
|
||||
priv = vm->privateData;
|
||||
qemuDomainObjEnterMonitor(vm);
|
||||
r = qemuMonitorSetBalloon(priv->mon, newmem);
|
||||
@ -1614,6 +1635,13 @@ static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
|
||||
"%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;
|
||||
endjob:
|
||||
@ -1626,6 +1654,10 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
|
||||
return qemudDomainSetMemoryFlags(dom, newmem, VIR_DOMAIN_MEM_LIVE);
|
||||
}
|
||||
|
||||
static int qemudDomainGetInfo(virDomainPtr dom,
|
||||
virDomainInfoPtr info) {
|
||||
struct qemud_driver *driver = dom->conn->privateData;
|
||||
@ -6854,7 +6886,7 @@ static virDriver qemuDriver = {
|
||||
qemudDomainGetMaxMemory, /* domainGetMaxMemory */
|
||||
NULL, /* domainSetMaxMemory */
|
||||
qemudDomainSetMemory, /* domainSetMemory */
|
||||
NULL, /* domainSetMemoryFlags */
|
||||
qemudDomainSetMemoryFlags, /* domainSetMemoryFlags */
|
||||
qemudDomainGetInfo, /* domainGetInfo */
|
||||
qemudDomainSave, /* domainSave */
|
||||
qemudDomainRestore, /* domainRestore */
|
||||
|
Loading…
x
Reference in New Issue
Block a user