render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Pablo Greco 40546a
From 0528d90148bcacba3fdbaa831ba89e043da94790 Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <0528d90148bcacba3fdbaa831ba89e043da94790@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:06:45 +0200
Pablo Greco 40546a
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceReadIops
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 dfaf5c6de1afa04fee1d9d97e79925fcc63682de)
Pablo Greco 40546a
Pablo Greco 40546a
Conflicts:
Pablo Greco 40546a
    src/util/vircgroup.c - missing commit 34e9c29357
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: <52a494fa2de2835abd887d804f4047febc87bb60.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        | 34 ++-----------------------
Pablo Greco 40546a
 src/util/vircgroupbackend.h | 12 +++++++++
Pablo Greco 40546a
 src/util/vircgroupv1.c      | 50 +++++++++++++++++++++++++++++++++++++
Pablo Greco 40546a
 3 files changed, 64 insertions(+), 32 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
Pablo Greco 40546a
index 83ceb3a9cb..b8cbd95e0c 100644
Pablo Greco 40546a
--- a/src/util/vircgroup.c
Pablo Greco 40546a
+++ b/src/util/vircgroup.c
Pablo Greco 40546a
@@ -1385,19 +1385,7 @@ virCgroupSetBlkioDeviceReadIops(virCgroupPtr group,
Pablo Greco 40546a
                                 const char *path,
Pablo Greco 40546a
                                 unsigned int riops)
Pablo Greco 40546a
 {
Pablo Greco 40546a
-    VIR_AUTOFREE(char *) str = NULL;
Pablo Greco 40546a
-    VIR_AUTOFREE(char *) blkstr = NULL;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    if (!(blkstr = virCgroupGetBlockDevString(path)))
Pablo Greco 40546a
-        return -1;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    if (virAsprintf(&str, "%s%u", blkstr, riops) < 0)
Pablo Greco 40546a
-        return -1;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    return virCgroupSetValueStr(group,
Pablo Greco 40546a
-                               VIR_CGROUP_CONTROLLER_BLKIO,
Pablo Greco 40546a
-                               "blkio.throttle.read_iops_device",
Pablo Greco 40546a
-                               str);
Pablo Greco 40546a
+    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceReadIops, -1, path, riops);
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -1517,25 +1505,7 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group,
Pablo Greco 40546a
                                 const char *path,
Pablo Greco 40546a
                                 unsigned int *riops)
Pablo Greco 40546a
 {
Pablo Greco 40546a
-    VIR_AUTOFREE(char *) str = NULL;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    if (virCgroupGetValueForBlkDev(group,
Pablo Greco 40546a
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
Pablo Greco 40546a
-                                   "blkio.throttle.read_iops_device",
Pablo Greco 40546a
-                                   path,
Pablo Greco 40546a
-                                   &str) < 0)
Pablo Greco 40546a
-        return -1;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    if (!str) {
Pablo Greco 40546a
-        *riops = 0;
Pablo Greco 40546a
-    } else if (virStrToLong_ui(str, NULL, 10, riops) < 0) {
Pablo Greco 40546a
-        virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
-                       _("Unable to parse '%s' as an integer"),
Pablo Greco 40546a
-                       str);
Pablo Greco 40546a
-        return -1;
Pablo Greco 40546a
-    }
Pablo Greco 40546a
-
Pablo Greco 40546a
-    return 0;
Pablo Greco 40546a
+    VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceReadIops, -1, path, riops);
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 aef2a87c61..0b7b4db1a4 100644
Pablo Greco 40546a
--- a/src/util/vircgroupbackend.h
Pablo Greco 40546a
+++ b/src/util/vircgroupbackend.h
Pablo Greco 40546a
@@ -170,6 +170,16 @@ typedef int
Pablo Greco 40546a
                                    const char *path,
Pablo Greco 40546a
                                    unsigned int *weight);
Pablo Greco 40546a
 
