render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From 10bd6c74aa383403fae5ef7f4aec98d28246d972 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <10bd6c74aa383403fae5ef7f4aec98d28246d972@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Tue, 2 Jul 2019 15:13:25 +0200
c480ed
Subject: [PATCH] util: vircgroup: move virCgroupGetValueStr out of
c480ed
 virCgroupGetValueForBlkDev
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
If we need to get a path of specific file and we need to check its
c480ed
existence before we use it then we can reuse that path to get value
c480ed
for specific device.  This way we will not build the path again in
c480ed
virCgroupGetValueForBlkDev.
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
(cherry picked from commit c23829f18a9b104466af88eb909a3fd9660b9cbe)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1658890
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <72fe6534d0e19e271bac2aeb35bac028e67cfac2.1562073117.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c     |  8 +----
c480ed
 src/util/vircgrouppriv.h |  6 ++--
c480ed
 src/util/vircgroupv1.c   | 70 ++++++++++++++++++++++++++--------------
c480ed
 src/util/vircgroupv2.c   | 65 +++++++++++++++++++++++--------------
c480ed
 4 files changed, 88 insertions(+), 61 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index 769e23a523..37f6def08d 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -538,20 +538,14 @@ virCgroupGetValueStr(virCgroupPtr group,
c480ed
 
c480ed
 
c480ed
 int
c480ed
-virCgroupGetValueForBlkDev(virCgroupPtr group,
c480ed
-                           int controller,
c480ed
-                           const char *key,
c480ed
+virCgroupGetValueForBlkDev(const char *str,
c480ed
                            const char *path,
c480ed
                            char **value)
c480ed
 {
c480ed
     VIR_AUTOFREE(char *) prefix = NULL;
c480ed
-    VIR_AUTOFREE(char *) str = NULL;
c480ed
     char **lines = NULL;
c480ed
     int ret = -1;
c480ed
 
c480ed
-    if (virCgroupGetValueStr(group, controller, key, &str) < 0)
c480ed
-        goto error;
c480ed
-
c480ed
     if (!(prefix = virCgroupGetBlockDevString(path)))
c480ed
         goto error;
c480ed
 
c480ed
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
c480ed
index bdb3d493b1..aec38e2ac5 100644
c480ed
--- a/src/util/vircgrouppriv.h
c480ed
+++ b/src/util/vircgrouppriv.h
c480ed
@@ -102,10 +102,8 @@ int virCgroupPartitionEscape(char **path);
c480ed
 
c480ed
 char *virCgroupGetBlockDevString(const char *path);
c480ed
 
c480ed
-int virCgroupGetValueForBlkDev(virCgroupPtr group,
c480ed
-                               int controller,
c480ed
-                               const char *key,
c480ed
-                               const char *path,
c480ed
+int virCgroupGetValueForBlkDev(const char *str,
c480ed
+                               const char *devPath,
c480ed
                                char **value);
c480ed
 
c480ed
 int virCgroupNew(pid_t pid,
c480ed
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c480ed
index 58bd20d636..e51db6ee1f 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -1181,12 +1181,16 @@ virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group,
c480ed
                                 unsigned int *weight)
c480ed
 {
c480ed
     VIR_AUTOFREE(char *) str = NULL;
c480ed
+    VIR_AUTOFREE(char *) value = NULL;
c480ed
 
c480ed
-    if (virCgroupGetValueForBlkDev(group,
c480ed
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                   "blkio.weight_device",
c480ed
-                                   path,
c480ed
-                                   &str) < 0)
c480ed
+    if (virCgroupGetValueStr(group,
c480ed
+                             VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                             "blkio.weight_device",
c480ed
+                             &value) < 0) {
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
c480ed
         return -1;
c480ed
 
c480ed
     if (!str) {
c480ed
@@ -1229,12 +1233,16 @@ virCgroupV1GetBlkioDeviceReadIops(virCgroupPtr group,
c480ed
                                   unsigned int *riops)
c480ed
 {
c480ed
     VIR_AUTOFREE(char *) str = NULL;
c480ed
+    VIR_AUTOFREE(char *) value = NULL;
c480ed
 
c480ed
-    if (virCgroupGetValueForBlkDev(group,
c480ed
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                   "blkio.throttle.read_iops_device",
c480ed
-                                   path,
c480ed
-                                   &str) < 0)
c480ed
+    if (virCgroupGetValueStr(group,
c480ed
+                             VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                             "blkio.throttle.read_iops_device",
c480ed
+                             &value) < 0) {
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
c480ed
         return -1;
c480ed
 
c480ed
     if (!str) {
c480ed
@@ -1277,12 +1285,16 @@ virCgroupV1GetBlkioDeviceWriteIops(virCgroupPtr group,
c480ed
                                    unsigned int *wiops)
c480ed
 {
c480ed
     VIR_AUTOFREE(char *) str = NULL;
c480ed
+    VIR_AUTOFREE(char *) value = NULL;
c480ed
 
c480ed
-    if (virCgroupGetValueForBlkDev(group,
c480ed
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                   "blkio.throttle.write_iops_device",
c480ed
-                                   path,
c480ed
-                                   &str) < 0)
c480ed
+    if (virCgroupGetValueStr(group,
c480ed
+                             VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                             "blkio.throttle.write_iops_device",
c480ed
+                             &value) < 0) {
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
c480ed
         return -1;
c480ed
 
c480ed
     if (!str) {
c480ed
@@ -1325,12 +1337,16 @@ virCgroupV1GetBlkioDeviceReadBps(virCgroupPtr group,
c480ed
                                  unsigned long long *rbps)
c480ed
 {
c480ed
     VIR_AUTOFREE(char *) str = NULL;
c480ed
+    VIR_AUTOFREE(char *) value = NULL;
c480ed
 
c480ed
-    if (virCgroupGetValueForBlkDev(group,
c480ed
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                   "blkio.throttle.read_bps_device",
c480ed
-                                   path,
c480ed
-                                   &str) < 0)
c480ed
+    if (virCgroupGetValueStr(group,
c480ed
+                             VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                             "blkio.throttle.read_bps_device",
c480ed
+                             &value) < 0) {
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
c480ed
         return -1;
c480ed
 
c480ed
     if (!str) {
c480ed
@@ -1373,12 +1389,16 @@ virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group,
c480ed
                                   unsigned long long *wbps)
c480ed
 {
c480ed
     VIR_AUTOFREE(char *) str = NULL;
c480ed
+    VIR_AUTOFREE(char *) value = NULL;
c480ed
 
c480ed
-    if (virCgroupGetValueForBlkDev(group,
c480ed
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                   "blkio.throttle.write_bps_device",
c480ed
-                                   path,
c480ed
-                                   &str) < 0)
c480ed
+    if (virCgroupGetValueStr(group,
c480ed
+                             VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                             "blkio.throttle.write_bps_device",
c480ed
+                             &value) < 0) {
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
c480ed
         return -1;
c480ed
 
c480ed
     if (!str) {
c480ed
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c480ed
index 749efa199b..e9bb331dd4 100644
c480ed
--- a/src/util/vircgroupv2.c
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -787,15 +787,18 @@ virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group,
c480ed
                                 unsigned int *weight)
c480ed
 {
c480ed
     VIR_AUTOFREE(char *) str = NULL;
c480ed
+    VIR_AUTOFREE(char *) value = NULL;
c480ed
 
c480ed
-    if (virCgroupGetValueForBlkDev(group,
c480ed
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                   "io.weight",
c480ed
-                                   path,
c480ed
-                                   &str) < 0) {
c480ed
+    if (virCgroupGetValueStr(group,
c480ed
+                             VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                             "io.weight",
c480ed
+                             &value) < 0) {
c480ed
         return -1;
c480ed
     }
c480ed
 
c480ed
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
     if (!str) {
c480ed
         *weight = 0;
c480ed
     } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) {
c480ed
@@ -841,17 +844,20 @@ virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group,
c480ed
                                   unsigned int *riops)
c480ed
 {
c480ed
     VIR_AUTOFREE(char *) str = NULL;
c480ed
+    VIR_AUTOFREE(char *) value = NULL;
c480ed
     const char *name = "riops=";
c480ed
     char *tmp;
c480ed
 
c480ed
-    if (virCgroupGetValueForBlkDev(group,
c480ed
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                   "io.max",
c480ed
-                                   path,
c480ed
-                                   &str) < 0) {
c480ed
+    if (virCgroupGetValueStr(group,
c480ed
+                             VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                             "io.max",
c480ed
+                             &value) < 0) {
c480ed
         return -1;
c480ed
     }
c480ed
 
c480ed
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
     if (!str) {
c480ed
         *riops = 0;
c480ed
     } else {
c480ed
@@ -909,17 +915,20 @@ virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group,
c480ed
                                    unsigned int *wiops)
c480ed
 {
c480ed
     VIR_AUTOFREE(char *) str = NULL;
c480ed
+    VIR_AUTOFREE(char *) value = NULL;
c480ed
     const char *name = "wiops=";
c480ed
     char *tmp;
c480ed
 
c480ed
-    if (virCgroupGetValueForBlkDev(group,
c480ed
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                   "io.max",
c480ed
-                                   path,
c480ed
-                                   &str) < 0) {
c480ed
+    if (virCgroupGetValueStr(group,
c480ed
+                             VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                             "io.max",
c480ed
+                             &value) < 0) {
c480ed
         return -1;
c480ed
     }
c480ed
 
c480ed
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
     if (!str) {
c480ed
         *wiops = 0;
c480ed
     } else {
c480ed
@@ -977,17 +986,20 @@ virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group,
c480ed
                                  unsigned long long *rbps)
c480ed
 {
c480ed
     VIR_AUTOFREE(char *) str = NULL;
c480ed
+    VIR_AUTOFREE(char *) value = NULL;
c480ed
     const char *name = "rbps=";
c480ed
     char *tmp;
c480ed
 
c480ed
-    if (virCgroupGetValueForBlkDev(group,
c480ed
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                   "io.max",
c480ed
-                                   path,
c480ed
-                                   &str) < 0) {
c480ed
+    if (virCgroupGetValueStr(group,
c480ed
+                             VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                             "io.max",
c480ed
+                             &value) < 0) {
c480ed
         return -1;
c480ed
     }
c480ed
 
c480ed
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
     if (!str) {
c480ed
         *rbps = 0;
c480ed
     } else {
c480ed
@@ -1045,17 +1057,20 @@ virCgroupV2GetBlkioDeviceWriteBps(virCgroupPtr group,
c480ed
                                   unsigned long long *wbps)
c480ed
 {
c480ed
     VIR_AUTOFREE(char *) str = NULL;
c480ed
+    VIR_AUTOFREE(char *) value = NULL;
c480ed
     const char *name = "wbps=";
c480ed
     char *tmp;
c480ed
 
c480ed
-    if (virCgroupGetValueForBlkDev(group,
c480ed
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
-                                   "io.max",
c480ed
-                                   path,
c480ed
-                                   &str) < 0) {
c480ed
+    if (virCgroupGetValueStr(group,
c480ed
+                             VIR_CGROUP_CONTROLLER_BLKIO,
c480ed
+                             "io.max",
c480ed
+                             &value) < 0) {
c480ed
         return -1;
c480ed
     }
c480ed
 
c480ed
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
     if (!str) {
c480ed
         *wbps = 0;
c480ed
     } else {
c480ed
-- 
c480ed
2.22.0
c480ed