c313de
From 0528d90148bcacba3fdbaa831ba89e043da94790 Mon Sep 17 00:00:00 2001
c313de
Message-Id: <0528d90148bcacba3fdbaa831ba89e043da94790@dist-git>
c313de
From: Pavel Hrdina <phrdina@redhat.com>
c313de
Date: Mon, 1 Jul 2019 17:06:45 +0200
c313de
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceReadIops
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
(cherry picked from commit dfaf5c6de1afa04fee1d9d97e79925fcc63682de)
c313de
c313de
Conflicts:
c313de
    src/util/vircgroup.c - missing commit 34e9c29357
c313de
c313de
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c313de
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
Message-Id: <52a494fa2de2835abd887d804f4047febc87bb60.1561993100.git.phrdina@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/util/vircgroup.c        | 34 ++-----------------------
c313de
 src/util/vircgroupbackend.h | 12 +++++++++
c313de
 src/util/vircgroupv1.c      | 50 +++++++++++++++++++++++++++++++++++++
c313de
 3 files changed, 64 insertions(+), 32 deletions(-)
c313de
c313de
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c313de
index 83ceb3a9cb..b8cbd95e0c 100644
c313de
--- a/src/util/vircgroup.c
c313de
+++ b/src/util/vircgroup.c
c313de
@@ -1385,19 +1385,7 @@ virCgroupSetBlkioDeviceReadIops(virCgroupPtr group,
c313de
                                 const char *path,
c313de
                                 unsigned int riops)
c313de
 {
c313de
-    VIR_AUTOFREE(char *) str = NULL;
c313de
-    VIR_AUTOFREE(char *) blkstr = NULL;
c313de
-
c313de
-    if (!(blkstr = virCgroupGetBlockDevString(path)))
c313de
-        return -1;
c313de
-
c313de
-    if (virAsprintf(&str, "%s%u", blkstr, riops) < 0)
c313de
-        return -1;
c313de
-
c313de
-    return virCgroupSetValueStr(group,
c313de
-                               VIR_CGROUP_CONTROLLER_BLKIO,
c313de
-                               "blkio.throttle.read_iops_device",
c313de
-                               str);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceReadIops, -1, path, riops);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1517,25 +1505,7 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group,
c313de
                                 const char *path,
c313de
                                 unsigned int *riops)
c313de
 {
c313de
-    VIR_AUTOFREE(char *) str = NULL;
c313de
-
c313de
-    if (virCgroupGetValueForBlkDev(group,
c313de
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c313de
-                                   "blkio.throttle.read_iops_device",
c313de
-                                   path,
c313de
-                                   &str) < 0)
c313de
-        return -1;
c313de
-
c313de
-    if (!str) {
c313de
-        *riops = 0;
c313de
-    } else if (virStrToLong_ui(str, NULL, 10, riops) < 0) {
c313de
-        virReportError(VIR_ERR_INTERNAL_ERROR,
c313de
-                       _("Unable to parse '%s' as an integer"),
c313de
-                       str);
c313de
-        return -1;
c313de
-    }
c313de
-
c313de
-    return 0;
c313de
+    VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceReadIops, -1, path, riops);
c313de
 }
c313de
 
