Pablo Greco 40546a
From d18c1d955b505493213e540d427868cc74e03c64 Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <d18c1d955b505493213e540d427868cc74e03c64@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:06:47 +0200
Pablo Greco 40546a
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceReadBps
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 32f199250bd52fe52cba6bfbc3ee6a7f6c88c2ff)
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: <562851da4866890cef588cf7f6f890118f3f81f4.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 4b682d72d7..ab587ea306 100644
Pablo Greco 40546a
--- a/src/util/vircgroup.c
Pablo Greco 40546a
+++ b/src/util/vircgroup.c
Pablo Greco 40546a
@@ -1419,19 +1419,7 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group,
Pablo Greco 40546a
                                const char *path,
Pablo Greco 40546a
                                unsigned long long rbps)
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%llu", blkstr, rbps) < 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_bps_device",
Pablo Greco 40546a
-                               str);
Pablo Greco 40546a
+    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceReadBps, -1, path, rbps);
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 /**
Pablo Greco 40546a
@@ -1525,25 +1513,7 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group,
Pablo Greco 40546a
                                const char *path,
Pablo Greco 40546a
                                unsigned long long *rbps)
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_bps_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
-        *rbps = 0;
Pablo Greco 40546a
-    } else if (virStrToLong_ull(str, NULL, 10, rbps) < 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, getBlkioDeviceReadBps, -1, path, rbps);
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 58e1828e01..3f1055a5d8 100644
Pablo Greco 40546a
--- a/src/util/vircgroupbackend.h
Pablo Greco 40546a
+++ b/src/util/vircgroupbackend.h
Pablo Greco 40546a
@@ -190,6 +190,16 @@ typedef int
Pablo Greco 40546a
                                       const char *path,
Pablo Greco 40546a
                                       unsigned int *wiops);
Pablo Greco 40546a
 
Pablo Greco 40546a
+typedef int
Pablo Greco 40546a
+(*virCgroupSetBlkioDeviceReadBpsCB)(virCgroupPtr group,
Pablo Greco 40546a
+                                    const char *path,
Pablo Greco 40546a
+                                    unsigned long long rbps);
Pablo Greco 40546a
+
Pablo Greco 40546a
+typedef int
Pablo Greco 40546a
+(*virCgroupGetBlkioDeviceReadBpsCB)(virCgroupPtr group,
Pablo Greco 40546a
+                                    const char *path,
Pablo Greco 40546a
+                                    unsigned long long *rbps);
Pablo Greco 40546a
+
Pablo Greco 40546a
 struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupBackendType type;
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -224,6 +234,8 @@ struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupGetBlkioDeviceReadIopsCB getBlkioDeviceReadIops;
Pablo Greco 40546a
     virCgroupSetBlkioDeviceWriteIopsCB setBlkioDeviceWriteIops;
Pablo Greco 40546a
     virCgroupGetBlkioDeviceWriteIopsCB getBlkioDeviceWriteIops;
Pablo Greco 40546a
+    virCgroupSetBlkioDeviceReadBpsCB setBlkioDeviceReadBps;
Pablo Greco 40546a
+    virCgroupGetBlkioDeviceReadBpsCB getBlkioDeviceReadBps;
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 5b0199a89f..e5663ccfb9 100644
Pablo Greco 40546a
--- a/src/util/vircgroupv1.c
Pablo Greco 40546a
+++ b/src/util/vircgroupv1.c
Pablo Greco 40546a
@@ -1282,6 +1282,54 @@ virCgroupV1GetBlkioDeviceWriteIops(virCgroupPtr group,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1SetBlkioDeviceReadBps(virCgroupPtr group,
Pablo Greco 40546a
+                                 const char *path,
Pablo Greco 40546a
+                                 unsigned long long rbps)
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%llu", blkstr, rbps) < 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_bps_device",
Pablo Greco 40546a
+                                str);
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1GetBlkioDeviceReadBps(virCgroupPtr group,
Pablo Greco 40546a
+                                 const char *path,
Pablo Greco 40546a
+                                 unsigned long long *rbps)
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_bps_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
+        *rbps = 0;
Pablo Greco 40546a
+    } else if (virStrToLong_ull(str, NULL, 10, rbps) < 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
@@ -1314,6 +1362,8 @@ virCgroupBackend virCgroupV1Backend = {
Pablo Greco 40546a
     .getBlkioDeviceReadIops = virCgroupV1GetBlkioDeviceReadIops,
Pablo Greco 40546a
     .setBlkioDeviceWriteIops = virCgroupV1SetBlkioDeviceWriteIops,
Pablo Greco 40546a
     .getBlkioDeviceWriteIops = virCgroupV1GetBlkioDeviceWriteIops,
Pablo Greco 40546a
+    .setBlkioDeviceReadBps = virCgroupV1SetBlkioDeviceReadBps,
Pablo Greco 40546a
+    .getBlkioDeviceReadBps = virCgroupV1GetBlkioDeviceReadBps,
Pablo Greco 40546a
 };
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a