mirror of https://gitee.com/openkylin/libvirt.git
qemu: implement the new flags for getting memory parameters
* src/qemu/qemu_driver.c: update qemuDomainGetMemoryParameters to look at the flag parameter and depending on it read the config or the live amount
This commit is contained in:
parent
118eac373d
commit
7639d1ef31
|
@ -4966,24 +4966,23 @@ cleanup:
|
||||||
static int qemuDomainGetMemoryParameters(virDomainPtr dom,
|
static int qemuDomainGetMemoryParameters(virDomainPtr dom,
|
||||||
virMemoryParameterPtr params,
|
virMemoryParameterPtr params,
|
||||||
int *nparams,
|
int *nparams,
|
||||||
unsigned int flags ATTRIBUTE_UNUSED)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
struct qemud_driver *driver = dom->conn->privateData;
|
struct qemud_driver *driver = dom->conn->privateData;
|
||||||
int i;
|
int i;
|
||||||
virCgroupPtr group = NULL;
|
virCgroupPtr group = NULL;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
|
virDomainDefPtr persistentDef = NULL;
|
||||||
unsigned long long val;
|
unsigned long long val;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int rc;
|
int rc;
|
||||||
|
bool isActive;
|
||||||
|
|
||||||
|
virCheckFlags(VIR_DOMAIN_MEMORY_PARAM_LIVE |
|
||||||
|
VIR_DOMAIN_MEMORY_PARAM_CONFIG, -1);
|
||||||
|
|
||||||
qemuDriverLock(driver);
|
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);
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||||
|
|
||||||
if (vm == NULL) {
|
if (vm == NULL) {
|
||||||
|
@ -4992,10 +4991,43 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virDomainObjIsActive(vm)) {
|
isActive = virDomainObjIsActive(vm);
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
|
||||||
"%s", _("domain is not running"));
|
if (flags == VIR_DOMAIN_MEMORY_PARAM_CURRENT) {
|
||||||
goto cleanup;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*nparams) == 0) {
|
if ((*nparams) == 0) {
|
||||||
|
@ -5011,10 +5043,47 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
|
if (flags & VIR_DOMAIN_MEMORY_PARAM_CONFIG) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
for (i = 0; i < *nparams; i++) {
|
||||||
_("cannot find cgroup for domain %s"), vm->def->name);
|
virMemoryParameterPtr param = ¶ms[i];
|
||||||
goto cleanup;
|
val = 0;
|
||||||
|
param->value.ul = 0;
|
||||||
|
param->type = VIR_DOMAIN_MEMORY_PARAM_ULLONG;
|
||||||
|
|
||||||
|
switch (i) {
|
||||||
|
case 0: /* fill memory hard limit here */
|
||||||
|
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_HARD_LIMIT) == NULL) {
|
||||||
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("Field memory hard limit too long for destination"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
param->value.ul = persistentDef->mem.hard_limit;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1: /* fill memory soft limit here */
|
||||||
|
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT) == NULL) {
|
||||||
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("Field memory soft limit too long for destination"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
param->value.ul = persistentDef->mem.soft_limit;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: /* fill swap hard limit here */
|
||||||
|
if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT) == NULL) {
|
||||||
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("Field swap hard limit too long for destination"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
param->value.ul = persistentDef->mem.swap_hard_limit;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
/* should not hit here */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < QEMU_NB_MEM_PARAM; i++) {
|
for (i = 0; i < QEMU_NB_MEM_PARAM; i++) {
|
||||||
|
@ -5075,6 +5144,7 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
*nparams = QEMU_NB_MEM_PARAM;
|
*nparams = QEMU_NB_MEM_PARAM;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue