c480ed
From 7fae41a63cd97501e3a4bf8fade48949d754f738 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <7fae41a63cd97501e3a4bf8fade48949d754f738@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:41 +0200
c480ed
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)BlkioWeight
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 c57b0be0cc200abb21cbe0473d96f447fd37b27d)
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: <23b514919f71ed2a44c04d7f62a031c4edc14365.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c        | 14 ++------------
c480ed
 src/util/vircgroupbackend.h | 20 ++++++++++++++++++++
c480ed
 src/util/vircgroupv1.c      | 29 +++++++++++++++++++++++++++++
c480ed
 3 files changed, 51 insertions(+), 12 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index e57aecb08a..d2ffa8aefe 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -1510,10 +1510,7 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group,
c480ed
 int
c480ed
 virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
c480ed
 {
c480ed
-    return virCgroupSetValueU64(group,
c480ed
-                                VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                "blkio.weight",
c480ed
-                                weight);
c480ed
+    VIR_CGROUP_BACKEND_CALL(group, setBlkioWeight, -1, weight);
c480ed
 }
c480ed
 
c480ed
 
c480ed
@@ -1528,14 +1525,7 @@ virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
c480ed
 int
c480ed
 virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight)
c480ed
 {
c480ed
-    unsigned long long tmp;
c480ed
-    int ret;
c480ed
-    ret = virCgroupGetValueU64(group,
c480ed
-                               VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                               "blkio.weight", &tmp);
c480ed
-    if (ret == 0)
c480ed
-        *weight = tmp;
c480ed
-    return ret;
c480ed
+    VIR_CGROUP_BACKEND_CALL(group, getBlkioWeight, -1, weight);
c480ed
 }
c480ed
 
c480ed
 /**
c480ed
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c480ed
index 74af796c2f..ccce65f1e2 100644
c480ed
--- a/src/util/vircgroupbackend.h
c480ed
+++ b/src/util/vircgroupbackend.h
c480ed
@@ -137,6 +137,14 @@ typedef int
c480ed
                        gid_t gid,
c480ed
                        int controllers);
c480ed
 
c480ed
+typedef int
c480ed
+(*virCgroupSetBlkioWeightCB)(virCgroupPtr group,
c480ed
+                             unsigned int weight);
c480ed
+
c480ed
+typedef int
c480ed
+(*virCgroupGetBlkioWeightCB)(virCgroupPtr group,
c480ed
+                             unsigned int *weight);
c480ed
+
c480ed
 struct _virCgroupBackend {
c480ed
     virCgroupBackendType type;
c480ed
 
c480ed
@@ -159,6 +167,10 @@ struct _virCgroupBackend {
c480ed
     virCgroupHasEmptyTasksCB hasEmptyTasks;
c480ed
     virCgroupBindMountCB bindMount;
c480ed
     virCgroupSetOwnerCB setOwner;
c480ed
+
c480ed
+    /* Optional cgroup controller specific callbacks. */
c480ed
+    virCgroupSetBlkioWeightCB setBlkioWeight;
c480ed
+    virCgroupGetBlkioWeightCB getBlkioWeight;
c480ed
 };
c480ed
 typedef struct _virCgroupBackend virCgroupBackend;
c480ed
 typedef virCgroupBackend *virCgroupBackendPtr;
c480ed
@@ -169,4 +181,12 @@ virCgroupBackendRegister(virCgroupBackendPtr backend);
c480ed
 virCgroupBackendPtr *
c480ed
 virCgroupBackendGetAll(void);
c480ed
 
c480ed
+# define VIR_CGROUP_BACKEND_CALL(group, func, ret, ...) \
c480ed
+    if (!group->backend->func) { \
c480ed
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, \
c480ed
+                       _("operation '%s' not supported"), #func); \
c480ed
+        return ret; \
c480ed
+    } \
c480ed
+    return group->backend->func(group, ##__VA_ARGS__);
c480ed
+
c480ed
 #endif /* __VIR_CGROUP_BACKEND_H__ */
c480ed
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c480ed
index c1e2583912..d67b3164ce 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -929,6 +929,32 @@ virCgroupV1SetOwner(virCgroupPtr cgroup,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV1SetBlkioWeight(virCgroupPtr group,
c480ed
+                          unsigned int weight)
c480ed
+{
c480ed
+    return virCgroupSetValueU64(group,
c480ed
+                                VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                                "blkio.weight",
c480ed
+                                weight);
c480ed
+}
c480ed
+
c480ed
+
c480ed
+static int
c480ed
+virCgroupV1GetBlkioWeight(virCgroupPtr group,
c480ed
+                          unsigned int *weight)
c480ed
+{
c480ed
+    unsigned long long tmp;
c480ed
+    int ret;
c480ed
+    ret = virCgroupGetValueU64(group,
c480ed
+                               VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                               "blkio.weight", &tmp);
c480ed
+    if (ret == 0)
c480ed
+        *weight = tmp;
c480ed
+    return ret;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV1Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
c480ed
 
c480ed
@@ -950,6 +976,9 @@ virCgroupBackend virCgroupV1Backend = {
c480ed
     .hasEmptyTasks = virCgroupV1HasEmptyTasks,
c480ed
     .bindMount = virCgroupV1BindMount,
c480ed
     .setOwner = virCgroupV1SetOwner,
c480ed
+
c480ed
+    .setBlkioWeight = virCgroupV1SetBlkioWeight,
c480ed
+    .getBlkioWeight = virCgroupV1GetBlkioWeight,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed