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;
|
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;
|
struct qemud_driver *driver = dom->conn->privateData;
|
||||||
qemuDomainObjPrivatePtr priv;
|
qemuDomainObjPrivatePtr priv;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
|
virDomainDefPtr persistentDef = NULL;
|
||||||
int ret = -1, r;
|
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);
|
qemuDriverLock(driver);
|
||||||
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||||
qemuDriverUnlock(driver);
|
qemuDriverUnlock(driver);
|
||||||
@ -1594,24 +1604,42 @@ static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
|
|||||||
if (qemuDomainObjBeginJob(vm) < 0)
|
if (qemuDomainObjBeginJob(vm) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!virDomainObjIsActive(vm)) {
|
if (!virDomainObjIsActive(vm) && (flags & VIR_DOMAIN_MEM_LIVE)) {
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
"%s", _("domain is not running"));
|
"%s", _("domain is not running"));
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
priv = vm->privateData;
|
if (flags & VIR_DOMAIN_MEM_CONFIG) {
|
||||||
qemuDomainObjEnterMonitor(vm);
|
if (!vm->persistent) {
|
||||||
r = qemuMonitorSetBalloon(priv->mon, newmem);
|
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
qemuDomainObjExitMonitor(vm);
|
_("cannot change persistent config of a transient domain"));
|
||||||
qemuAuditMemory(vm, vm->def->mem.cur_balloon, newmem, "update", r == 1);
|
goto endjob;
|
||||||
if (r < 0)
|
}
|
||||||
goto endjob;
|
if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
||||||
|
goto endjob;
|
||||||
|
}
|
||||||
|
|
||||||
/* Lack of balloon support is a fatal error */
|
if (flags & VIR_DOMAIN_MEM_LIVE) {
|
||||||
if (r == 0) {
|
priv = vm->privateData;
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
qemuDomainObjEnterMonitor(vm);
|
||||||
"%s", _("cannot set memory of an active domain"));
|
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;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1626,6 +1654,10 @@ cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
|
||||||
|
return qemudDomainSetMemoryFlags(dom, newmem, VIR_DOMAIN_MEM_LIVE);
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -6854,7 +6886,7 @@ static virDriver qemuDriver = {
|
|||||||
qemudDomainGetMaxMemory, /* domainGetMaxMemory */
|
qemudDomainGetMaxMemory, /* domainGetMaxMemory */
|
||||||
NULL, /* domainSetMaxMemory */
|
NULL, /* domainSetMaxMemory */
|
||||||
qemudDomainSetMemory, /* domainSetMemory */
|
qemudDomainSetMemory, /* domainSetMemory */
|
||||||
NULL, /* domainSetMemoryFlags */
|
qemudDomainSetMemoryFlags, /* domainSetMemoryFlags */
|
||||||
qemudDomainGetInfo, /* domainGetInfo */
|
qemudDomainGetInfo, /* domainGetInfo */
|
||||||
qemudDomainSave, /* domainSave */
|
qemudDomainSave, /* domainSave */
|
||||||
qemudDomainRestore, /* domainRestore */
|
qemudDomainRestore, /* domainRestore */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user