mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
qemu: implement the new flags for setting memory parameters
* src/qemu/qemu_driver.c: update qemuDomainSetMemoryParameters to look at the flag parameter and depending on it save the config or the live amount
This commit is contained in:
parent
7639d1ef31
commit
4b997daaf5
@ -4860,20 +4860,20 @@ cleanup:
|
||||
static int qemuDomainSetMemoryParameters(virDomainPtr dom,
|
||||
virMemoryParameterPtr params,
|
||||
int nparams,
|
||||
unsigned int flags ATTRIBUTE_UNUSED)
|
||||
unsigned int flags)
|
||||
{
|
||||
struct qemud_driver *driver = dom->conn->privateData;
|
||||
int i;
|
||||
virDomainDefPtr persistentDef = NULL;
|
||||
virCgroupPtr group = NULL;
|
||||
virDomainObjPtr vm = NULL;
|
||||
int ret = -1;
|
||||
bool isActive;
|
||||
|
||||
virCheckFlags(VIR_DOMAIN_MEMORY_PARAM_LIVE |
|
||||
VIR_DOMAIN_MEMORY_PARAM_CONFIG, -1);
|
||||
|
||||
qemuDriverLock(driver);
|
||||
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_MEMORY)) {
|
||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
||||
"%s", _("cgroup memory controller is not mounted"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||
|
||||
@ -4883,17 +4883,44 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!virDomainObjIsActive(vm)) {
|
||||
isActive = virDomainObjIsActive(vm);
|
||||
|
||||
if (flags == VIR_DOMAIN_MEMORY_PARAM_CURRENT) {
|
||||
if (isActive)
|
||||
flags = VIR_DOMAIN_MEMORY_PARAM_LIVE;
|
||||
else
|
||||
flags = VIR_DOMAIN_MEMORY_PARAM_CONFIG;
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_MEMORY_PARAM_LIVE) {
|
||||
if (!isActive) {
|
||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
||||
"%s", _("domain is not running"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_MEMORY)) {
|
||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
||||
"%s", _("cgroup memory controller is not mounted"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
|
||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("cannot find cgroup for domain %s"), vm->def->name);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_MEMORY_PARAM_CONFIG) {
|
||||
if (!vm->persistent) {
|
||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||
_("cannot change persistent config of a transient domain"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
for (i = 0; i < nparams; i++) {
|
||||
@ -4908,12 +4935,18 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_MEMORY_PARAM_LIVE) {
|
||||
rc = virCgroupSetMemoryHardLimit(group, params[i].value.ul);
|
||||
if (rc != 0) {
|
||||
virReportSystemError(-rc, "%s",
|
||||
_("unable to set memory hard_limit tunable"));
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_MEMORY_PARAM_CONFIG) {
|
||||
persistentDef->mem.hard_limit = params[i].value.ul;
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT)) {
|
||||
int rc;
|
||||
if (param->type != VIR_DOMAIN_MEMORY_PARAM_ULLONG) {
|
||||
@ -4923,12 +4956,18 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_MEMORY_PARAM_LIVE) {
|
||||
rc = virCgroupSetMemorySoftLimit(group, params[i].value.ul);
|
||||
if (rc != 0) {
|
||||
virReportSystemError(-rc, "%s",
|
||||
_("unable to set memory soft_limit tunable"));
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_MEMORY_PARAM_CONFIG) {
|
||||
persistentDef->mem.soft_limit = params[i].value.ul;
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT)) {
|
||||
int rc;
|
||||
if (param->type != VIR_DOMAIN_MEMORY_PARAM_ULLONG) {
|
||||
@ -4938,12 +4977,17 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_MEMORY_PARAM_LIVE) {
|
||||
rc = virCgroupSetMemSwapHardLimit(group, params[i].value.ul);
|
||||
if (rc != 0) {
|
||||
virReportSystemError(-rc, "%s",
|
||||
_("unable to set swap_hard_limit tunable"));
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
if (flags & VIR_DOMAIN_MEMORY_PARAM_CONFIG) {
|
||||
persistentDef->mem.swap_hard_limit = params[i].value.ul;
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_MEMORY_MIN_GUARANTEE)) {
|
||||
qemuReportError(VIR_ERR_INVALID_ARG,
|
||||
_("Memory tunable `%s' not implemented"), param->field);
|
||||
@ -4955,6 +4999,10 @@ static int qemuDomainSetMemoryParameters(virDomainPtr dom,
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_MEMORY_PARAM_CONFIG) {
|
||||
ret = virDomainSaveConfig(driver->configDir, persistentDef);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virCgroupFree(&group);
|
||||
if (vm)
|
||||
|
Loading…
Reference in New Issue
Block a user