render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From 1ae8ce96561e368af7e68d3837d9e794b023c530 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <1ae8ce96561e368af7e68d3837d9e794b023c530@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:58 +0200
c480ed
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)CpuCfsQuota
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 5436fd75d808ad7b595a06bfd727e8de3283ef1a)
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: <cb76fa8f21f7a46d9e3b9fa19bcfb5c22652a53a.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c        | 20 +++-----------------
c480ed
 src/util/vircgroupbackend.h | 10 ++++++++++
c480ed
 src/util/vircgrouppriv.h    |  5 +++++
c480ed
 src/util/vircgroupv1.c      | 32 ++++++++++++++++++++++++++++++++
c480ed
 4 files changed, 50 insertions(+), 17 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index f4d995b22a..a3e7954d03 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -559,7 +559,7 @@ virCgroupSetValueI64(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
-static int
c480ed
+int
c480ed
 virCgroupGetValueI64(virCgroupPtr group,
c480ed
                      int controller,
c480ed
                      const char *key,
c480ed
@@ -2258,19 +2258,7 @@ virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period)
c480ed
 int
c480ed
 virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota)
c480ed
 {
c480ed
-    /* The cfs_quota should be greater or equal than 1ms */
c480ed
-    if (cfs_quota >= 0 &&
c480ed
-        (cfs_quota < 1000 ||
c480ed
-         cfs_quota > ULLONG_MAX / 1000)) {
c480ed
-        virReportError(VIR_ERR_INVALID_ARG,
c480ed
-                       _("cfs_quota '%lld' must be in range (1000, %llu)"),
c480ed
-                       cfs_quota, ULLONG_MAX / 1000);
c480ed
-        return -1;
c480ed
-    }
c480ed
-
c480ed
-    return virCgroupSetValueI64(group,
c480ed
-                                VIR_CGROUP_CONTROLLER_CPU,
c480ed
-                                "cpu.cfs_quota_us", cfs_quota);
c480ed
+    VIR_CGROUP_BACKEND_CALL(group, setCpuCfsQuota, -1, cfs_quota);
c480ed
 }
c480ed
 
c480ed
 
c480ed
@@ -2594,9 +2582,7 @@ virCgroupKillPainfully(virCgroupPtr group)
c480ed
 int
c480ed
 virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota)
c480ed
 {
c480ed
-    return virCgroupGetValueI64(group,
c480ed
-                                VIR_CGROUP_CONTROLLER_CPU,
c480ed
-                                "cpu.cfs_quota_us", cfs_quota);
c480ed
+    VIR_CGROUP_BACKEND_CALL(group, getCpuCfsQuota, -1, cfs_quota);
c480ed
 }
c480ed
 
c480ed
 
c480ed
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c480ed
index 7dc1f77bfd..f7c230db76 100644
c480ed
--- a/src/util/vircgroupbackend.h
c480ed
+++ b/src/util/vircgroupbackend.h
c480ed
@@ -292,6 +292,14 @@ typedef int
c480ed
 (*virCgroupGetCpuCfsPeriodCB)(virCgroupPtr group,
c480ed
                               unsigned long long *cfs_period);
c480ed
 
c480ed
+typedef int
c480ed
+(*virCgroupSetCpuCfsQuotaCB)(virCgroupPtr group,
c480ed
+                             long long cfs_quota);
c480ed
+
c480ed
+typedef int
c480ed
+(*virCgroupGetCpuCfsQuotaCB)(virCgroupPtr group,
c480ed
+                             long long *cfs_quota);
c480ed
+
c480ed
 struct _virCgroupBackend {
c480ed
     virCgroupBackendType type;
c480ed
 
c480ed
@@ -351,6 +359,8 @@ struct _virCgroupBackend {
c480ed
     virCgroupGetCpuSharesCB getCpuShares;
c480ed
     virCgroupSetCpuCfsPeriodCB setCpuCfsPeriod;
c480ed
     virCgroupGetCpuCfsPeriodCB getCpuCfsPeriod;
c480ed
+    virCgroupSetCpuCfsQuotaCB setCpuCfsQuota;
c480ed
+    virCgroupGetCpuCfsQuotaCB getCpuCfsQuota;
c480ed
 };
c480ed
 typedef struct _virCgroupBackend virCgroupBackend;
c480ed
 typedef virCgroupBackend *virCgroupBackendPtr;
c480ed
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
c480ed
index 7b985280e1..38c911e8ed 100644
c480ed
--- a/src/util/vircgrouppriv.h
c480ed
+++ b/src/util/vircgrouppriv.h
c480ed
@@ -78,6 +78,11 @@ int virCgroupSetValueI64(virCgroupPtr group,
c480ed
                          const char *key,
c480ed
                          long long int value);
c480ed
 
c480ed
+int virCgroupGetValueI64(virCgroupPtr group,
c480ed
+                         int controller,
c480ed
+                         const char *key,
c480ed
+                         long long int *value);
c480ed
+
c480ed
 int virCgroupPartitionEscape(char **path);
c480ed
 
c480ed
 char *virCgroupGetBlockDevString(const char *path);
c480ed
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c480ed
index dc4cf1e9db..25f7376026 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -1816,6 +1816,36 @@ virCgroupV1GetCpuCfsPeriod(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV1SetCpuCfsQuota(virCgroupPtr group,
c480ed
+                          long long cfs_quota)
c480ed
+{
c480ed
+    /* The cfs_quota should be greater or equal than 1ms */
c480ed
+    if (cfs_quota >= 0 &&
c480ed
+        (cfs_quota < 1000 ||
c480ed
+         cfs_quota > ULLONG_MAX / 1000)) {
c480ed
+        virReportError(VIR_ERR_INVALID_ARG,
c480ed
+                       _("cfs_quota '%lld' must be in range (1000, %llu)"),
c480ed
+                       cfs_quota, ULLONG_MAX / 1000);
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    return virCgroupSetValueI64(group,
c480ed
+                                VIR_CGROUP_CONTROLLER_CPU,
c480ed
+                                "cpu.cfs_quota_us", cfs_quota);
c480ed
+}
c480ed
+
c480ed
+
c480ed
+static int
c480ed
+virCgroupV1GetCpuCfsQuota(virCgroupPtr group,
c480ed
+                          long long *cfs_quota)
c480ed
+{
c480ed
+    return virCgroupGetValueI64(group,
c480ed
+                                VIR_CGROUP_CONTROLLER_CPU,
c480ed
+                                "cpu.cfs_quota_us", cfs_quota);
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV1Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
c480ed
 
c480ed
@@ -1873,6 +1903,8 @@ virCgroupBackend virCgroupV1Backend = {
c480ed
     .getCpuShares = virCgroupV1GetCpuShares,
c480ed
     .setCpuCfsPeriod = virCgroupV1SetCpuCfsPeriod,
c480ed
     .getCpuCfsPeriod = virCgroupV1GetCpuCfsPeriod,
c480ed
+    .setCpuCfsQuota = virCgroupV1SetCpuCfsQuota,
c480ed
+    .getCpuCfsQuota = virCgroupV1GetCpuCfsQuota,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed