[PATCH 2/4] util: vircgroup: move virCgroupGetValueStr out of virCgroupGetValueForBlkDev

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If we need to get a path of specific file and we need to check its
existence before we use it then we can reuse that path to get value
for specific device.  This way we will not build the path again in
virCgroupGetValueForBlkDev.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/util/vircgroup.c     |  8 +----
 src/util/vircgrouppriv.h |  6 ++--
 src/util/vircgroupv1.c   | 70 ++++++++++++++++++++++++++--------------
 src/util/vircgroupv2.c   | 65 +++++++++++++++++++++++--------------
 4 files changed, 88 insertions(+), 61 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 278453ea2f..e32215935b 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -533,20 +533,14 @@ virCgroupGetValueStr(virCgroupPtr group,
 
 
 int
-virCgroupGetValueForBlkDev(virCgroupPtr group,
-                           int controller,
-                           const char *key,
+virCgroupGetValueForBlkDev(const char *str,
                            const char *path,
                            char **value)
 {
     VIR_AUTOFREE(char *) prefix = NULL;
-    VIR_AUTOFREE(char *) str = NULL;
     char **lines = NULL;
     int ret = -1;
 
-    if (virCgroupGetValueStr(group, controller, key, &str) < 0)
-        goto error;
-
     if (!(prefix = virCgroupGetBlockDevString(path)))
         goto error;
 
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
index 758091811e..334095719e 100644
--- a/src/util/vircgrouppriv.h
+++ b/src/util/vircgrouppriv.h
@@ -98,10 +98,8 @@ int virCgroupPartitionEscape(char **path);
 
 char *virCgroupGetBlockDevString(const char *path);
 
-int virCgroupGetValueForBlkDev(virCgroupPtr group,
-                               int controller,
-                               const char *key,
-                               const char *path,
+int virCgroupGetValueForBlkDev(const char *str,
+                               const char *devPath,
                                char **value);
 
 int virCgroupNew(pid_t pid,
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 8ce10d3608..064b99dceb 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1181,12 +1181,16 @@ virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group,
                                 unsigned int *weight)
 {
     VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) value = NULL;
 
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "blkio.weight_device",
-                                   path,
-                                   &str) < 0)
+    if (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "blkio.weight_device",
+                             &value) < 0) {
+        return -1;
+    }
+
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
         return -1;
 
     if (!str) {
@@ -1229,12 +1233,16 @@ virCgroupV1GetBlkioDeviceReadIops(virCgroupPtr group,
                                   unsigned int *riops)
 {
     VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) value = NULL;
 
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "blkio.throttle.read_iops_device",
-                                   path,
-                                   &str) < 0)
+    if (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "blkio.throttle.read_iops_device",
+                             &value) < 0) {
+        return -1;
+    }
+
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
         return -1;
 
     if (!str) {
@@ -1277,12 +1285,16 @@ virCgroupV1GetBlkioDeviceWriteIops(virCgroupPtr group,
                                    unsigned int *wiops)
 {
     VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) value = NULL;
 
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "blkio.throttle.write_iops_device",
-                                   path,
-                                   &str) < 0)
+    if (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "blkio.throttle.write_iops_device",
+                             &value) < 0) {
+        return -1;
+    }
+
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
         return -1;
 
     if (!str) {
@@ -1325,12 +1337,16 @@ virCgroupV1GetBlkioDeviceReadBps(virCgroupPtr group,
                                  unsigned long long *rbps)
 {
     VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) value = NULL;
 
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "blkio.throttle.read_bps_device",
-                                   path,
-                                   &str) < 0)
+    if (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "blkio.throttle.read_bps_device",
+                             &value) < 0) {
+        return -1;
+    }
+
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
         return -1;
 
     if (!str) {
@@ -1373,12 +1389,16 @@ virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group,
                                   unsigned long long *wbps)
 {
     VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) value = NULL;
 
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "blkio.throttle.write_bps_device",
-                                   path,
-                                   &str) < 0)
+    if (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "blkio.throttle.write_bps_device",
+                             &value) < 0) {
+        return -1;
+    }
+
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
         return -1;
 
     if (!str) {
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 0cfbc96264..de3a9dae8a 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -750,15 +750,18 @@ virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group,
                                 unsigned int *weight)
 {
     VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) value = NULL;
 
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "io.weight",
-                                   path,
-                                   &str) < 0) {
+    if (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "io.weight",
+                             &value) < 0) {
         return -1;
     }
 
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
+        return -1;
+
     if (!str) {
         *weight = 0;
     } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) {
@@ -804,17 +807,20 @@ virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group,
                                   unsigned int *riops)
 {
     VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) value = NULL;
     const char *name = "riops=";
     char *tmp;
 
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "io.max",
-                                   path,
-                                   &str) < 0) {
+    if (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "io.max",
+                             &value) < 0) {
         return -1;
     }
 
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
+        return -1;
+
     if (!str) {
         *riops = 0;
     } else {
@@ -872,17 +878,20 @@ virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group,
                                    unsigned int *wiops)
 {
     VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) value = NULL;
     const char *name = "wiops=";
     char *tmp;
 
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "io.max",
-                                   path,
-                                   &str) < 0) {
+    if (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "io.max",
+                             &value) < 0) {
         return -1;
     }
 
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
+        return -1;
+
     if (!str) {
         *wiops = 0;
     } else {
@@ -940,17 +949,20 @@ virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group,
                                  unsigned long long *rbps)
 {
     VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) value = NULL;
     const char *name = "rbps=";
     char *tmp;
 
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "io.max",
-                                   path,
-                                   &str) < 0) {
+    if (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "io.max",
+                             &value) < 0) {
         return -1;
     }
 
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
+        return -1;
+
     if (!str) {
         *rbps = 0;
     } else {
@@ -1008,17 +1020,20 @@ virCgroupV2GetBlkioDeviceWriteBps(virCgroupPtr group,
                                   unsigned long long *wbps)
 {
     VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) value = NULL;
     const char *name = "wbps=";
     char *tmp;
 
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "io.max",
-                                   path,
-                                   &str) < 0) {
+    if (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "io.max",
+                             &value) < 0) {
         return -1;
     }
 
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
+        return -1;
+
     if (!str) {
         *wbps = 0;
     } else {
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux