render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From 1d91616a1f70531a38695b1634e5538e1699b648 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <1d91616a1f70531a38695b1634e5538e1699b648@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:07:00 +0200
c480ed
Subject: [PATCH] vircgroup: extract virCgroupV1GetCpuacct*Usage
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 83704663234b894251eb197638e81b652674103e)
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: <fa6bba63dd9a7d3ad733b3107a613033e6fa6cd2.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c        |  7 ++-----
c480ed
 src/util/vircgroupbackend.h | 11 +++++++++++
c480ed
 src/util/vircgroupv1.c      | 22 ++++++++++++++++++++++
c480ed
 3 files changed, 35 insertions(+), 5 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index fa9fa52019..4f791204d3 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -2265,8 +2265,7 @@ virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota)
c480ed
 int
c480ed
 virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage)
c480ed
 {
c480ed
-    return virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT,
c480ed
-                                "cpuacct.usage_percpu", usage);
c480ed
+    VIR_CGROUP_BACKEND_CALL(group, getCpuacctPercpuUsage, -1, usage);
c480ed
 }
c480ed
 
c480ed
 
c480ed
@@ -2589,9 +2588,7 @@ virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota)
c480ed
 int
c480ed
 virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage)
c480ed
 {
c480ed
-    return virCgroupGetValueU64(group,
c480ed
-                                VIR_CGROUP_CONTROLLER_CPUACCT,
c480ed
-                                "cpuacct.usage", usage);
c480ed
+    VIR_CGROUP_BACKEND_CALL(group, getCpuacctUsage, -1, usage);
c480ed
 }
c480ed
 
c480ed
 
c480ed
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c480ed
index d3d5e7c222..39a75a69f4 100644
c480ed
--- a/src/util/vircgroupbackend.h
c480ed
+++ b/src/util/vircgroupbackend.h
c480ed
@@ -303,6 +303,14 @@ typedef int
c480ed
 typedef bool
c480ed
 (*virCgroupSupportsCpuBWCB)(virCgroupPtr cgroup);
c480ed
 
c480ed
+typedef int
c480ed
+(*virCgroupGetCpuacctUsageCB)(virCgroupPtr group,
c480ed
+                              unsigned long long *usage);
c480ed
+
c480ed
+typedef int
c480ed
+(*virCgroupGetCpuacctPercpuUsageCB)(virCgroupPtr group,
c480ed
+                                    char **usage);
c480ed
+
c480ed
 struct _virCgroupBackend {
c480ed
     virCgroupBackendType type;
c480ed
 
c480ed
@@ -365,6 +373,9 @@ struct _virCgroupBackend {
c480ed
     virCgroupSetCpuCfsQuotaCB setCpuCfsQuota;
c480ed
     virCgroupGetCpuCfsQuotaCB getCpuCfsQuota;
c480ed
     virCgroupSupportsCpuBWCB supportsCpuBW;
c480ed
+
c480ed
+    virCgroupGetCpuacctUsageCB getCpuacctUsage;
c480ed
+    virCgroupGetCpuacctPercpuUsageCB getCpuacctPercpuUsage;
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 f2a8839f6e..9fb0c5cb96 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -1864,6 +1864,25 @@ virCgroupV1SupportsCpuBW(virCgroupPtr cgroup)
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV1GetCpuacctUsage(virCgroupPtr group,
c480ed
+                           unsigned long long *usage)
c480ed
+{
c480ed
+    return virCgroupGetValueU64(group,
c480ed
+                                VIR_CGROUP_CONTROLLER_CPUACCT,
c480ed
+                                "cpuacct.usage", usage);
c480ed
+}
c480ed
+
c480ed
+
c480ed
+static int
c480ed
+virCgroupV1GetCpuacctPercpuUsage(virCgroupPtr group,
c480ed
+                                 char **usage)
c480ed
+{
c480ed
+    return virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT,
c480ed
+                                "cpuacct.usage_percpu", usage);
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV1Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
c480ed
 
c480ed
@@ -1924,6 +1943,9 @@ virCgroupBackend virCgroupV1Backend = {
c480ed
     .setCpuCfsQuota = virCgroupV1SetCpuCfsQuota,
c480ed
     .getCpuCfsQuota = virCgroupV1GetCpuCfsQuota,
c480ed
     .supportsCpuBW = virCgroupV1SupportsCpuBW,
c480ed
+
c480ed
+    .getCpuacctUsage = virCgroupV1GetCpuacctUsage,
c480ed
+    .getCpuacctPercpuUsage = virCgroupV1GetCpuacctPercpuUsage,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed