]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroup: extract virCgroupV1(Set|Get)CpuCfsQuota
authorPavel Hrdina <phrdina@redhat.com>
Fri, 17 Aug 2018 14:22:56 +0000 (16:22 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 25 Sep 2018 11:40:22 +0000 (13:40 +0200)
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/util/vircgroup.c
src/util/vircgroupbackend.h
src/util/vircgrouppriv.h
src/util/vircgroupv1.c

index 8594f75eafe6fb66ebac7d56805bd108a6c54deb..44e88c46f2ab6baf0f2ce6c435e3fda23fca7d4e 100644 (file)
@@ -555,7 +555,7 @@ virCgroupSetValueI64(virCgroupPtr group,
 }
 
 
-static int
+int
 virCgroupGetValueI64(virCgroupPtr group,
                      int controller,
                      const char *key,
@@ -2254,19 +2254,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);
 }
 
 
@@ -2590,9 +2578,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);
 }
 
 
index 7dc1f77bfd04244b6832b83b1355efe581a4e166..f7c230db7627f3ff14c0e96dec1267d14f4d10ee 100644 (file)
@@ -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;
index 7b985280e1601bd3022dcffed171c7dfba9493d8..38c911e8edae8bbcbca77d5dc8133ebd73b1f502 100644 (file)
@@ -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);
index f1760d474d48ad8b9b0d6b7cc8c5ed07c8dac8ca..ea206d8b37248ad188fd7c87e84ca5a10fe39030 100644 (file)
@@ -1815,6 +1815,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,
 
@@ -1872,6 +1902,8 @@ virCgroupBackend virCgroupV1Backend = {
     .getCpuShares = virCgroupV1GetCpuShares,
     .setCpuCfsPeriod = virCgroupV1SetCpuCfsPeriod,
     .getCpuCfsPeriod = virCgroupV1GetCpuCfsPeriod,
+    .setCpuCfsQuota = virCgroupV1SetCpuCfsQuota,
+    .getCpuCfsQuota = virCgroupV1GetCpuCfsQuota,
 };