Pablo Greco 40546a
+typedef int
Pablo Greco 40546a
+(*virCgroupSetBlkioDeviceReadIopsCB)(virCgroupPtr group,
Pablo Greco 40546a
+                                     const char *path,
Pablo Greco 40546a
+                                     unsigned int riops);
Pablo Greco 40546a
+
Pablo Greco 40546a
+typedef int
Pablo Greco 40546a
+(*virCgroupGetBlkioDeviceReadIopsCB)(virCgroupPtr group,
Pablo Greco 40546a
+                                     const char *path,
Pablo Greco 40546a
+                                     unsigned int *riops);
Pablo Greco 40546a
+
Pablo Greco 40546a
 struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupBackendType type;
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -200,6 +210,8 @@ struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupGetBlkioIoDeviceServicedCB getBlkioIoDeviceServiced;
Pablo Greco 40546a
     virCgroupSetBlkioDeviceWeightCB setBlkioDeviceWeight;
Pablo Greco 40546a
     virCgroupGetBlkioDeviceWeightCB getBlkioDeviceWeight;
Pablo Greco 40546a
+    virCgroupSetBlkioDeviceReadIopsCB setBlkioDeviceReadIops;
Pablo Greco 40546a
+    virCgroupGetBlkioDeviceReadIopsCB getBlkioDeviceReadIops;
Pablo Greco 40546a
 };
Pablo Greco 40546a
 typedef struct _virCgroupBackend virCgroupBackend;
Pablo Greco 40546a
 typedef virCgroupBackend *virCgroupBackendPtr;
Pablo Greco 40546a
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
Pablo Greco 40546a
index 1e5f38a2ee..47b0c13f38 100644
Pablo Greco 40546a
--- a/src/util/vircgroupv1.c
Pablo Greco 40546a
+++ b/src/util/vircgroupv1.c
Pablo Greco 40546a
@@ -1186,6 +1186,54 @@ virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1SetBlkioDeviceReadIops(virCgroupPtr group,
Pablo Greco 40546a
+                                  const char *path,
Pablo Greco 40546a
+                                  unsigned int riops)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    VIR_AUTOFREE(char *) str = NULL;
Pablo Greco 40546a
+    VIR_AUTOFREE(char *) blkstr = NULL;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (!(blkstr = virCgroupGetBlockDevString(path)))
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (virAsprintf(&str, "%s%u", blkstr, riops) < 0)
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return virCgroupSetValueStr(group,
Pablo Greco 40546a
+                                VIR_CGROUP_CONTROLLER_BLKIO,
Pablo Greco 40546a
+                                "blkio.throttle.read_iops_device",
Pablo Greco 40546a
+                                str);
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1GetBlkioDeviceReadIops(virCgroupPtr group,
Pablo Greco 40546a
+                                  const char *path,
Pablo Greco 40546a
+                                  unsigned int *riops)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    VIR_AUTOFREE(char *) str = NULL;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (virCgroupGetValueForBlkDev(group,
Pablo Greco 40546a
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
Pablo Greco 40546a
+                                   "blkio.throttle.read_iops_device",
Pablo Greco 40546a
+                                   path,
Pablo Greco 40546a
+                                   &str) < 0)
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (!str) {
Pablo Greco 40546a
+        *riops = 0;
Pablo Greco 40546a
+    } else if (virStrToLong_ui(str, NULL, 10, riops) < 0) {
Pablo Greco 40546a
+        virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
+                       _("Unable to parse '%s' as an integer"),
Pablo Greco 40546a
+                       str);
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return 0;
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
@@ -1214,6 +1262,8 @@ virCgroupBackend virCgroupV1Backend = {
Pablo Greco 40546a
     .getBlkioIoDeviceServiced = virCgroupV1GetBlkioIoDeviceServiced,
Pablo Greco 40546a
     .setBlkioDeviceWeight = virCgroupV1SetBlkioDeviceWeight,
Pablo Greco 40546a
     .getBlkioDeviceWeight = virCgroupV1GetBlkioDeviceWeight,
Pablo Greco 40546a
+    .setBlkioDeviceReadIops = virCgroupV1SetBlkioDeviceReadIops,
Pablo Greco 40546a
+    .getBlkioDeviceReadIops = virCgroupV1GetBlkioDeviceReadIops,
Pablo Greco 40546a
 };
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a