This new util function puts the duplicated code from
qemu_cgroup.c:qemuSetupBlkioCgroup() and
lxc_cgroup.c:virLXCCgroupSetupBlkioTune() in a single
function to be used in both places.
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/libvirt_private.syms | 1 +
src/lxc/lxc_cgroup.c | 49 +----------------------------------
src/qemu/qemu_cgroup.c | 47 +---------------------------------
src/util/vircgroup.c | 55 ++++++++++++++++++++++++++++++++++++++++
src/util/vircgroup.h | 3 +++
5 files changed, 61 insertions(+), 94 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index dc0449d1d8..64163a5e56 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1728,6 +1728,7 @@ virCgroupSetMemoryHardLimit;
virCgroupSetMemorySoftLimit;
virCgroupSetMemSwapHardLimit;
virCgroupSetOwner;
+virCgroupSetupBlkioTune;
virCgroupSupportsCpuBW;
virCgroupTerminateMachine;
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index 7f3701593a..96d43b06f2 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -101,54 +101,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 45701b4c6e..a5eaa24d90 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -591,7 +591,6 @@ static int
qemuSetupBlkioCgroup(virDomainObjPtr vm)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
- size_t i;
if (!virCgroupHasController(priv->cgroup,
VIR_CGROUP_CONTROLLER_BLKIO)) {
@@ -604,51 +603,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 0680ff7c24..0d83e2094f 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -35,6 +35,7 @@
#define LIBVIRT_VIRCGROUPPRIV_H_ALLOW
#include "vircgrouppriv.h"
+#include "conf/domain_conf.h"
#include "virutil.h"
#include "viralloc.h"
#include "vircgroupbackend.h"
@@ -3581,3 +3582,57 @@ virCgroupDelThread(virCgroupPtr cgroup,
return 0;
}
+
+
+int
+virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune 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 != 0 &&
+ (virCgroupSetBlkioDeviceWeight(cgroup, dev->path,
+ dev->weight) < 0 ||
+ virCgroupGetBlkioDeviceWeight(cgroup, dev->path,
+ &dev->weight) < 0))
+ return -1;
+
+ if (dev->riops != 0 &&
+ (virCgroupSetBlkioDeviceReadIops(cgroup, dev->path,
+ dev->riops) < 0 ||
+ virCgroupGetBlkioDeviceReadIops(cgroup, dev->path,
+ &dev->riops) < 0))
+ return -1;
+
+ if (dev->wiops != 0 &&
+ (virCgroupSetBlkioDeviceWriteIops(cgroup, dev->path,
+ dev->wiops) < 0 ||
+ virCgroupGetBlkioDeviceWriteIops(cgroup, dev->path,
+ &dev->wiops) < 0))
+ return -1;
+
+ if (dev->rbps != 0 &&
+ (virCgroupSetBlkioDeviceReadBps(cgroup, dev->path,
+ dev->rbps) < 0 ||
+ virCgroupGetBlkioDeviceReadBps(cgroup, dev->path,
+ &dev->rbps) < 0))
+ return -1;
+
+ if (dev->wbps != 0 &&
+ (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 15263f534a..d2d7e7ab51 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -24,6 +24,7 @@
#include "virutil.h"
#include "virbitmap.h"
#include "virenum.h"
+#include "conf/virconftypes.h"
struct _virCgroup;
typedef struct _virCgroup virCgroup;
@@ -285,3 +286,5 @@ int virCgroupSetOwner(virCgroupPtr cgroup,
int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller);
bool virCgroupControllerAvailable(int controller);
+
+int virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune blkio);
--
2.24.1