--- src/qemu/qemu_driver.c | 124 +++++++++++++++++++++++++++++++++--------------- 1 files changed, 86 insertions(+), 38 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 691965d..ddd3d58 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4725,18 +4725,16 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom, int i; virCgroupPtr group = NULL; virDomainObjPtr vm = NULL; + virDomainDefPtr persistentDef = NULL; unsigned int val; int ret = -1; int rc; + bool isActive; - virCheckFlags(0, -1); + virCheckFlags(VIR_DOMAIN_BLKIO_PARAM_LIVE | + VIR_DOMAIN_BLKIO_PARAM_CONFIG, -1); qemuDriverLock(driver); - if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) { - qemuReportError(VIR_ERR_NO_SUPPORT, _("blkio cgroup isn't mounted")); - goto cleanup; - } - vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (vm == NULL) { @@ -4745,12 +4743,6 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom, goto cleanup; } - if (!virDomainObjIsActive(vm)) { - qemuReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("domain is not running")); - goto cleanup; - } - if ((*nparams) == 0) { /* Current number of blkio parameters supported by cgroups */ *nparams = QEMU_NB_BLKIO_PARAM; @@ -4764,37 +4756,93 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom, 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; + isActive = virDomainObjIsActive(vm); + + if (flags == VIR_DOMAIN_BLKIO_PARAM_CURRENT) { + if (isActive) + flags = VIR_DOMAIN_BLKIO_PARAM_LIVE; + else + flags = VIR_DOMAIN_BLKIO_PARAM_CONFIG; } - for (i = 0; i < *nparams; i++) { - virBlkioParameterPtr param = ¶ms[i]; - val = 0; - param->value.ui = 0; - param->type = VIR_DOMAIN_BLKIO_PARAM_UINT; + if (flags & VIR_DOMAIN_BLKIO_PARAM_LIVE) { + if (!isActive) { + qemuReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("domain is not running")); + goto cleanup; + } - switch (i) { - case 0: /* fill blkio weight here */ - rc = virCgroupGetBlkioWeight(group, &val); - if (rc != 0) { - virReportSystemError(-rc, "%s", - _("unable to get blkio weight")); - goto cleanup; - } - if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) { - qemuReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("Field blkio weight too long for destination")); - goto cleanup; + if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) { + qemuReportError(VIR_ERR_NO_SUPPORT, _("blkio cgroup isn't 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_BLKIO_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 (flags & VIR_DOMAIN_BLKIO_PARAM_LIVE) { + for (i = 0; i < *nparams; i++) { + virBlkioParameterPtr param = ¶ms[i]; + val = 0; + param->value.ui = 0; + param->type = VIR_DOMAIN_BLKIO_PARAM_UINT; + + switch (i) { + case 0: /* fill blkio weight here */ + rc = virCgroupGetBlkioWeight(group, &val); + if (rc != 0) { + virReportSystemError(-rc, "%s", + _("unable to get blkio weight")); + goto cleanup; + } + if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) { + qemuReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Field blkio weight too long for destination")); + goto cleanup; + } + param->value.ui = val; + break; + + default: + break; + /* should not hit here */ } - param->value.ui = val; - break; + } + } else if (flags & VIR_DOMAIN_BLKIO_PARAM_CONFIG) { + for (i = 0; i < *nparams; i++) { + virBlkioParameterPtr param = ¶ms[i]; + val = 0; + param->value.ui = 0; + param->type = VIR_DOMAIN_BLKIO_PARAM_UINT; + + switch (i) { + case 0: /* fill blkio weight here */ + if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) { + qemuReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Field blkio weight too long for destination")); + goto cleanup; + } + param->value.ui = persistentDef->blkio.weight; + break; - default: - break; - /* should not hit here */ + default: + break; + /* should not hit here */ + } } } -- 1.7.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list