render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From af26c5b793fcd0206a105e75c6583ddfe57557c2 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <af26c5b793fcd0206a105e75c6583ddfe57557c2@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:44 +0200
c480ed
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceWeight
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 8f50f9ca24596c838082c7d8da4ffe7104d22b23)
c480ed
c480ed
Conflicts:
c480ed
    src/util/vircgroup.c - missing commit 34e9c29357
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: <1ad5f481f00748a6808760b50f4d1d0116191073.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c        | 36 +++-----------------------
c480ed
 src/util/vircgroupbackend.h | 12 +++++++++
c480ed
 src/util/vircgrouppriv.h    |  6 +++++
c480ed
 src/util/vircgroupv1.c      | 50 +++++++++++++++++++++++++++++++++++++
c480ed
 4 files changed, 71 insertions(+), 33 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index fd39144ed2..83ceb3a9cb 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -498,7 +498,7 @@ virCgroupGetValueStr(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
-static int
c480ed
+int
c480ed
 virCgroupGetValueForBlkDev(virCgroupPtr group,
c480ed
                            int controller,
c480ed
                            const char *key,
c480ed
@@ -1501,19 +1501,7 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group,
c480ed
                               const char *path,
c480ed
                               unsigned int weight)
c480ed
 {
c480ed
-    VIR_AUTOFREE(char *) str = NULL;
c480ed
-    VIR_AUTOFREE(char *) blkstr = NULL;
c480ed
-
c480ed
-    if (!(blkstr = virCgroupGetBlockDevString(path)))
c480ed
-        return -1;
c480ed
-
c480ed
-    if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
c480ed
-        return -1;
c480ed
-
c480ed
-    return virCgroupSetValueStr(group,
c480ed
-                               VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                               "blkio.weight_device",
c480ed
-                               str);
c480ed
+    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWeight, -1, path, weight);
c480ed
 }
c480ed
 
c480ed
 /**
c480ed
@@ -1665,25 +1653,7 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group,
c480ed
                               const char *path,
c480ed
                               unsigned int *weight)
c480ed
 {
c480ed
-    VIR_AUTOFREE(char *) str = NULL;
c480ed
-
c480ed
-    if (virCgroupGetValueForBlkDev(group,
c480ed
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                   "blkio.weight_device",
c480ed
-                                   path,
c480ed
-                                   &str) < 0)
c480ed
-        return -1;
c480ed
-
c480ed
-    if (!str) {
c480ed
-        *weight = 0;
c480ed
-    } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) {
c480ed
-        virReportError(VIR_ERR_INTERNAL_ERROR,
c480ed
-                       _("Unable to parse '%s' as an integer"),
c480ed
-                       str);
c480ed
-        return -1;
c480ed
-    }
c480ed
-
c480ed
-    return 0;
c480ed
+    VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWeight, -1, path, weight);
c480ed
 }
c480ed
 
c480ed
 
c480ed
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c480ed
index e16d631a0f..aef2a87c61 100644
c480ed
--- a/src/util/vircgroupbackend.h
c480ed
+++ b/src/util/vircgroupbackend.h
c480ed
@@ -160,6 +160,16 @@ typedef int
c480ed
                                        long long *requests_read,
c480ed
                                        long long *requests_write);
c480ed
 
c480ed
+typedef int
c480ed
+(*virCgroupSetBlkioDeviceWeightCB)(virCgroupPtr group,
c480ed
+                                   const char *path,
c480ed
+                                   unsigned int weight);
c480ed
+
c480ed
+typedef int
c480ed
+(*virCgroupGetBlkioDeviceWeightCB)(virCgroupPtr group,
c480ed
+                                   const char *path,
c480ed
+                                   unsigned int *weight);
c480ed
+
c480ed
 struct _virCgroupBackend {
c480ed
     virCgroupBackendType type;
c480ed
 
c480ed
@@ -188,6 +198,8 @@ struct _virCgroupBackend {
c480ed
     virCgroupGetBlkioWeightCB getBlkioWeight;
c480ed
     virCgroupGetBlkioIoServicedCB getBlkioIoServiced;
c480ed
     virCgroupGetBlkioIoDeviceServicedCB getBlkioIoDeviceServiced;
c480ed
+    virCgroupSetBlkioDeviceWeightCB setBlkioDeviceWeight;
c480ed
+    virCgroupGetBlkioDeviceWeightCB getBlkioDeviceWeight;
c480ed
 };
c480ed
 typedef struct _virCgroupBackend virCgroupBackend;
c480ed
 typedef virCgroupBackend *virCgroupBackendPtr;
c480ed
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
c480ed
index 525c288a9a..3a968c1ce2 100644
c480ed
--- a/src/util/vircgrouppriv.h
c480ed
+++ b/src/util/vircgrouppriv.h
c480ed
@@ -82,6 +82,12 @@ int virCgroupPartitionEscape(char **path);
c480ed
 
c480ed
 char *virCgroupGetBlockDevString(const char *path);
c480ed
 
c480ed
+int virCgroupGetValueForBlkDev(virCgroupPtr group,
c480ed
+                               int controller,
c480ed
+                               const char *key,
c480ed
+                               const char *path,
c480ed
+                               char **value);
c480ed
+
c480ed
 int virCgroupNewPartition(const char *path,
c480ed
                           bool create,
c480ed
                           int controllers,
c480ed
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c480ed
index 79c4812aef..1e5f38a2ee 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -1138,6 +1138,54 @@ virCgroupV1GetBlkioIoDeviceServiced(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group,
c480ed
+                                const char *path,
c480ed
+                                unsigned int weight)
c480ed
+{
c480ed
+    VIR_AUTOFREE(char *) str = NULL;
c480ed
+    VIR_AUTOFREE(char *) blkstr = NULL;
c480ed
+
c480ed
+    if (!(blkstr = virCgroupGetBlockDevString(path)))
c480ed
+        return -1;
c480ed
+
c480ed
+    if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
+    return virCgroupSetValueStr(group,
c480ed
+                                VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                                "blkio.weight_device",
c480ed
+                                str);
c480ed
+}
c480ed
+
c480ed
+
c480ed
+static int
c480ed
+virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group,
c480ed
+                                const char *path,
c480ed
+                                unsigned int *weight)
c480ed
+{
c480ed
+    VIR_AUTOFREE(char *) str = NULL;
c480ed
+
c480ed
+    if (virCgroupGetValueForBlkDev(group,
c480ed
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                                   "blkio.weight_device",
c480ed
+                                   path,
c480ed
+                                   &str) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
+    if (!str) {
c480ed
+        *weight = 0;
c480ed
+    } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) {
c480ed
+        virReportError(VIR_ERR_INTERNAL_ERROR,
c480ed
+                       _("Unable to parse '%s' as an integer"),
c480ed
+                       str);
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    return 0;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV1Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
c480ed
 
c480ed
@@ -1164,6 +1212,8 @@ virCgroupBackend virCgroupV1Backend = {
c480ed
     .getBlkioWeight = virCgroupV1GetBlkioWeight,
c480ed
     .getBlkioIoServiced = virCgroupV1GetBlkioIoServiced,
c480ed
     .getBlkioIoDeviceServiced = virCgroupV1GetBlkioIoDeviceServiced,
c480ed
+    .setBlkioDeviceWeight = virCgroupV1SetBlkioDeviceWeight,
c480ed
+    .getBlkioDeviceWeight = virCgroupV1GetBlkioDeviceWeight,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed