virCgroupSetupMemTune() has been introduced in order to remove the code
duplication present between virLXCCgroupSetupMemTune() and
qemuSetupMemoryCgroup().
Signed-off-by: Fabiano FidĂȘncio <fidencio(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/lxc/lxc_cgroup.c | 20 ++------------------
src/qemu/qemu_cgroup.c | 14 +-------------
src/util/vircgroup.c | 20 ++++++++++++++++++++
src/util/vircgroup.h | 2 ++
5 files changed, 26 insertions(+), 31 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5df48f88f4..94044c60ec 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1580,6 +1580,7 @@ virCgroupSetMemorySoftLimit;
virCgroupSetMemSwapHardLimit;
virCgroupSetOwner;
virCgroupSetupBlkioTune;
+virCgroupSetupMemTune;
virCgroupSupportsCpuBW;
virCgroupTerminateMachine;
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index 4a95f2a8b0..95311fde9e 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -113,26 +113,10 @@ static int virLXCCgroupSetupBlkioTune(virDomainDefPtr def,
static int virLXCCgroupSetupMemTune(virDomainDefPtr def,
virCgroupPtr cgroup)
{
- int ret = -1;
-
if (virCgroupSetMemory(cgroup, virDomainDefGetMemoryInitial(def)) < 0)
- goto cleanup;
-
- if (virMemoryLimitIsSet(def->mem.hard_limit))
- if (virCgroupSetMemoryHardLimit(cgroup, def->mem.hard_limit) < 0)
- goto cleanup;
-
- if (virMemoryLimitIsSet(def->mem.soft_limit))
- if (virCgroupSetMemorySoftLimit(cgroup, def->mem.soft_limit) < 0)
- goto cleanup;
-
- if (virMemoryLimitIsSet(def->mem.swap_hard_limit))
- if (virCgroupSetMemSwapHardLimit(cgroup, def->mem.swap_hard_limit) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return virCgroupSetupMemTune(cgroup, &def->mem);
}
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 0e53678faa..205098ec30 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -547,19 +547,7 @@ qemuSetupMemoryCgroup(virDomainObjPtr vm)
}
}
- if (virMemoryLimitIsSet(vm->def->mem.hard_limit))
- if (virCgroupSetMemoryHardLimit(priv->cgroup, vm->def->mem.hard_limit)
< 0)
- return -1;
-
- if (virMemoryLimitIsSet(vm->def->mem.soft_limit))
- if (virCgroupSetMemorySoftLimit(priv->cgroup, vm->def->mem.soft_limit)
< 0)
- return -1;
-
- if (virMemoryLimitIsSet(vm->def->mem.swap_hard_limit))
- if (virCgroupSetMemSwapHardLimit(priv->cgroup,
vm->def->mem.swap_hard_limit) < 0)
- return -1;
-
- return 0;
+ return virCgroupSetupMemTune(priv->cgroup, &vm->def->mem);
}
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index a08b6f4869..3973f6da61 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -4874,3 +4874,23 @@ virCgroupSetupBlkioTune(virCgroupPtr cgroup,
return 0;
}
+
+
+int
+virCgroupSetupMemTune(virCgroupPtr cgroup,
+ virMemTunePtr mem)
+{
+ if (virMemoryLimitIsSet(mem->hard_limit))
+ if (virCgroupSetMemoryHardLimit(cgroup, mem->hard_limit) < 0)
+ return -1;
+
+ if (virMemoryLimitIsSet(mem->soft_limit))
+ if (virCgroupSetMemorySoftLimit(cgroup, mem->soft_limit) < 0)
+ return -1;
+
+ if (virMemoryLimitIsSet(mem->swap_hard_limit))
+ if (virCgroupSetMemSwapHardLimit(cgroup, mem->swap_hard_limit) < 0)
+ return -1;
+
+ return 0;
+}
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index 2908f70372..c01422ec84 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -28,6 +28,7 @@
# include "virutil.h"
# include "virbitmap.h"
# include "virblkio.h"
+# include "virmem.h"
struct _virCgroup;
typedef struct _virCgroup virCgroup;
@@ -289,4 +290,5 @@ int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller);
bool virCgroupControllerAvailable(int controller);
int virCgroupSetupBlkioTune(virCgroupPtr cgroup, virBlkioTunePtr blkio);
+int virCgroupSetupMemTune(virCgroupPtr cgroup, virMemTunePtr mem);
#endif /* __VIR_CGROUP_H__ */
--
2.17.1