1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

qemu: Make Set*Mem commands hotplug only

SetMem and SetMaxMem are hotplug only APIs, any persistent config
changes are supposed to go via XML definition. The original implementation
of these calls were incorrect and had the nasty side effect of making
a psuedo persistent change that would be lost after libvirtd restart
(I didn't know any better).

Fix these APIs to rightly reject non running domains.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2010-02-09 16:25:06 -05:00
parent 535db41be8
commit 09a33fd8a9

View File

@ -3764,14 +3764,21 @@ static int qemudDomainSetMaxMemory(virDomainPtr dom, unsigned long newmax) {
goto cleanup; goto cleanup;
} }
if (newmax < vm->def->memory) { if (!virDomainObjIsActive(vm)) {
qemuReportError(VIR_ERR_INVALID_ARG, qemuReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cannot set max memory lower than current memory")); "%s", _("domain is not running"));
goto cleanup;; goto cleanup;
} }
vm->def->maxmem = newmax; if (newmax < vm->def->memory) {
ret = 0; qemuReportError(VIR_ERR_INVALID_ARG, "%s",
_("cannot set max memory lower than current memory"));
goto cleanup;
}
/* There isn't any way to change this value for a running qemu guest */
qemuReportError(VIR_ERR_NO_SUPPORT,
"%s", _("cannot set max memory of an active domain"));
cleanup: cleanup:
if (vm) if (vm)
@ -3782,8 +3789,9 @@ cleanup:
static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) { static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
struct qemud_driver *driver = dom->conn->privateData; struct qemud_driver *driver = dom->conn->privateData;
qemuDomainObjPrivatePtr priv;
virDomainObjPtr vm; virDomainObjPtr vm;
int ret = -1; int ret = -1, r;
qemuDriverLock(driver); qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@ -3796,6 +3804,12 @@ static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
goto cleanup; goto cleanup;
} }
if (!virDomainObjIsActive(vm)) {
qemuReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
goto cleanup;
}
if (newmem > vm->def->maxmem) { if (newmem > vm->def->maxmem) {
qemuReportError(VIR_ERR_INVALID_ARG, qemuReportError(VIR_ERR_INVALID_ARG,
"%s", _("cannot set memory higher than max memory")); "%s", _("cannot set memory higher than max memory"));
@ -3805,25 +3819,21 @@ static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
if (qemuDomainObjBeginJob(vm) < 0) if (qemuDomainObjBeginJob(vm) < 0)
goto cleanup; goto cleanup;
if (virDomainObjIsActive(vm)) { priv = vm->privateData;
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjEnterMonitor(vm);
qemuDomainObjEnterMonitor(vm); r = qemuMonitorSetBalloon(priv->mon, newmem);
int r = qemuMonitorSetBalloon(priv->mon, newmem); qemuDomainObjExitMonitor(vm);
qemuDomainObjExitMonitor(vm); if (r < 0)
if (r < 0) goto endjob;
goto endjob;
/* Lack of balloon support is a fatal error */ /* Lack of balloon support is a fatal error */
if (r == 0) { if (r == 0) {
qemuReportError(VIR_ERR_NO_SUPPORT, qemuReportError(VIR_ERR_NO_SUPPORT,
"%s", _("cannot set memory of an active domain")); "%s", _("cannot set memory of an active domain"));
goto endjob; goto endjob;
}
} else {
vm->def->memory = newmem;
} }
ret = 0;
ret = 0;
endjob: endjob:
if (qemuDomainObjEndJob(vm) == 0) if (qemuDomainObjEndJob(vm) == 0)
vm = NULL; vm = NULL;