c480ed
From a9c415edc1bc386ac6f4be91e98fe23469b62011 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <a9c415edc1bc386ac6f4be91e98fe23469b62011@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:48 +0200
c480ed
Subject: [PATCH] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceWriteBps
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 02fe32d3aa965b21342bc2dee245e6e8e5ca8bf7)
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: <3bbdc28fe71070c8e351679a17d6889b866b46fd.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 ab587ea306..684bce4997 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -1435,19 +1435,7 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group,
c480ed
                                 const char *path,
c480ed
                                 unsigned long long wbps)
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%llu", blkstr, wbps) < 0)
c480ed
-        return -1;
c480ed
-
c480ed
-    return virCgroupSetValueStr(group,
c480ed
-                               VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                               "blkio.throttle.write_bps_device",
c480ed
-                               str);
c480ed
+    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWriteBps, -1, path, wbps);
c480ed
 }
c480ed
 
c480ed
 
c480ed
@@ -1529,25 +1517,7 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group,
c480ed
                                 const char *path,
c480ed
                                 unsigned long long *wbps)
c480ed
 {
c480ed
-    VIR_AUTOFREE(char *) str = NULL;
c480ed
-
c480ed
-    if (virCgroupGetValueForBlkDev(group,
c480ed
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                   "blkio.throttle.write_bps_device",
c480ed
-                                   path,
c480ed
-                                   &str) < 0)
c480ed
-        return -1;
c480ed
-
c480ed
-    if (!str) {
c480ed
-        *wbps = 0;
c480ed
-    } else if (virStrToLong_ull(str, NULL, 10, wbps) < 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, getBlkioDeviceWriteBps, -1, path, wbps);
c480ed
 }
c480ed
 
c480ed
 /**
c480ed
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c480ed
index 3f1055a5d8..67e795a2b7 100644
c480ed
--- a/src/util/vircgroupbackend.h
c480ed
+++ b/src/util/vircgroupbackend.h
c480ed
@@ -200,6 +200,16 @@ typedef int
c480ed
                                     const char *path,
c480ed
                                     unsigned long long *rbps);
c480ed
 
c480ed
+typedef int
c480ed
+(*virCgroupSetBlkioDeviceWriteBpsCB)(virCgroupPtr group,
c480ed
+                                     const char *path,
c480ed
+                                     unsigned long long wbps);
c480ed
+
c480ed
+typedef int
c480ed
+(*virCgroupGetBlkioDeviceWriteBpsCB)(virCgroupPtr group,
c480ed
+                                     const char *path,
c480ed
+                                     unsigned long long *wbps);
c480ed
+
c480ed
 struct _virCgroupBackend {
c480ed
     virCgroupBackendType type;
c480ed
 
c480ed
@@ -236,6 +246,8 @@ struct _virCgroupBackend {
c480ed
     virCgroupGetBlkioDeviceWriteIopsCB getBlkioDeviceWriteIops;
c480ed
     virCgroupSetBlkioDeviceReadBpsCB setBlkioDeviceReadBps;
c480ed
     virCgroupGetBlkioDeviceReadBpsCB getBlkioDeviceReadBps;
c480ed
+    virCgroupSetBlkioDeviceWriteBpsCB setBlkioDeviceWriteBps;
c480ed
+    virCgroupGetBlkioDeviceWriteBpsCB getBlkioDeviceWriteBps;
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 e5663ccfb9..c044414dfd 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -1330,6 +1330,54 @@ virCgroupV1GetBlkioDeviceReadBps(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV1SetBlkioDeviceWriteBps(virCgroupPtr group,
c480ed
+                                  const char *path,
c480ed
+                                  unsigned long long wbps)
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%llu", blkstr, wbps) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
+    return virCgroupSetValueStr(group,
c480ed
+                                VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                                "blkio.throttle.write_bps_device",
c480ed
+                                str);
c480ed
+}
c480ed
+
c480ed
+
c480ed
+static int
c480ed
+virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group,
c480ed
+                                  const char *path,
c480ed
+                                  unsigned long long *wbps)
c480ed
+{
c480ed
+    VIR_AUTOFREE(char *) str = NULL;
c480ed
+
c480ed
+    if (virCgroupGetValueForBlkDev(group,
c480ed
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                                   "blkio.throttle.write_bps_device",
c480ed
+                                   path,
c480ed
+                                   &str) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
+    if (!str) {
c480ed
+        *wbps = 0;
c480ed
+    } else if (virStrToLong_ull(str, NULL, 10, wbps) < 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
@@ -1364,6 +1412,8 @@ virCgroupBackend virCgroupV1Backend = {
c480ed
     .getBlkioDeviceWriteIops = virCgroupV1GetBlkioDeviceWriteIops,
c480ed
     .setBlkioDeviceReadBps = virCgroupV1SetBlkioDeviceReadBps,
c480ed
     .getBlkioDeviceReadBps = virCgroupV1GetBlkioDeviceReadBps,
c480ed
+    .setBlkioDeviceWriteBps = virCgroupV1SetBlkioDeviceWriteBps,
c480ed
+    .getBlkioDeviceWriteBps = virCgroupV1GetBlkioDeviceWriteBps,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed