mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
update qemuDomainGetBlkioParameters to use flags
This commit is contained in:
parent
1bb414af27
commit
100c39ca03
@ -4932,18 +4932,16 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom,
|
|||||||
int i;
|
int i;
|
||||||
virCgroupPtr group = NULL;
|
virCgroupPtr group = NULL;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
|
virDomainDefPtr persistentDef = NULL;
|
||||||
unsigned int val;
|
unsigned int val;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int rc;
|
int rc;
|
||||||
|
bool isActive;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
|
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
||||||
qemuDriverLock(driver);
|
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);
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||||
|
|
||||||
if (vm == NULL) {
|
if (vm == NULL) {
|
||||||
@ -4952,12 +4950,6 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virDomainObjIsActive(vm)) {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
|
||||||
"%s", _("domain is not running"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((*nparams) == 0) {
|
if ((*nparams) == 0) {
|
||||||
/* Current number of blkio parameters supported by cgroups */
|
/* Current number of blkio parameters supported by cgroups */
|
||||||
*nparams = QEMU_NB_BLKIO_PARAM;
|
*nparams = QEMU_NB_BLKIO_PARAM;
|
||||||
@ -4971,12 +4963,45 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isActive = virDomainObjIsActive(vm);
|
||||||
|
|
||||||
|
if (flags == VIR_DOMAIN_AFFECT_CURRENT) {
|
||||||
|
if (isActive)
|
||||||
|
flags = VIR_DOMAIN_AFFECT_LIVE;
|
||||||
|
else
|
||||||
|
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||||
|
if (!isActive) {
|
||||||
|
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
|
"%s", _("domain is not running"));
|
||||||
|
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) {
|
if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot find cgroup for domain %s"), vm->def->name);
|
_("cannot find cgroup for domain %s"), vm->def->name);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & VIR_DOMAIN_AFFECT_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_AFFECT_LIVE) {
|
||||||
for (i = 0; i < *nparams; i++) {
|
for (i = 0; i < *nparams; i++) {
|
||||||
virTypedParameterPtr param = ¶ms[i];
|
virTypedParameterPtr param = ¶ms[i];
|
||||||
val = 0;
|
val = 0;
|
||||||
@ -5004,6 +5029,29 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom,
|
|||||||
/* should not hit here */
|
/* should not hit here */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
||||||
|
for (i = 0; i < *nparams; i++) {
|
||||||
|
virTypedParameterPtr param = ¶ms[i];
|
||||||
|
val = 0;
|
||||||
|
param->value.ui = 0;
|
||||||
|
param->type = VIR_TYPED_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 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user