render / rpms / libvirt

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