render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From b80aeea66090c760fb2863d8bb7d682ff40a8361 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <b80aeea66090c760fb2863d8bb7d682ff40a8361@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:46 +0200
c480ed
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceWriteIops
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 2edd0bcda65122ba16f92c2b95f06ae7dad072ba)
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: <10671a59ba137b61325a9d5a730f53a2032dd49b.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c        | 34 ++-----------------------
c480ed
 src/util/vircgroupbackend.h | 12 +++++++++
c480ed
 src/util/vircgroupv1.c      | 50 +++++++++++++++++++++++++++++++++++++
c480ed
 3 files changed, 64 insertions(+), 32 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index b8cbd95e0c..4b682d72d7 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -1402,19 +1402,7 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group,
c480ed
                                  const char *path,
c480ed
                                  unsigned int wiops)
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%u", blkstr, wiops) < 0)
c480ed
-        return -1;
c480ed
-
c480ed
-    return virCgroupSetValueStr(group,
c480ed
-                               VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                               "blkio.throttle.write_iops_device",
c480ed
-                               str);
c480ed
+    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWriteIops, -1, path, wiops);
c480ed
 }
c480ed
 
c480ed
 
c480ed
@@ -1521,25 +1509,7 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group,
c480ed
                                  const char *path,
c480ed
                                  unsigned int *wiops)
c480ed
 {
c480ed
-    VIR_AUTOFREE(char *) str = NULL;
c480ed
-
c480ed
-    if (virCgroupGetValueForBlkDev(group,
c480ed
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                   "blkio.throttle.write_iops_device",
c480ed
-                                   path,
c480ed
-                                   &str) < 0)
c480ed
-        return -1;
c480ed
-
c480ed
-    if (!str) {
c480ed
-        *wiops = 0;
c480ed
-    } else if (virStrToLong_ui(str, NULL, 10, wiops) < 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, getBlkioDeviceWriteIops, -1, path, wiops);
c480ed
 }
c480ed
 
c480ed
 /**
c480ed
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c480ed
index 0b7b4db1a4..58e1828e01 100644
c480ed
--- a/src/util/vircgroupbackend.h
c480ed
+++ b/src/util/vircgroupbackend.h
c480ed
@@ -180,6 +180,16 @@ typedef int
c480ed
                                      const char *path,
c480ed
                                      unsigned int *riops);
c480ed
 
c480ed
+typedef int
c480ed
+(*virCgroupSetBlkioDeviceWriteIopsCB)(virCgroupPtr group,
c480ed
+                                      const char *path,
c480ed
+                                      unsigned int wiops);
c480ed
+
c480ed
+typedef int
c480ed
+(*virCgroupGetBlkioDeviceWriteIopsCB)(virCgroupPtr group,
c480ed
+                                      const char *path,
c480ed
+                                      unsigned int *wiops);
c480ed
+
c480ed
 struct _virCgroupBackend {
c480ed
     virCgroupBackendType type;
c480ed
 
c480ed
@@ -212,6 +222,8 @@ struct _virCgroupBackend {
c480ed
     virCgroupGetBlkioDeviceWeightCB getBlkioDeviceWeight;
c480ed
     virCgroupSetBlkioDeviceReadIopsCB setBlkioDeviceReadIops;
c480ed
     virCgroupGetBlkioDeviceReadIopsCB getBlkioDeviceReadIops;
c480ed
+    virCgroupSetBlkioDeviceWriteIopsCB setBlkioDeviceWriteIops;
c480ed
+    virCgroupGetBlkioDeviceWriteIopsCB getBlkioDeviceWriteIops;
c480ed
 };
c480ed
 typedef struct _virCgroupBackend virCgroupBackend;
c480ed
 typedef virCgroupBackend *virCgroupBackendPtr;
c480ed
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c480ed
index 47b0c13f38..5b0199a89f 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -1234,6 +1234,54 @@ virCgroupV1GetBlkioDeviceReadIops(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV1SetBlkioDeviceWriteIops(virCgroupPtr group,
c480ed
+                                   const char *path,
c480ed
+                                   unsigned int wiops)
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%u", blkstr, wiops) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
+    return virCgroupSetValueStr(group,
c480ed
+                                VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                                "blkio.throttle.write_iops_device",
c480ed
+                                str);
c480ed
+}
c480ed
+
c480ed
+
c480ed
+static int
c480ed
+virCgroupV1GetBlkioDeviceWriteIops(virCgroupPtr group,
c480ed
+                                   const char *path,
c480ed
+                                   unsigned int *wiops)
c480ed
+{
c480ed
+    VIR_AUTOFREE(char *) str = NULL;
c480ed
+
c480ed
+    if (virCgroupGetValueForBlkDev(group,
c480ed
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                                   "blkio.throttle.write_iops_device",
c480ed
+                                   path,
c480ed
+                                   &str) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
+    if (!str) {
c480ed
+        *wiops = 0;
c480ed
+    } else if (virStrToLong_ui(str, NULL, 10, wiops) < 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
@@ -1264,6 +1312,8 @@ virCgroupBackend virCgroupV1Backend = {
c480ed
     .getBlkioDeviceWeight = virCgroupV1GetBlkioDeviceWeight,
c480ed
     .setBlkioDeviceReadIops = virCgroupV1SetBlkioDeviceReadIops,
c480ed
     .getBlkioDeviceReadIops = virCgroupV1GetBlkioDeviceReadIops,
c480ed
+    .setBlkioDeviceWriteIops = virCgroupV1SetBlkioDeviceWriteIops,
c480ed
+    .getBlkioDeviceWriteIops = virCgroupV1GetBlkioDeviceWriteIops,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed