mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
domain_cgroup.c: add virDomainCgroupSetupDomainBlkioParameters()
After the introduction of virDomainDriverMergeBlkioDevice() in a previous patch, it is now clear that lxcDomainSetBlkioParameters() and qemuDomainSetBlkioParameters() uses the same loop to set cgroup blkio parameter of a domain. Avoid the repetition by adding a new helper called virDomainCgroupSetupDomainBlkioParameters(). Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
2450a04119
commit
ac87d3520a
@ -78,6 +78,7 @@
|
||||
@SRCDIR@/src/hyperv/hyperv_driver.c
|
||||
@SRCDIR@/src/hyperv/hyperv_util.c
|
||||
@SRCDIR@/src/hyperv/hyperv_wmi.c
|
||||
@SRCDIR@/src/hypervisor/domain_cgroup.c
|
||||
@SRCDIR@/src/hypervisor/domain_driver.c
|
||||
@SRCDIR@/src/interface/interface_backend_netcf.c
|
||||
@SRCDIR@/src/interface/interface_backend_udev.c
|
||||
|
@ -21,6 +21,9 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "domain_cgroup.h"
|
||||
#include "domain_driver.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_DOMAIN
|
||||
|
||||
|
||||
int
|
||||
@ -84,3 +87,101 @@ virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virDomainCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup,
|
||||
virDomainDefPtr def,
|
||||
virTypedParameterPtr params,
|
||||
int nparams)
|
||||
{
|
||||
size_t i;
|
||||
int ret = 0;
|
||||
|
||||
for (i = 0; i < nparams; i++) {
|
||||
virTypedParameterPtr param = ¶ms[i];
|
||||
|
||||
if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) {
|
||||
if (virCgroupSetBlkioWeight(cgroup, params[i].value.ui) < 0)
|
||||
ret = -1;
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) ||
|
||||
STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) ||
|
||||
STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS) ||
|
||||
STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) ||
|
||||
STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
|
||||
size_t ndevices;
|
||||
virBlkioDevicePtr devices = NULL;
|
||||
size_t j;
|
||||
|
||||
if (virDomainDriverParseBlkioDeviceStr(params[i].value.s,
|
||||
param->field,
|
||||
&devices,
|
||||
&ndevices) < 0) {
|
||||
ret = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceWeight(cgroup, devices[j].path,
|
||||
&devices[j].weight) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceReadIops(cgroup, devices[j].path,
|
||||
&devices[j].riops) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceWriteIops(cgroup, devices[j].path,
|
||||
&devices[j].wiops) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceReadBps(cgroup, devices[j].path,
|
||||
&devices[j].rbps) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devices[j].path,
|
||||
&devices[j].wbps) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
virReportError(VIR_ERR_INVALID_ARG, _("Unknown blkio parameter %s"),
|
||||
param->field);
|
||||
ret = -1;
|
||||
virBlkioDeviceArrayClear(devices, ndevices);
|
||||
g_free(devices);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (j != ndevices ||
|
||||
virDomainDriverMergeBlkioDevice(&def->blkio.devices,
|
||||
&def->blkio.ndevices,
|
||||
devices, ndevices,
|
||||
param->field) < 0)
|
||||
ret = -1;
|
||||
|
||||
virBlkioDeviceArrayClear(devices, ndevices);
|
||||
g_free(devices);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -26,3 +26,7 @@
|
||||
|
||||
int virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blkio);
|
||||
int virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem);
|
||||
int virDomainCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup,
|
||||
virDomainDefPtr def,
|
||||
virTypedParameterPtr params,
|
||||
int nparams);
|
||||
|
@ -1392,6 +1392,7 @@ virSetConnectStorage;
|
||||
|
||||
# hypervisor/domain_cgroup.h
|
||||
virDomainCgroupSetupBlkio;
|
||||
virDomainCgroupSetupDomainBlkioParameters;
|
||||
virDomainCgroupSetupMemtune;
|
||||
|
||||
|
||||
|
@ -56,6 +56,7 @@
|
||||
#include "virpidfile.h"
|
||||
#include "virfdstream.h"
|
||||
#include "domain_audit.h"
|
||||
#include "domain_cgroup.h"
|
||||
#include "domain_driver.h"
|
||||
#include "domain_nwfilter.h"
|
||||
#include "virinitctl.h"
|
||||
@ -2364,90 +2365,8 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
|
||||
|
||||
ret = 0;
|
||||
if (def) {
|
||||
for (i = 0; i < nparams; i++) {
|
||||
virTypedParameterPtr param = ¶ms[i];
|
||||
|
||||
if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) {
|
||||
if (virCgroupSetBlkioWeight(priv->cgroup, params[i].value.ui) < 0)
|
||||
ret = -1;
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) ||
|
||||
STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) ||
|
||||
STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS) ||
|
||||
STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) ||
|
||||
STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
|
||||
virCgroupPtr cgroup = priv->cgroup;
|
||||
size_t ndevices;
|
||||
virBlkioDevicePtr devices = NULL;
|
||||
size_t j;
|
||||
|
||||
if (virDomainDriverParseBlkioDeviceStr(params[i].value.s,
|
||||
param->field,
|
||||
&devices,
|
||||
&ndevices) < 0) {
|
||||
ret = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceWeight(cgroup, devices[j].path,
|
||||
&devices[j].weight) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceReadIops(cgroup, devices[j].path,
|
||||
&devices[j].riops) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceWriteIops(cgroup, devices[j].path,
|
||||
&devices[j].wiops) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceReadBps(cgroup, devices[j].path,
|
||||
&devices[j].rbps) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devices[j].path,
|
||||
&devices[j].wbps) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
virReportError(VIR_ERR_INVALID_ARG, _("Unknown blkio parameter %s"),
|
||||
param->field);
|
||||
ret = -1;
|
||||
virBlkioDeviceArrayClear(devices, ndevices);
|
||||
VIR_FREE(devices);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (j != ndevices ||
|
||||
virDomainDriverMergeBlkioDevice(&def->blkio.devices,
|
||||
&def->blkio.ndevices,
|
||||
devices, ndevices,
|
||||
param->field) < 0)
|
||||
ret = -1;
|
||||
virBlkioDeviceArrayClear(devices, ndevices);
|
||||
VIR_FREE(devices);
|
||||
}
|
||||
}
|
||||
ret = virDomainCgroupSetupDomainBlkioParameters(priv->cgroup, def,
|
||||
params, nparams);
|
||||
}
|
||||
if (ret < 0)
|
||||
goto endjob;
|
||||
|
@ -65,6 +65,7 @@
|
||||
#include "viruuid.h"
|
||||
#include "domain_conf.h"
|
||||
#include "domain_audit.h"
|
||||
#include "domain_cgroup.h"
|
||||
#include "domain_driver.h"
|
||||
#include "node_device_conf.h"
|
||||
#include "virpci.h"
|
||||
@ -9375,91 +9376,8 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
|
||||
|
||||
ret = 0;
|
||||
if (def) {
|
||||
for (i = 0; i < nparams; i++) {
|
||||
virTypedParameterPtr param = ¶ms[i];
|
||||
|
||||
if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) {
|
||||
if (virCgroupSetBlkioWeight(priv->cgroup, param->value.ui) < 0 ||
|
||||
virCgroupGetBlkioWeight(priv->cgroup, &def->blkio.weight) < 0)
|
||||
ret = -1;
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) ||
|
||||
STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) ||
|
||||
STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS) ||
|
||||
STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) ||
|
||||
STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
|
||||
virCgroupPtr cgroup = priv->cgroup;
|
||||
size_t ndevices;
|
||||
virBlkioDevicePtr devices = NULL;
|
||||
size_t j;
|
||||
|
||||
if (virDomainDriverParseBlkioDeviceStr(param->value.s,
|
||||
param->field,
|
||||
&devices,
|
||||
&ndevices) < 0) {
|
||||
ret = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceWeight(cgroup, devices[j].path,
|
||||
&devices[j].weight) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceReadIops(cgroup, devices[j].path,
|
||||
&devices[j].riops) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceWriteIops(cgroup, devices[j].path,
|
||||
&devices[j].wiops) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceReadBps(cgroup, devices[j].path,
|
||||
&devices[j].rbps) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devices[j].path,
|
||||
&devices[j].wbps) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
virReportError(VIR_ERR_INVALID_ARG, _("Unknown blkio parameter %s"),
|
||||
param->field);
|
||||
ret = -1;
|
||||
virBlkioDeviceArrayClear(devices, ndevices);
|
||||
VIR_FREE(devices);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (j != ndevices ||
|
||||
virDomainDriverMergeBlkioDevice(&def->blkio.devices,
|
||||
&def->blkio.ndevices,
|
||||
devices, ndevices,
|
||||
param->field) < 0)
|
||||
ret = -1;
|
||||
virBlkioDeviceArrayClear(devices, ndevices);
|
||||
VIR_FREE(devices);
|
||||
}
|
||||
}
|
||||
ret = virDomainCgroupSetupDomainBlkioParameters(priv->cgroup, def,
|
||||
params, nparams);
|
||||
|
||||
if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
|
||||
goto endjob;
|
||||
|
Loading…
Reference in New Issue
Block a user