提交 ac87d352 编写于 作者: D Daniel Henrique Barboza 提交者: Ján Tomko

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: NDaniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 2450a041
...@@ -78,6 +78,7 @@ ...@@ -78,6 +78,7 @@
@SRCDIR@/src/hyperv/hyperv_driver.c @SRCDIR@/src/hyperv/hyperv_driver.c
@SRCDIR@/src/hyperv/hyperv_util.c @SRCDIR@/src/hyperv/hyperv_util.c
@SRCDIR@/src/hyperv/hyperv_wmi.c @SRCDIR@/src/hyperv/hyperv_wmi.c
@SRCDIR@/src/hypervisor/domain_cgroup.c
@SRCDIR@/src/hypervisor/domain_driver.c @SRCDIR@/src/hypervisor/domain_driver.c
@SRCDIR@/src/interface/interface_backend_netcf.c @SRCDIR@/src/interface/interface_backend_netcf.c
@SRCDIR@/src/interface/interface_backend_udev.c @SRCDIR@/src/interface/interface_backend_udev.c
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
#include <config.h> #include <config.h>
#include "domain_cgroup.h" #include "domain_cgroup.h"
#include "domain_driver.h"
#define VIR_FROM_THIS VIR_FROM_DOMAIN
int int
...@@ -84,3 +87,101 @@ virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem) ...@@ -84,3 +87,101 @@ virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem)
return 0; 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 = &params[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 @@ ...@@ -26,3 +26,7 @@
int virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blkio); int virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blkio);
int virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem); int virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem);
int virDomainCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup,
virDomainDefPtr def,
virTypedParameterPtr params,
int nparams);
...@@ -1392,6 +1392,7 @@ virSetConnectStorage; ...@@ -1392,6 +1392,7 @@ virSetConnectStorage;
# hypervisor/domain_cgroup.h # hypervisor/domain_cgroup.h
virDomainCgroupSetupBlkio; virDomainCgroupSetupBlkio;
virDomainCgroupSetupDomainBlkioParameters;
virDomainCgroupSetupMemtune; virDomainCgroupSetupMemtune;
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "virpidfile.h" #include "virpidfile.h"
#include "virfdstream.h" #include "virfdstream.h"
#include "domain_audit.h" #include "domain_audit.h"
#include "domain_cgroup.h"
#include "domain_driver.h" #include "domain_driver.h"
#include "domain_nwfilter.h" #include "domain_nwfilter.h"
#include "virinitctl.h" #include "virinitctl.h"
...@@ -2364,90 +2365,8 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, ...@@ -2364,90 +2365,8 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
ret = 0; ret = 0;
if (def) { if (def) {
for (i = 0; i < nparams; i++) { ret = virDomainCgroupSetupDomainBlkioParameters(priv->cgroup, def,
virTypedParameterPtr param = &params[i]; params, nparams);
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);
}
}
} }
if (ret < 0) if (ret < 0)
goto endjob; goto endjob;
......
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
#include "viruuid.h" #include "viruuid.h"
#include "domain_conf.h" #include "domain_conf.h"
#include "domain_audit.h" #include "domain_audit.h"
#include "domain_cgroup.h"
#include "domain_driver.h" #include "domain_driver.h"
#include "node_device_conf.h" #include "node_device_conf.h"
#include "virpci.h" #include "virpci.h"
...@@ -9375,91 +9376,8 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, ...@@ -9375,91 +9376,8 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
ret = 0; ret = 0;
if (def) { if (def) {
for (i = 0; i < nparams; i++) { ret = virDomainCgroupSetupDomainBlkioParameters(priv->cgroup, def,
virTypedParameterPtr param = &params[i]; params, nparams);
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);
}
}
if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
goto endjob; goto endjob;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册