render / rpms / libvirt

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