c313de
 /**
c313de
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c313de
index aef2a87c61..0b7b4db1a4 100644
c313de
--- a/src/util/vircgroupbackend.h
c313de
+++ b/src/util/vircgroupbackend.h
c313de
@@ -170,6 +170,16 @@ typedef int
c313de
                                    const char *path,
c313de
                                    unsigned int *weight);
c313de
 
c313de
+typedef int
c313de
+(*virCgroupSetBlkioDeviceReadIopsCB)(virCgroupPtr group,
c313de
+                                     const char *path,
c313de
+                                     unsigned int riops);
c313de
+
c313de
+typedef int
c313de
+(*virCgroupGetBlkioDeviceReadIopsCB)(virCgroupPtr group,
c313de
+                                     const char *path,
c313de
+                                     unsigned int *riops);
c313de
+
c313de
 struct _virCgroupBackend {
c313de
     virCgroupBackendType type;
c313de
 
c313de
@@ -200,6 +210,8 @@ struct _virCgroupBackend {
c313de
     virCgroupGetBlkioIoDeviceServicedCB getBlkioIoDeviceServiced;
c313de
     virCgroupSetBlkioDeviceWeightCB setBlkioDeviceWeight;
c313de
     virCgroupGetBlkioDeviceWeightCB getBlkioDeviceWeight;
c313de
+    virCgroupSetBlkioDeviceReadIopsCB setBlkioDeviceReadIops;
c313de
+    virCgroupGetBlkioDeviceReadIopsCB getBlkioDeviceReadIops;
c313de
 };
c313de
 typedef struct _virCgroupBackend virCgroupBackend;
c313de
 typedef virCgroupBackend *virCgroupBackendPtr;
c313de
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c313de
index 1e5f38a2ee..47b0c13f38 100644
c313de
--- a/src/util/vircgroupv1.c
c313de
+++ b/src/util/vircgroupv1.c
c313de
@@ -1186,6 +1186,54 @@ virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group,
c313de
 }
c313de
 
c313de
 
c313de
+static int
c313de
+virCgroupV1SetBlkioDeviceReadIops(virCgroupPtr group,
c313de
+                                  const char *path,
c313de
+                                  unsigned int riops)
c313de
+{
c313de
+    VIR_AUTOFREE(char *) str = NULL;
c313de
+    VIR_AUTOFREE(char *) blkstr = NULL;
c313de
+
c313de
+    if (!(blkstr = virCgroupGetBlockDevString(path)))
c313de
+        return -1;
c313de
+
c313de
+    if (virAsprintf(&str, "%s%u", blkstr, riops) < 0)
c313de
+        return -1;
c313de
+
c313de
+    return virCgroupSetValueStr(group,
c313de
+                                VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                                "blkio.throttle.read_iops_device",
c313de
+                                str);
c313de
+}
c313de
+
c313de
+
c313de
+static int
c313de
+virCgroupV1GetBlkioDeviceReadIops(virCgroupPtr group,
c313de
+                                  const char *path,
c313de
+                                  unsigned int *riops)
c313de
+{
c313de
+    VIR_AUTOFREE(char *) str = NULL;
c313de
+
c313de
+    if (virCgroupGetValueForBlkDev(group,
c313de
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                                   "blkio.throttle.read_iops_device",
c313de
+                                   path,
c313de
+                                   &str) < 0)
c313de
+        return -1;
c313de
+
c313de
+    if (!str) {
c313de
+        *riops = 0;
c313de
+    } else if (virStrToLong_ui(str, NULL, 10, riops) < 0) {
c313de
+        virReportError(VIR_ERR_INTERNAL_ERROR,
c313de
+                       _("Unable to parse '%s' as an integer"),
c313de
+                       str);
c313de
+        return -1;
c313de
+    }
c313de
+
c313de
+    return 0;
c313de
+}
c313de
+
c313de
+
c313de
 virCgroupBackend virCgroupV1Backend = {
c313de
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
c313de
 
c313de
@@ -1214,6 +1262,8 @@ virCgroupBackend virCgroupV1Backend = {
c313de
     .getBlkioIoDeviceServiced = virCgroupV1GetBlkioIoDeviceServiced,
c313de
     .setBlkioDeviceWeight = virCgroupV1SetBlkioDeviceWeight,
c313de
     .getBlkioDeviceWeight = virCgroupV1GetBlkioDeviceWeight,
c313de
+    .setBlkioDeviceReadIops = virCgroupV1SetBlkioDeviceReadIops,
c313de
+    .getBlkioDeviceReadIops = virCgroupV1GetBlkioDeviceReadIops,
c313de
 };
c313de
 
c313de
 
c313de
-- 
c313de
2.22.0
c313de