c313de
From d9dca0b3b1ad64bcde8d96b05538d4656ca93af3 Mon Sep 17 00:00:00 2001
c313de
Message-Id: <d9dca0b3b1ad64bcde8d96b05538d4656ca93af3@dist-git>
c313de
From: Pavel Hrdina <phrdina@redhat.com>
c313de
Date: Mon, 1 Jul 2019 17:07:42 +0200
c313de
Subject: [PATCH] vircgroup: introduce virCgroupV2(Set|Get)MemoryHardLimit
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
(cherry picked from commit 2aa5385c58d50270d7084f8d11a22ac993275dc0)
c313de
c313de
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c313de
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
Message-Id: <dc9320d118699dc39071dc1f15b1094112cf5a04.1561993100.git.phrdina@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/util/vircgroupv2.c | 43 ++++++++++++++++++++++++++++++++++++++++++
c313de
 1 file changed, 43 insertions(+)
c313de
c313de
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c313de
index 87d357b0a7..81a577d28f 100644
c313de
--- a/src/util/vircgroupv2.c
c313de
+++ b/src/util/vircgroupv2.c
c313de
@@ -1130,6 +1130,47 @@ virCgroupV2GetMemoryUsage(virCgroupPtr group,
c313de
 }
c313de
 
c313de
 
c313de
+static int
c313de
+virCgroupV2SetMemoryHardLimit(virCgroupPtr group,
c313de
+                              unsigned long long kb)
c313de
+{
c313de
+    return virCgroupV2SetMemory(group, kb);
c313de
+}
c313de
+
c313de
+
c313de
+static int
c313de
+virCgroupV2GetMemoryHardLimit(virCgroupPtr group,
c313de
+                              unsigned long long *kb)
c313de
+{
c313de
+    VIR_AUTOFREE(char *) value = NULL;
c313de
+    unsigned long long max;
c313de
+
c313de
+    if (virCgroupGetValueStr(group,
c313de
+                             VIR_CGROUP_CONTROLLER_MEMORY,
c313de
+                             "memory.max", &value) < 0) {
c313de
+        return -1;
c313de
+    }
c313de
+
c313de
+    if (STREQ(value, "max")) {
c313de
+        *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
c313de
+        return 0;
c313de
+    }
c313de
+
c313de
+    if (virStrToLong_ull(value, NULL, 10, &max) < 0) {
c313de
+        virReportError(VIR_ERR_INTERNAL_ERROR,
c313de
+                       _("Failed to parse value '%s' as number."),
c313de
+                       value);
c313de
+        return -1;
c313de
+    }
c313de
+
c313de
+    *kb = max >> 10;
c313de
+    if (*kb >= VIR_DOMAIN_MEMORY_PARAM_UNLIMITED)
c313de
+        *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
c313de
+
c313de
+    return 0;
c313de
+}
c313de
+
c313de
+
c313de
 virCgroupBackend virCgroupV2Backend = {
c313de
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
c313de
 
c313de
@@ -1170,6 +1211,8 @@ virCgroupBackend virCgroupV2Backend = {
c313de
     .setMemory = virCgroupV2SetMemory,
c313de
     .getMemoryStat = virCgroupV2GetMemoryStat,
c313de
     .getMemoryUsage = virCgroupV2GetMemoryUsage,
c313de
+    .setMemoryHardLimit = virCgroupV2SetMemoryHardLimit,
c313de
+    .getMemoryHardLimit = virCgroupV2GetMemoryHardLimit,
c313de
 };
c313de
 
c313de
 
c313de
-- 
c313de
2.22.0
c313de