render / rpms / libvirt

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