render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From d9dca0b3b1ad64bcde8d96b05538d4656ca93af3 Mon Sep 17 00:00:00 2001
Message-Id: <d9dca0b3b1ad64bcde8d96b05538d4656ca93af3@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:07:42 +0200
Subject: [PATCH] vircgroup: introduce virCgroupV2(Set|Get)MemoryHardLimit
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 2aa5385c58d50270d7084f8d11a22ac993275dc0)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <dc9320d118699dc39071dc1f15b1094112cf5a04.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroupv2.c | 43 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 87d357b0a7..81a577d28f 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -1130,6 +1130,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,
 
@@ -1170,6 +1211,8 @@ virCgroupBackend virCgroupV2Backend = {
     .setMemory = virCgroupV2SetMemory,
     .getMemoryStat = virCgroupV2GetMemoryStat,
     .getMemoryUsage = virCgroupV2GetMemoryUsage,
+    .setMemoryHardLimit = virCgroupV2SetMemoryHardLimit,
+    .getMemoryHardLimit = virCgroupV2GetMemoryHardLimit,
 };
 
 
-- 
2.22.0