render / rpms / libvirt

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