On Tue, Sep 18, 2018 at 5:45 PM, Pavel Hrdina <phrdina@redhat.com> wrote:
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
 
---
 src/util/vircgroup.c        | 20 +++-----------------
 src/util/vircgroupbackend.h | 10 ++++++++++
 src/util/vircgrouppriv.h    |  5 +++++
 src/util/vircgroupv1.c      | 32 ++++++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index beb661df4b..17b8c13cf9 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -561,7 +561,7 @@ virCgroupSetValueI64(virCgroupPtr group,
 }


-static int
+int
 virCgroupGetValueI64(virCgroupPtr group,
                      int controller,
                      const char *key,
@@ -2260,19 +2260,7 @@ virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period)
 int
 virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota)
 {
-    /* The cfs_quota should be greater or equal than 1ms */
-    if (cfs_quota >= 0 &&
-        (cfs_quota < 1000 ||
-         cfs_quota > ULLONG_MAX / 1000)) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("cfs_quota '%lld' must be in range (1000, %llu)"),
-                       cfs_quota, ULLONG_MAX / 1000);
-        return -1;
-    }
-
-    return virCgroupSetValueI64(group,
-                                VIR_CGROUP_CONTROLLER_CPU,
-                                "cpu.cfs_quota_us", cfs_quota);
+    VIR_CGROUP_BACKEND_CALL(group, setCpuCfsQuota, -1, cfs_quota);
 }


@@ -2596,9 +2584,7 @@ virCgroupKillPainfully(virCgroupPtr group)
 int
 virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota)
 {
-    return virCgroupGetValueI64(group,
-                                VIR_CGROUP_CONTROLLER_CPU,
-                                "cpu.cfs_quota_us", cfs_quota);
+    VIR_CGROUP_BACKEND_CALL(group, getCpuCfsQuota, -1, cfs_quota);
 }


diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 59f68169ba..b94a89069a 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -284,6 +284,14 @@ typedef int
 (*virCgroupGetCpuCfsPeriodCB)(virCgroupPtr group,
                               unsigned long long *cfs_period);

+typedef int
+(*virCgroupSetCpuCfsQuotaCB)(virCgroupPtr group,
+                             long long cfs_quota);
+
+typedef int
+(*virCgroupGetCpuCfsQuotaCB)(virCgroupPtr group,
+                             long long *cfs_quota);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;

@@ -343,6 +351,8 @@ struct _virCgroupBackend {
     virCgroupGetCpuSharesCB getCpuShares;
     virCgroupSetCpuCfsPeriodCB setCpuCfsPeriod;
     virCgroupGetCpuCfsPeriodCB getCpuCfsPeriod;
+    virCgroupSetCpuCfsQuotaCB setCpuCfsQuota;
+    virCgroupGetCpuCfsQuotaCB getCpuCfsQuota;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
index 7b985280e1..38c911e8ed 100644
--- a/src/util/vircgrouppriv.h
+++ b/src/util/vircgrouppriv.h
@@ -78,6 +78,11 @@ int virCgroupSetValueI64(virCgroupPtr group,
                          const char *key,
                          long long int value);

+int virCgroupGetValueI64(virCgroupPtr group,
+                         int controller,
+                         const char *key,
+                         long long int *value);
+
 int virCgroupPartitionEscape(char **path);

 char *virCgroupGetBlockDevString(const char *path);
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 3641371512..5de6d27f48 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1810,6 +1810,36 @@ virCgroupV1GetCpuCfsPeriod(virCgroupPtr group,
 }


+static int
+virCgroupV1SetCpuCfsQuota(virCgroupPtr group,
+                          long long cfs_quota)
+{
+    /* The cfs_quota should be greater or equal than 1ms */
+    if (cfs_quota >= 0 &&
+        (cfs_quota < 1000 ||
+         cfs_quota > ULLONG_MAX / 1000)) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("cfs_quota '%lld' must be in range (1000, %llu)"),
+                       cfs_quota, ULLONG_MAX / 1000);
+        return -1;
+    }
+
+    return virCgroupSetValueI64(group,
+                                VIR_CGROUP_CONTROLLER_CPU,
+                                "cpu.cfs_quota_us", cfs_quota);
+}
+
+
+static int
+virCgroupV1GetCpuCfsQuota(virCgroupPtr group,
+                          long long *cfs_quota)
+{
+    return virCgroupGetValueI64(group,
+                                VIR_CGROUP_CONTROLLER_CPU,
+                                "cpu.cfs_quota_us", cfs_quota);
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,

@@ -1867,6 +1897,8 @@ virCgroupBackend virCgroupV1Backend = {
     .getCpuShares = virCgroupV1GetCpuShares,
     .setCpuCfsPeriod = virCgroupV1SetCpuCfsPeriod,
     .getCpuCfsPeriod = virCgroupV1GetCpuCfsPeriod,
+    .setCpuCfsQuota = virCgroupV1SetCpuCfsQuota,
+    .getCpuCfsQuota = virCgroupV1GetCpuCfsQuota,
 };
 

--
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list