render / rpms / libvirt

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