mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
lxc,qemu: use virCgroupSetupBlkioDevice* helpers
There are code repetition of set() and get() blkio device parameters across lxc and qemu files. Use the new vircgroup helpers to trim the repetition a bit. 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
3118b4ee95
commit
17e8af6b45
@ -112,38 +112,28 @@ static int virLXCCgroupSetupBlkioTune(virDomainDefPtr def,
|
||||
virBlkioDevicePtr dev = &def->blkio.devices[i];
|
||||
|
||||
if (dev->weight &&
|
||||
(virCgroupSetBlkioDeviceWeight(cgroup, dev->path,
|
||||
dev->weight) < 0 ||
|
||||
virCgroupGetBlkioDeviceWeight(cgroup, dev->path,
|
||||
&dev->weight) < 0))
|
||||
virCgroupSetupBlkioDeviceWeight(cgroup, dev->path,
|
||||
&dev->weight) < 0)
|
||||
return -1;
|
||||
|
||||
if (dev->riops &&
|
||||
(virCgroupSetBlkioDeviceReadIops(cgroup, dev->path,
|
||||
dev->riops) < 0 ||
|
||||
virCgroupGetBlkioDeviceReadIops(cgroup, dev->path,
|
||||
&dev->riops) < 0))
|
||||
virCgroupSetupBlkioDeviceReadIops(cgroup, dev->path,
|
||||
&dev->riops) < 0)
|
||||
return -1;
|
||||
|
||||
if (dev->wiops &&
|
||||
(virCgroupSetBlkioDeviceWriteIops(cgroup, dev->path,
|
||||
dev->wiops) < 0 ||
|
||||
virCgroupGetBlkioDeviceWriteIops(cgroup, dev->path,
|
||||
&dev->wiops) < 0))
|
||||
virCgroupSetupBlkioDeviceWriteIops(cgroup, dev->path,
|
||||
&dev->wiops) < 0)
|
||||
return -1;
|
||||
|
||||
if (dev->rbps &&
|
||||
(virCgroupSetBlkioDeviceReadBps(cgroup, dev->path,
|
||||
dev->rbps) < 0 ||
|
||||
virCgroupGetBlkioDeviceReadBps(cgroup, dev->path,
|
||||
&dev->rbps) < 0))
|
||||
virCgroupSetupBlkioDeviceReadBps(cgroup, dev->path,
|
||||
&dev->rbps) < 0)
|
||||
return -1;
|
||||
|
||||
if (dev->wbps &&
|
||||
(virCgroupSetBlkioDeviceWriteBps(cgroup, dev->path,
|
||||
dev->wbps) < 0 ||
|
||||
virCgroupGetBlkioDeviceWriteBps(cgroup, dev->path,
|
||||
&dev->wbps) < 0))
|
||||
virCgroupSetupBlkioDeviceWriteBps(cgroup, dev->path,
|
||||
&dev->wbps) < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -2581,6 +2581,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
|
||||
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;
|
||||
@ -2595,60 +2596,40 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
|
||||
|
||||
if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetBlkioDeviceWeight(priv->cgroup,
|
||||
devices[j].path,
|
||||
devices[j].weight) < 0 ||
|
||||
virCgroupGetBlkioDeviceWeight(priv->cgroup,
|
||||
devices[j].path,
|
||||
&devices[j].weight) < 0) {
|
||||
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 (virCgroupSetBlkioDeviceReadIops(priv->cgroup,
|
||||
devices[j].path,
|
||||
devices[j].riops) < 0 ||
|
||||
virCgroupGetBlkioDeviceReadIops(priv->cgroup,
|
||||
devices[j].path,
|
||||
&devices[j].riops) < 0) {
|
||||
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 (virCgroupSetBlkioDeviceWriteIops(priv->cgroup,
|
||||
devices[j].path,
|
||||
devices[j].wiops) < 0 ||
|
||||
virCgroupGetBlkioDeviceWriteIops(priv->cgroup,
|
||||
devices[j].path,
|
||||
&devices[j].wiops) < 0) {
|
||||
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 (virCgroupSetBlkioDeviceReadBps(priv->cgroup,
|
||||
devices[j].path,
|
||||
devices[j].rbps) < 0 ||
|
||||
virCgroupGetBlkioDeviceReadBps(priv->cgroup,
|
||||
devices[j].path,
|
||||
&devices[j].rbps) < 0) {
|
||||
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 (virCgroupSetBlkioDeviceWriteBps(priv->cgroup,
|
||||
devices[j].path,
|
||||
devices[j].wbps) < 0 ||
|
||||
virCgroupGetBlkioDeviceWriteBps(priv->cgroup,
|
||||
devices[j].path,
|
||||
&devices[j].wbps) < 0) {
|
||||
if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devices[j].path,
|
||||
&devices[j].wbps) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
@ -611,39 +611,31 @@ qemuSetupBlkioCgroup(virDomainObjPtr vm)
|
||||
if (vm->def->blkio.ndevices) {
|
||||
for (i = 0; i < vm->def->blkio.ndevices; i++) {
|
||||
virBlkioDevicePtr dev = &vm->def->blkio.devices[i];
|
||||
virCgroupPtr cgroup = priv->cgroup;
|
||||
|
||||
if (dev->weight &&
|
||||
(virCgroupSetBlkioDeviceWeight(priv->cgroup, dev->path,
|
||||
dev->weight) < 0 ||
|
||||
virCgroupGetBlkioDeviceWeight(priv->cgroup, dev->path,
|
||||
&dev->weight) < 0))
|
||||
virCgroupSetupBlkioDeviceWeight(cgroup, dev->path,
|
||||
&dev->weight) < 0)
|
||||
return -1;
|
||||
|
||||
if (dev->riops &&
|
||||
(virCgroupSetBlkioDeviceReadIops(priv->cgroup, dev->path,
|
||||
dev->riops) < 0 ||
|
||||
virCgroupGetBlkioDeviceReadIops(priv->cgroup, dev->path,
|
||||
&dev->riops) < 0))
|
||||
virCgroupSetupBlkioDeviceReadIops(cgroup, dev->path,
|
||||
&dev->riops) < 0)
|
||||
return -1;
|
||||
|
||||
if (dev->wiops &&
|
||||
(virCgroupSetBlkioDeviceWriteIops(priv->cgroup, dev->path,
|
||||
dev->wiops) < 0 ||
|
||||
virCgroupGetBlkioDeviceWriteIops(priv->cgroup, dev->path,
|
||||
&dev->wiops) < 0))
|
||||
virCgroupSetupBlkioDeviceWriteIops(cgroup, dev->path,
|
||||
&dev->wiops) < 0)
|
||||
return -1;
|
||||
|
||||
if (dev->rbps &&
|
||||
(virCgroupSetBlkioDeviceReadBps(priv->cgroup, dev->path,
|
||||
dev->rbps) < 0 ||
|
||||
virCgroupGetBlkioDeviceReadBps(priv->cgroup, dev->path,
|
||||
&dev->rbps) < 0))
|
||||
virCgroupSetupBlkioDeviceReadBps(cgroup, dev->path,
|
||||
&dev->rbps) < 0)
|
||||
return -1;
|
||||
|
||||
if (dev->wbps &&
|
||||
(virCgroupSetBlkioDeviceWriteBps(priv->cgroup, dev->path,
|
||||
dev->wbps) < 0 ||
|
||||
virCgroupGetBlkioDeviceWriteBps(priv->cgroup, dev->path,
|
||||
&dev->wbps) < 0))
|
||||
virCgroupSetupBlkioDeviceWriteBps(cgroup, dev->path,
|
||||
&dev->wbps) < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -9564,6 +9564,7 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
|
||||
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;
|
||||
@ -9578,60 +9579,40 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
|
||||
|
||||
if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
|
||||
for (j = 0; j < ndevices; j++) {
|
||||
if (virCgroupSetBlkioDeviceWeight(priv->cgroup,
|
||||
devices[j].path,
|
||||
devices[j].weight) < 0 ||
|
||||
virCgroupGetBlkioDeviceWeight(priv->cgroup,
|
||||
devices[j].path,
|
||||
&devices[j].weight) < 0) {
|
||||
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 (virCgroupSetBlkioDeviceReadIops(priv->cgroup,
|
||||
devices[j].path,
|
||||
devices[j].riops) < 0 ||
|
||||
virCgroupGetBlkioDeviceReadIops(priv->cgroup,
|
||||
devices[j].path,
|
||||
&devices[j].riops) < 0) {
|
||||
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 (virCgroupSetBlkioDeviceWriteIops(priv->cgroup,
|
||||
devices[j].path,
|
||||
devices[j].wiops) < 0 ||
|
||||
virCgroupGetBlkioDeviceWriteIops(priv->cgroup,
|
||||
devices[j].path,
|
||||
&devices[j].wiops) < 0) {
|
||||
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 (virCgroupSetBlkioDeviceReadBps(priv->cgroup,
|
||||
devices[j].path,
|
||||
devices[j].rbps) < 0 ||
|
||||
virCgroupGetBlkioDeviceReadBps(priv->cgroup,
|
||||
devices[j].path,
|
||||
&devices[j].rbps) < 0) {
|
||||
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 (virCgroupSetBlkioDeviceWriteBps(priv->cgroup,
|
||||
devices[j].path,
|
||||
devices[j].wbps) < 0 ||
|
||||
virCgroupGetBlkioDeviceWriteBps(priv->cgroup,
|
||||
devices[j].path,
|
||||
&devices[j].wbps) < 0) {
|
||||
if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devices[j].path,
|
||||
&devices[j].wbps) < 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user