From 1ae8ce96561e368af7e68d3837d9e794b023c530 Mon Sep 17 00:00:00 2001
Message-Id: <1ae8ce96561e368af7e68d3837d9e794b023c530@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:58 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)CpuCfsQuota
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 5436fd75d808ad7b595a06bfd727e8de3283ef1a)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <cb76fa8f21f7a46d9e3b9fa19bcfb5c22652a53a.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@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 f4d995b22a..a3e7954d03 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -559,7 +559,7 @@ virCgroupSetValueI64(virCgroupPtr group,
}
-static int
+int
virCgroupGetValueI64(virCgroupPtr group,
int controller,
const char *key,
@@ -2258,19 +2258,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);
}
@@ -2594,9 +2582,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 7dc1f77bfd..f7c230db76 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -292,6 +292,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;
@@ -351,6 +359,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 dc4cf1e9db..25f7376026 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1816,6 +1816,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,
@@ -1873,6 +1903,8 @@ virCgroupBackend virCgroupV1Backend = {
.getCpuShares = virCgroupV1GetCpuShares,
.setCpuCfsPeriod = virCgroupV1SetCpuCfsPeriod,
.getCpuCfsPeriod = virCgroupV1GetCpuCfsPeriod,
+ .setCpuCfsQuota = virCgroupV1SetCpuCfsQuota,
+ .getCpuCfsQuota = virCgroupV1GetCpuCfsQuota,
};
--
2.22.0