render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From b80aeea66090c760fb2863d8bb7d682ff40a8361 Mon Sep 17 00:00:00 2001
Message-Id: <b80aeea66090c760fb2863d8bb7d682ff40a8361@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:46 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceWriteIops
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 2edd0bcda65122ba16f92c2b95f06ae7dad072ba)

Conflicts:
    src/util/vircgroup.c - missing commit 34e9c29357

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <10671a59ba137b61325a9d5a730f53a2032dd49b.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroup.c        | 34 ++-----------------------
 src/util/vircgroupbackend.h | 12 +++++++++
 src/util/vircgroupv1.c      | 50 +++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 32 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index b8cbd95e0c..4b682d72d7 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1402,19 +1402,7 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group,
                                  const char *path,
                                  unsigned int wiops)
 {
-    VIR_AUTOFREE(char *) str = NULL;
-    VIR_AUTOFREE(char *) blkstr = NULL;
-
-    if (!(blkstr = virCgroupGetBlockDevString(path)))
-        return -1;
-
-    if (virAsprintf(&str, "%s%u", blkstr, wiops) < 0)
-        return -1;
-
-    return virCgroupSetValueStr(group,
-                               VIR_CGROUP_CONTROLLER_BLKIO,
-                               "blkio.throttle.write_iops_device",
-                               str);
+    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWriteIops, -1, path, wiops);
 }
 
 
@@ -1521,25 +1509,7 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group,
                                  const char *path,
                                  unsigned int *wiops)
 {
-    VIR_AUTOFREE(char *) str = NULL;
-
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "blkio.throttle.write_iops_device",
-                                   path,
-                                   &str) < 0)
-        return -1;
-
-    if (!str) {
-        *wiops = 0;
-    } else if (virStrToLong_ui(str, NULL, 10, wiops) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Unable to parse '%s' as an integer"),
-                       str);
-        return -1;
-    }
-
-    return 0;
+    VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWriteIops, -1, path, wiops);
 }
 
 /**
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 0b7b4db1a4..58e1828e01 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -180,6 +180,16 @@ typedef int
                                      const char *path,
                                      unsigned int *riops);
 
+typedef int
+(*virCgroupSetBlkioDeviceWriteIopsCB)(virCgroupPtr group,
+                                      const char *path,
+                                      unsigned int wiops);
+
+typedef int
+(*virCgroupGetBlkioDeviceWriteIopsCB)(virCgroupPtr group,
+                                      const char *path,
+                                      unsigned int *wiops);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -212,6 +222,8 @@ struct _virCgroupBackend {
     virCgroupGetBlkioDeviceWeightCB getBlkioDeviceWeight;
     virCgroupSetBlkioDeviceReadIopsCB setBlkioDeviceReadIops;
     virCgroupGetBlkioDeviceReadIopsCB getBlkioDeviceReadIops;
+    virCgroupSetBlkioDeviceWriteIopsCB setBlkioDeviceWriteIops;
+    virCgroupGetBlkioDeviceWriteIopsCB getBlkioDeviceWriteIops;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 47b0c13f38..5b0199a89f 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1234,6 +1234,54 @@ virCgroupV1GetBlkioDeviceReadIops(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV1SetBlkioDeviceWriteIops(virCgroupPtr group,
+                                   const char *path,
+                                   unsigned int wiops)
+{
+    VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) blkstr = NULL;
+
+    if (!(blkstr = virCgroupGetBlockDevString(path)))
+        return -1;
+
+    if (virAsprintf(&str, "%s%u", blkstr, wiops) < 0)
+        return -1;
+
+    return virCgroupSetValueStr(group,
+                                VIR_CGROUP_CONTROLLER_BLKIO,
+                                "blkio.throttle.write_iops_device",
+                                str);
+}
+
+
+static int
+virCgroupV1GetBlkioDeviceWriteIops(virCgroupPtr group,
+                                   const char *path,
+                                   unsigned int *wiops)
+{
+    VIR_AUTOFREE(char *) str = NULL;
+
+    if (virCgroupGetValueForBlkDev(group,
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
+                                   "blkio.throttle.write_iops_device",
+                                   path,
+                                   &str) < 0)
+        return -1;
+
+    if (!str) {
+        *wiops = 0;
+    } else if (virStrToLong_ui(str, NULL, 10, wiops) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to parse '%s' as an integer"),
+                       str);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -1264,6 +1312,8 @@ virCgroupBackend virCgroupV1Backend = {
     .getBlkioDeviceWeight = virCgroupV1GetBlkioDeviceWeight,
     .setBlkioDeviceReadIops = virCgroupV1SetBlkioDeviceReadIops,
     .getBlkioDeviceReadIops = virCgroupV1GetBlkioDeviceReadIops,
+    .setBlkioDeviceWriteIops = virCgroupV1SetBlkioDeviceWriteIops,
+    .getBlkioDeviceWriteIops = virCgroupV1GetBlkioDeviceWriteIops,
 };
 
 
-- 
2.22.0