render / rpms / libvirt

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