Pablo Greco 40546a
From 86865e9638ec63808b1f68e4bd9b4896b5438ece Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <86865e9638ec63808b1f68e4bd9b4896b5438ece@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:06:56 +0200
Pablo Greco 40546a
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)CpuShares
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
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
(cherry picked from commit 857aac1f55bc1c44be4c03c4b721632caedd2a23)
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: <d43fdbd54cb3c387df54c11d2bd24483c717bd5a.1561993100.git.phrdina@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
---
Pablo Greco 40546a
 src/util/vircgroup.c        |  8 ++------
Pablo Greco 40546a
 src/util/vircgroupbackend.h | 11 +++++++++++
Pablo Greco 40546a
 src/util/vircgroupv1.c      | 23 +++++++++++++++++++++++
Pablo Greco 40546a
 3 files changed, 36 insertions(+), 6 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
Pablo Greco 40546a
index 67c68f3dc6..953e353ec3 100644
Pablo Greco 40546a
--- a/src/util/vircgroup.c
Pablo Greco 40546a
+++ b/src/util/vircgroup.c
Pablo Greco 40546a
@@ -2205,18 +2205,14 @@ virCgroupGetDomainTotalCpuStats(virCgroupPtr group,
Pablo Greco 40546a
 int
Pablo Greco 40546a
 virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares)
Pablo Greco 40546a
 {
Pablo Greco 40546a
-    return virCgroupSetValueU64(group,
Pablo Greco 40546a
-                                VIR_CGROUP_CONTROLLER_CPU,
Pablo Greco 40546a
-                                "cpu.shares", shares);
Pablo Greco 40546a
+    VIR_CGROUP_BACKEND_CALL(group, setCpuShares, -1, shares);
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
 int
Pablo Greco 40546a
 virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares)
Pablo Greco 40546a
 {
Pablo Greco 40546a
-    return virCgroupGetValueU64(group,
Pablo Greco 40546a
-                                VIR_CGROUP_CONTROLLER_CPU,
Pablo Greco 40546a
-                                "cpu.shares", shares);
Pablo Greco 40546a
+    VIR_CGROUP_BACKEND_CALL(group, getCpuShares, -1, shares);
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
Pablo Greco 40546a
index 436c83f6fa..54fbead8a2 100644
Pablo Greco 40546a
--- a/src/util/vircgroupbackend.h
Pablo Greco 40546a
+++ b/src/util/vircgroupbackend.h
Pablo Greco 40546a
@@ -276,6 +276,14 @@ typedef int
Pablo Greco 40546a
 typedef int
Pablo Greco 40546a
 (*virCgroupDenyAllDevicesCB)(virCgroupPtr group);
Pablo Greco 40546a
 
Pablo Greco 40546a
+typedef int
Pablo Greco 40546a
+(*virCgroupSetCpuSharesCB)(virCgroupPtr group,
Pablo Greco 40546a
+                           unsigned long long shares);
Pablo Greco 40546a
+
Pablo Greco 40546a
+typedef int
Pablo Greco 40546a
+(*virCgroupGetCpuSharesCB)(virCgroupPtr group,
Pablo Greco 40546a
+                           unsigned long long *shares);
Pablo Greco 40546a
+
Pablo Greco 40546a
 struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupBackendType type;
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -330,6 +338,9 @@ struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupDenyDeviceCB denyDevice;
Pablo Greco 40546a
     virCgroupAllowAllDevicesCB allowAllDevices;
Pablo Greco 40546a
     virCgroupDenyAllDevicesCB denyAllDevices;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    virCgroupSetCpuSharesCB setCpuShares;
Pablo Greco 40546a
+    virCgroupGetCpuSharesCB getCpuShares;
Pablo Greco 40546a
 };
Pablo Greco 40546a
 typedef struct _virCgroupBackend virCgroupBackend;
Pablo Greco 40546a
 typedef virCgroupBackend *virCgroupBackendPtr;
Pablo Greco 40546a
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
Pablo Greco 40546a
index 34393812d2..537845bafe 100644
Pablo Greco 40546a
--- a/src/util/vircgroupv1.c
Pablo Greco 40546a
+++ b/src/util/vircgroupv1.c
Pablo Greco 40546a
@@ -1766,6 +1766,26 @@ virCgroupV1DenyAllDevices(virCgroupPtr group)
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1SetCpuShares(virCgroupPtr group,
Pablo Greco 40546a
+                        unsigned long long shares)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    return virCgroupSetValueU64(group,
Pablo Greco 40546a
+                                VIR_CGROUP_CONTROLLER_CPU,
Pablo Greco 40546a
+                                "cpu.shares", shares);
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1GetCpuShares(virCgroupPtr group,
Pablo Greco 40546a
+                        unsigned long long *shares)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    return virCgroupGetValueU64(group,
Pablo Greco 40546a
+                                VIR_CGROUP_CONTROLLER_CPU,
Pablo Greco 40546a
+                                "cpu.shares", shares);
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
 virCgroupBackend virCgroupV1Backend = {
Pablo Greco 40546a
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -1818,6 +1838,9 @@ virCgroupBackend virCgroupV1Backend = {
Pablo Greco 40546a
     .denyDevice = virCgroupV1DenyDevice,
Pablo Greco 40546a
     .allowAllDevices = virCgroupV1AllowAllDevices,
Pablo Greco 40546a
     .denyAllDevices = virCgroupV1DenyAllDevices,
Pablo Greco 40546a
+
Pablo Greco 40546a
+    .setCpuShares = virCgroupV1SetCpuShares,
Pablo Greco 40546a
+    .getCpuShares = virCgroupV1GetCpuShares,
Pablo Greco 40546a
 };
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a