Blob Blame History Raw
From d18c1d955b505493213e540d427868cc74e03c64 Mon Sep 17 00:00:00 2001
Message-Id: <d18c1d955b505493213e540d427868cc74e03c64@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:47 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceReadBps
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 32f199250bd52fe52cba6bfbc3ee6a7f6c88c2ff)

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: <562851da4866890cef588cf7f6f890118f3f81f4.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 4b682d72d7..ab587ea306 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1419,19 +1419,7 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group,
                                const char *path,
                                unsigned long long rbps)
 {
-    VIR_AUTOFREE(char *) str = NULL;
-    VIR_AUTOFREE(char *) blkstr = NULL;
-
-    if (!(blkstr = virCgroupGetBlockDevString(path)))
-        return -1;
-
-    if (virAsprintf(&str, "%s%llu", blkstr, rbps) < 0)
-        return -1;
-
-    return virCgroupSetValueStr(group,
-                               VIR_CGROUP_CONTROLLER_BLKIO,
-                               "blkio.throttle.read_bps_device",
-                               str);
+    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceReadBps, -1, path, rbps);
 }
 
 /**
@@ -1525,25 +1513,7 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group,
                                const char *path,
                                unsigned long long *rbps)
 {
-    VIR_AUTOFREE(char *) str = NULL;
-
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "blkio.throttle.read_bps_device",
-                                   path,
-                                   &str) < 0)
-        return -1;
-
-    if (!str) {
-        *rbps = 0;
-    } else if (virStrToLong_ull(str, NULL, 10, rbps) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Unable to parse '%s' as an integer"),
-                       str);
-        return -1;
-    }
-
-    return 0;
+    VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceReadBps, -1, path, rbps);
 }
 
 /**
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 58e1828e01..3f1055a5d8 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -190,6 +190,16 @@ typedef int
                                       const char *path,
                                       unsigned int *wiops);
 
+typedef int
+(*virCgroupSetBlkioDeviceReadBpsCB)(virCgroupPtr group,
+                                    const char *path,
+                                    unsigned long long rbps);
+
+typedef int
+(*virCgroupGetBlkioDeviceReadBpsCB)(virCgroupPtr group,
+                                    const char *path,
+                                    unsigned long long *rbps);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -224,6 +234,8 @@ struct _virCgroupBackend {
     virCgroupGetBlkioDeviceReadIopsCB getBlkioDeviceReadIops;
     virCgroupSetBlkioDeviceWriteIopsCB setBlkioDeviceWriteIops;
     virCgroupGetBlkioDeviceWriteIopsCB getBlkioDeviceWriteIops;
+    virCgroupSetBlkioDeviceReadBpsCB setBlkioDeviceReadBps;
+    virCgroupGetBlkioDeviceReadBpsCB getBlkioDeviceReadBps;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 5b0199a89f..e5663ccfb9 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1282,6 +1282,54 @@ virCgroupV1GetBlkioDeviceWriteIops(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV1SetBlkioDeviceReadBps(virCgroupPtr group,
+                                 const char *path,
+                                 unsigned long long rbps)
+{
+    VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) blkstr = NULL;
+
+    if (!(blkstr = virCgroupGetBlockDevString(path)))
+        return -1;
+
+    if (virAsprintf(&str, "%s%llu", blkstr, rbps) < 0)
+        return -1;
+
+    return virCgroupSetValueStr(group,
+                                VIR_CGROUP_CONTROLLER_BLKIO,
+                                "blkio.throttle.read_bps_device",
+                                str);
+}
+
+
+static int
+virCgroupV1GetBlkioDeviceReadBps(virCgroupPtr group,
+                                 const char *path,
+                                 unsigned long long *rbps)
+{
+    VIR_AUTOFREE(char *) str = NULL;
+
+    if (virCgroupGetValueForBlkDev(group,
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
+                                   "blkio.throttle.read_bps_device",
+                                   path,
+                                   &str) < 0)
+        return -1;
+
+    if (!str) {
+        *rbps = 0;
+    } else if (virStrToLong_ull(str, NULL, 10, rbps) < 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,
 
@@ -1314,6 +1362,8 @@ virCgroupBackend virCgroupV1Backend = {
     .getBlkioDeviceReadIops = virCgroupV1GetBlkioDeviceReadIops,
     .setBlkioDeviceWriteIops = virCgroupV1SetBlkioDeviceWriteIops,
     .getBlkioDeviceWriteIops = virCgroupV1GetBlkioDeviceWriteIops,
+    .setBlkioDeviceReadBps = virCgroupV1SetBlkioDeviceReadBps,
+    .getBlkioDeviceReadBps = virCgroupV1GetBlkioDeviceReadBps,
 };
 
 
-- 
2.22.0