virCgroupSetupBlkioTune() has been introduced in order to remove the
code duplication present between virLXCCgroupSetupBlkioTune() and
qemuSetupBlkioCgroup().
Signed-off-by: Fabiano FidĂȘncio <fidencio(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/lxc/lxc_cgroup.c | 49 +-----------------------------------
src/qemu/qemu_cgroup.c | 47 +---------------------------------
src/util/vircgroup.c | 54 ++++++++++++++++++++++++++++++++++++++++
src/util/vircgroup.h | 3 +++
5 files changed, 60 insertions(+), 94 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index bf1536ea57..5df48f88f4 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1579,6 +1579,7 @@ virCgroupSetMemoryHardLimit;
virCgroupSetMemorySoftLimit;
virCgroupSetMemSwapHardLimit;
virCgroupSetOwner;
+virCgroupSetupBlkioTune;
virCgroupSupportsCpuBW;
virCgroupTerminateMachine;
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index d93a19d684..4a95f2a8b0 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -106,54 +106,7 @@ static int virLXCCgroupSetupCpusetTune(virDomainDefPtr def,
static int virLXCCgroupSetupBlkioTune(virDomainDefPtr def,
virCgroupPtr cgroup)
{
- size_t i;
-
- if (def->blkio.weight &&
- virCgroupSetBlkioWeight(cgroup, def->blkio.weight) < 0)
- return -1;
-
- if (def->blkio.ndevices) {
- for (i = 0; i < def->blkio.ndevices; i++) {
- virBlkioDevicePtr dev = &def->blkio.devices[i];
-
- if (dev->weight &&
- (virCgroupSetBlkioDeviceWeight(cgroup, dev->path,
- dev->weight) < 0 ||
- virCgroupGetBlkioDeviceWeight(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))
- return -1;
-
- if (dev->wiops &&
- (virCgroupSetBlkioDeviceWriteIops(cgroup, dev->path,
- dev->wiops) < 0 ||
- virCgroupGetBlkioDeviceWriteIops(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))
- return -1;
-
- if (dev->wbps &&
- (virCgroupSetBlkioDeviceWriteBps(cgroup, dev->path,
- dev->wbps) < 0 ||
- virCgroupGetBlkioDeviceWriteBps(cgroup, dev->path,
- &dev->wbps) < 0))
- return -1;
- }
- }
-
- return 0;
+ return virCgroupSetupBlkioTune(cgroup, &def->blkio);
}
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 43e17d786e..0e53678faa 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -514,7 +514,6 @@ static int
qemuSetupBlkioCgroup(virDomainObjPtr vm)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
- size_t i;
if (!virCgroupHasController(priv->cgroup,
VIR_CGROUP_CONTROLLER_BLKIO)) {
@@ -527,51 +526,7 @@ qemuSetupBlkioCgroup(virDomainObjPtr vm)
}
}
- if (vm->def->blkio.weight != 0 &&
- virCgroupSetBlkioWeight(priv->cgroup, vm->def->blkio.weight) < 0)
- return -1;
-
- if (vm->def->blkio.ndevices) {
- for (i = 0; i < vm->def->blkio.ndevices; i++) {
- virBlkioDevicePtr dev = &vm->def->blkio.devices[i];
- if (dev->weight &&
- (virCgroupSetBlkioDeviceWeight(priv->cgroup, dev->path,
- dev->weight) < 0 ||
- virCgroupGetBlkioDeviceWeight(priv->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))
- return -1;
-
- if (dev->wiops &&
- (virCgroupSetBlkioDeviceWriteIops(priv->cgroup, dev->path,
- dev->wiops) < 0 ||
- virCgroupGetBlkioDeviceWriteIops(priv->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))
- return -1;
-
- if (dev->wbps &&
- (virCgroupSetBlkioDeviceWriteBps(priv->cgroup, dev->path,
- dev->wbps) < 0 ||
- virCgroupGetBlkioDeviceWriteBps(priv->cgroup, dev->path,
- &dev->wbps) < 0))
- return -1;
- }
- }
-
- return 0;
+ return virCgroupSetupBlkioTune(priv->cgroup, &vm->def->blkio);
}
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 64507bf8aa..a08b6f4869 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -4820,3 +4820,57 @@ virCgroupDelThread(virCgroupPtr cgroup,
return 0;
}
+
+
+int
+virCgroupSetupBlkioTune(virCgroupPtr cgroup,
+ virBlkioTunePtr blkio)
+{
+ size_t i;
+
+ if (blkio->weight != 0 &&
+ virCgroupSetBlkioWeight(cgroup, blkio->weight) < 0)
+ return -1;
+
+ if (blkio->ndevices) {
+ for (i = 0; i < blkio->ndevices; i++) {
+ virBlkioDevicePtr dev = &blkio->devices[i];
+ if (dev->weight &&
+ (virCgroupSetBlkioDeviceWeight(cgroup, dev->path,
+ dev->weight) < 0 ||
+ virCgroupGetBlkioDeviceWeight(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))
+ return -1;
+
+ if (dev->wiops &&
+ (virCgroupSetBlkioDeviceWriteIops(cgroup, dev->path,
+ dev->wiops) < 0 ||
+ virCgroupGetBlkioDeviceWriteIops(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))
+ return -1;
+
+ if (dev->wbps &&
+ (virCgroupSetBlkioDeviceWriteBps(cgroup, dev->path,
+ dev->wbps) < 0 ||
+ virCgroupGetBlkioDeviceWriteBps(cgroup, dev->path,
+ &dev->wbps) < 0))
+ return -1;
+ }
+ }
+
+ return 0;
+}
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index ee3b7c7222..2908f70372 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -27,6 +27,7 @@
# include "virutil.h"
# include "virbitmap.h"
+# include "virblkio.h"
struct _virCgroup;
typedef struct _virCgroup virCgroup;
@@ -286,4 +287,6 @@ int virCgroupSetOwner(virCgroupPtr cgroup,
int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller);
bool virCgroupControllerAvailable(int controller);
+
+int virCgroupSetupBlkioTune(virCgroupPtr cgroup, virBlkioTunePtr blkio);
#endif /* __VIR_CGROUP_H__ */
--
2.17.1