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

domain_cgroup.c: add virDomainCgroupSetupMemtune()

virLXCCgroupSetupMemTune() and qemuSetupMemoryCgroup() shares
duplicated code that can be put in a new helper to avoid
code repetition.
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>
上级 f1704e61
......@@ -65,3 +65,22 @@ virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blkio)
return 0;
}
int
virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune 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;
}
......@@ -25,3 +25,4 @@
int virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blkio);
int virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem);
......@@ -1392,6 +1392,7 @@ virSetConnectStorage;
# hypervisor/domain_cgroup.h
virDomainCgroupSetupBlkio;
virDomainCgroupSetupMemtune;
# libvirt_internal.h
......
......@@ -112,19 +112,7 @@ static int virLXCCgroupSetupMemTune(virDomainDefPtr def,
if (virCgroupSetMemory(cgroup, virDomainDefGetMemoryInitial(def)) < 0)
return -1;
if (virMemoryLimitIsSet(def->mem.hard_limit))
if (virCgroupSetMemoryHardLimit(cgroup, def->mem.hard_limit) < 0)
return -1;
if (virMemoryLimitIsSet(def->mem.soft_limit))
if (virCgroupSetMemorySoftLimit(cgroup, def->mem.soft_limit) < 0)
return -1;
if (virMemoryLimitIsSet(def->mem.swap_hard_limit))
if (virCgroupSetMemSwapHardLimit(cgroup, def->mem.swap_hard_limit) < 0)
return -1;
return 0;
return virDomainCgroupSetupMemtune(cgroup, def->mem);
}
......
......@@ -625,19 +625,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 virDomainCgroupSetupMemtune(priv->cgroup, vm->def->mem);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册