render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 86865e9638ec63808b1f68e4bd9b4896b5438ece Mon Sep 17 00:00:00 2001
Message-Id: <86865e9638ec63808b1f68e4bd9b4896b5438ece@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:56 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)CpuShares
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 857aac1f55bc1c44be4c03c4b721632caedd2a23)

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <d43fdbd54cb3c387df54c11d2bd24483c717bd5a.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroup.c        |  8 ++------
 src/util/vircgroupbackend.h | 11 +++++++++++
 src/util/vircgroupv1.c      | 23 +++++++++++++++++++++++
 3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 67c68f3dc6..953e353ec3 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -2205,18 +2205,14 @@ virCgroupGetDomainTotalCpuStats(virCgroupPtr group,
 int
 virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares)
 {
-    return virCgroupSetValueU64(group,
-                                VIR_CGROUP_CONTROLLER_CPU,
-                                "cpu.shares", shares);
+    VIR_CGROUP_BACKEND_CALL(group, setCpuShares, -1, shares);
 }
 
 
 int
 virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares)
 {
-    return virCgroupGetValueU64(group,
-                                VIR_CGROUP_CONTROLLER_CPU,
-                                "cpu.shares", shares);
+    VIR_CGROUP_BACKEND_CALL(group, getCpuShares, -1, shares);
 }
 
 
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 436c83f6fa..54fbead8a2 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -276,6 +276,14 @@ typedef int
 typedef int
 (*virCgroupDenyAllDevicesCB)(virCgroupPtr group);
 
+typedef int
+(*virCgroupSetCpuSharesCB)(virCgroupPtr group,
+                           unsigned long long shares);
+
+typedef int
+(*virCgroupGetCpuSharesCB)(virCgroupPtr group,
+                           unsigned long long *shares);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -330,6 +338,9 @@ struct _virCgroupBackend {
     virCgroupDenyDeviceCB denyDevice;
     virCgroupAllowAllDevicesCB allowAllDevices;
     virCgroupDenyAllDevicesCB denyAllDevices;
+
+    virCgroupSetCpuSharesCB setCpuShares;
+    virCgroupGetCpuSharesCB getCpuShares;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 34393812d2..537845bafe 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1766,6 +1766,26 @@ virCgroupV1DenyAllDevices(virCgroupPtr group)
 }
 
 
+static int
+virCgroupV1SetCpuShares(virCgroupPtr group,
+                        unsigned long long shares)
+{
+    return virCgroupSetValueU64(group,
+                                VIR_CGROUP_CONTROLLER_CPU,
+                                "cpu.shares", shares);
+}
+
+
+static int
+virCgroupV1GetCpuShares(virCgroupPtr group,
+                        unsigned long long *shares)
+{
+    return virCgroupGetValueU64(group,
+                                VIR_CGROUP_CONTROLLER_CPU,
+                                "cpu.shares", shares);
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -1818,6 +1838,9 @@ virCgroupBackend virCgroupV1Backend = {
     .denyDevice = virCgroupV1DenyDevice,
     .allowAllDevices = virCgroupV1AllowAllDevices,
     .denyAllDevices = virCgroupV1DenyAllDevices,
+
+    .setCpuShares = virCgroupV1SetCpuShares,
+    .getCpuShares = virCgroupV1GetCpuShares,
 };
 
 
-- 
2.22.0