Blob Blame History Raw
From 1d91616a1f70531a38695b1634e5538e1699b648 Mon Sep 17 00:00:00 2001
Message-Id: <1d91616a1f70531a38695b1634e5538e1699b648@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:07:00 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1GetCpuacct*Usage
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 83704663234b894251eb197638e81b652674103e)

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

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

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index fa9fa52019..4f791204d3 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -2265,8 +2265,7 @@ virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota)
 int
 virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage)
 {
-    return virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT,
-                                "cpuacct.usage_percpu", usage);
+    VIR_CGROUP_BACKEND_CALL(group, getCpuacctPercpuUsage, -1, usage);
 }
 
 
@@ -2589,9 +2588,7 @@ virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota)
 int
 virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage)
 {
-    return virCgroupGetValueU64(group,
-                                VIR_CGROUP_CONTROLLER_CPUACCT,
-                                "cpuacct.usage", usage);
+    VIR_CGROUP_BACKEND_CALL(group, getCpuacctUsage, -1, usage);
 }
 
 
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index d3d5e7c222..39a75a69f4 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -303,6 +303,14 @@ typedef int
 typedef bool
 (*virCgroupSupportsCpuBWCB)(virCgroupPtr cgroup);
 
+typedef int
+(*virCgroupGetCpuacctUsageCB)(virCgroupPtr group,
+                              unsigned long long *usage);
+
+typedef int
+(*virCgroupGetCpuacctPercpuUsageCB)(virCgroupPtr group,
+                                    char **usage);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -365,6 +373,9 @@ struct _virCgroupBackend {
     virCgroupSetCpuCfsQuotaCB setCpuCfsQuota;
     virCgroupGetCpuCfsQuotaCB getCpuCfsQuota;
     virCgroupSupportsCpuBWCB supportsCpuBW;
+
+    virCgroupGetCpuacctUsageCB getCpuacctUsage;
+    virCgroupGetCpuacctPercpuUsageCB getCpuacctPercpuUsage;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index f2a8839f6e..9fb0c5cb96 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1864,6 +1864,25 @@ virCgroupV1SupportsCpuBW(virCgroupPtr cgroup)
 }
 
 
+static int
+virCgroupV1GetCpuacctUsage(virCgroupPtr group,
+                           unsigned long long *usage)
+{
+    return virCgroupGetValueU64(group,
+                                VIR_CGROUP_CONTROLLER_CPUACCT,
+                                "cpuacct.usage", usage);
+}
+
+
+static int
+virCgroupV1GetCpuacctPercpuUsage(virCgroupPtr group,
+                                 char **usage)
+{
+    return virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT,
+                                "cpuacct.usage_percpu", usage);
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -1924,6 +1943,9 @@ virCgroupBackend virCgroupV1Backend = {
     .setCpuCfsQuota = virCgroupV1SetCpuCfsQuota,
     .getCpuCfsQuota = virCgroupV1GetCpuCfsQuota,
     .supportsCpuBW = virCgroupV1SupportsCpuBW,
+
+    .getCpuacctUsage = virCgroupV1GetCpuacctUsage,
+    .getCpuacctPercpuUsage = virCgroupV1GetCpuacctPercpuUsage,
 };
 
 
-- 
2.22.0