render / rpms / libvirt

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

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 7f3aedacac33fd4775d7def3734422108d6cd93e)

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <0067ed0a20d90451ab63112dc273ddb8344569ca.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroup.c        | 13 ++-----------
 src/util/vircgroupbackend.h | 10 ++++++++++
 src/util/vircgroupv1.c      | 27 +++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 700e597157..1a5ed472df 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1742,10 +1742,7 @@ virCgroupGetCpusetMems(virCgroupPtr group, char **mems)
 int
 virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate)
 {
-    return virCgroupSetValueStr(group,
-                                VIR_CGROUP_CONTROLLER_CPUSET,
-                                "cpuset.memory_migrate",
-                                migrate ? "1" : "0");
+    VIR_CGROUP_BACKEND_CALL(group, setCpusetMemoryMigrate, -1, migrate);
 }
 
 
@@ -1760,13 +1757,7 @@ virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate)
 int
 virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate)
 {
-    unsigned long long value = 0;
-    int ret = virCgroupGetValueU64(group,
-                                   VIR_CGROUP_CONTROLLER_CPUSET,
-                                   "cpuset.memory_migrate",
-                                   &value);
-    *migrate = !!value;
-    return ret;
+    VIR_CGROUP_BACKEND_CALL(group, getCpusetMemoryMigrate, -1, migrate);
 }
 
 
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 35221e90df..d4e4c4a6cc 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -332,6 +332,14 @@ typedef int
 (*virCgroupGetCpusetMemsCB)(virCgroupPtr group,
                             char **mems);
 
+typedef int
+(*virCgroupSetCpusetMemoryMigrateCB)(virCgroupPtr group,
+                                     bool migrate);
+
+typedef int
+(*virCgroupGetCpusetMemoryMigrateCB)(virCgroupPtr group,
+                                     bool *migrate);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -404,6 +412,8 @@ struct _virCgroupBackend {
 
     virCgroupSetCpusetMemsCB setCpusetMems;
     virCgroupGetCpusetMemsCB getCpusetMems;
+    virCgroupSetCpusetMemoryMigrateCB setCpusetMemoryMigrate;
+    virCgroupGetCpusetMemoryMigrateCB getCpusetMemoryMigrate;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index be9a6b82b4..3a41899dd8 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1971,6 +1971,31 @@ virCgroupV1GetCpusetMems(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV1SetCpusetMemoryMigrate(virCgroupPtr group,
+                                  bool migrate)
+{
+    return virCgroupSetValueStr(group,
+                                VIR_CGROUP_CONTROLLER_CPUSET,
+                                "cpuset.memory_migrate",
+                                migrate ? "1" : "0");
+}
+
+
+static int
+virCgroupV1GetCpusetMemoryMigrate(virCgroupPtr group,
+                                  bool *migrate)
+{
+    unsigned long long value = 0;
+    int ret = virCgroupGetValueU64(group,
+                                   VIR_CGROUP_CONTROLLER_CPUSET,
+                                   "cpuset.memory_migrate",
+                                   &value);
+    *migrate = !!value;
+    return ret;
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -2041,6 +2066,8 @@ virCgroupBackend virCgroupV1Backend = {
 
     .setCpusetMems = virCgroupV1SetCpusetMems,
     .getCpusetMems = virCgroupV1GetCpusetMems,
+    .setCpusetMemoryMigrate = virCgroupV1SetCpusetMemoryMigrate,
+    .getCpusetMemoryMigrate = virCgroupV1GetCpusetMemoryMigrate,
 };
 
 
-- 
2.22.0