[PATCH v2 31/53] [ACKED] vircgroup: introduce virCgroupV2(Set|Get)MemoryHardLimit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/util/vircgroupv2.c | 43 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 51e08fe74b..0904eaa548 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -1138,6 +1138,47 @@ virCgroupV2GetMemoryUsage(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV2SetMemoryHardLimit(virCgroupPtr group,
+                              unsigned long long kb)
+{
+    return virCgroupV2SetMemory(group, kb);
+}
+
+
+static int
+virCgroupV2GetMemoryHardLimit(virCgroupPtr group,
+                              unsigned long long *kb)
+{
+    VIR_AUTOFREE(char *) value = NULL;
+    unsigned long long max;
+
+    if (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_MEMORY,
+                             "memory.max", &value) < 0) {
+        return -1;
+    }
+
+    if (STREQ(value, "max")) {
+        *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
+        return 0;
+    }
+
+    if (virStrToLong_ull(value, NULL, 10, &max) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to parse value '%s' as number."),
+                       value);
+        return -1;
+    }
+
+    *kb = max >> 10;
+    if (*kb >= VIR_DOMAIN_MEMORY_PARAM_UNLIMITED)
+        *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
+
+    return 0;
+}
+
+
 virCgroupBackend virCgroupV2Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
 
@@ -1178,6 +1219,8 @@ virCgroupBackend virCgroupV2Backend = {
     .setMemory = virCgroupV2SetMemory,
     .getMemoryStat = virCgroupV2GetMemoryStat,
     .getMemoryUsage = virCgroupV2GetMemoryUsage,
+    .setMemoryHardLimit = virCgroupV2SetMemoryHardLimit,
+    .getMemoryHardLimit = virCgroupV2GetMemoryHardLimit,
 };
 
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux