render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From 75e53d9323c069ece39b40a99675425967ac2d62 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <75e53d9323c069ece39b40a99675425967ac2d62@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:49 +0200
c480ed
Subject: [PATCH] vircgroup: extract virCgroupV1SetMemory
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit 53f43deb0dfa666cb8c614cabbf5add075ccc33f)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <d24181f343e9a9ca60165d1f936cc9ec9c0616ec.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c        | 20 +-------------------
c480ed
 src/util/vircgroupbackend.h |  6 ++++++
c480ed
 src/util/vircgroupv1.c      | 28 ++++++++++++++++++++++++++++
c480ed
 3 files changed, 35 insertions(+), 19 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index 684bce4997..4053c65939 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -1593,25 +1593,7 @@ virCgroupGetMemoryUnlimitedKB(void)
c480ed
 int
c480ed
 virCgroupSetMemory(virCgroupPtr group, unsigned long long kb)
c480ed
 {
c480ed
-    unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
c480ed
-
c480ed
-    if (kb > maxkb) {
c480ed
-        virReportError(VIR_ERR_INVALID_ARG,
c480ed
-                       _("Memory '%llu' must be less than %llu"),
c480ed
-                       kb, maxkb);
c480ed
-        return -1;
c480ed
-    }
c480ed
-
c480ed
-    if (kb == maxkb)
c480ed
-        return virCgroupSetValueI64(group,
c480ed
-                                    VIR_CGROUP_CONTROLLER_MEMORY,
c480ed
-                                    "memory.limit_in_bytes",
c480ed
-                                    -1);
c480ed
-    else
c480ed
-        return virCgroupSetValueU64(group,
c480ed
-                                    VIR_CGROUP_CONTROLLER_MEMORY,
c480ed
-                                    "memory.limit_in_bytes",
c480ed
-                                    kb << 10);
c480ed
+    VIR_CGROUP_BACKEND_CALL(group, setMemory, -1, kb);
c480ed
 }
c480ed
 
c480ed
 
c480ed
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c480ed
index 67e795a2b7..e1f75c5c31 100644
c480ed
--- a/src/util/vircgroupbackend.h
c480ed
+++ b/src/util/vircgroupbackend.h
c480ed
@@ -210,6 +210,10 @@ typedef int
c480ed
                                      const char *path,
c480ed
                                      unsigned long long *wbps);
c480ed
 
c480ed
+typedef int
c480ed
+(*virCgroupSetMemoryCB)(virCgroupPtr group,
c480ed
+                        unsigned long long kb);
c480ed
+
c480ed
 struct _virCgroupBackend {
c480ed
     virCgroupBackendType type;
c480ed
 
c480ed
@@ -248,6 +252,8 @@ struct _virCgroupBackend {
c480ed
     virCgroupGetBlkioDeviceReadBpsCB getBlkioDeviceReadBps;
c480ed
     virCgroupSetBlkioDeviceWriteBpsCB setBlkioDeviceWriteBps;
c480ed
     virCgroupGetBlkioDeviceWriteBpsCB getBlkioDeviceWriteBps;
c480ed
+
c480ed
+    virCgroupSetMemoryCB setMemory;
c480ed
 };
c480ed
 typedef struct _virCgroupBackend virCgroupBackend;
c480ed
 typedef virCgroupBackend *virCgroupBackendPtr;
c480ed
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c480ed
index c044414dfd..17a4d67972 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -1378,6 +1378,32 @@ virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV1SetMemory(virCgroupPtr group,
c480ed
+                     unsigned long long kb)
c480ed
+{
c480ed
+    unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
c480ed
+
c480ed
+    if (kb > maxkb) {
c480ed
+        virReportError(VIR_ERR_INVALID_ARG,
c480ed
+                       _("Memory '%llu' must be less than %llu"),
c480ed
+                       kb, maxkb);
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    if (kb == maxkb)
c480ed
+        return virCgroupSetValueI64(group,
c480ed
+                                    VIR_CGROUP_CONTROLLER_MEMORY,
c480ed
+                                    "memory.limit_in_bytes",
c480ed
+                                    -1);
c480ed
+    else
c480ed
+        return virCgroupSetValueU64(group,
c480ed
+                                    VIR_CGROUP_CONTROLLER_MEMORY,
c480ed
+                                    "memory.limit_in_bytes",
c480ed
+                                    kb << 10);
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV1Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
c480ed
 
c480ed
@@ -1414,6 +1440,8 @@ virCgroupBackend virCgroupV1Backend = {
c480ed
     .getBlkioDeviceReadBps = virCgroupV1GetBlkioDeviceReadBps,
c480ed
     .setBlkioDeviceWriteBps = virCgroupV1SetBlkioDeviceWriteBps,
c480ed
     .getBlkioDeviceWriteBps = virCgroupV1GetBlkioDeviceWriteBps,
c480ed
+
c480ed
+    .setMemory = virCgroupV1SetMemory,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed