render / rpms / libvirt

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