]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: vircgroup: move virCgroupGetValueStr out of virCgroupGetValueForBlkDev
authorPavel Hrdina <phrdina@redhat.com>
Tue, 18 Jun 2019 13:24:41 +0000 (15:24 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 21 Jun 2019 12:35:57 +0000 (14:35 +0200)
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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/vircgroup.c
src/util/vircgrouppriv.h
src/util/vircgroupv1.c
src/util/vircgroupv2.c

index 278453ea2fe50d42672f3b0cd3cb3755580c5a67..e32215935b0cdfa7dbe2cb0a4de0856f4b107d6a 100644 (file)
@@ -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;
 
index 758091811e19d83e1eb8f8ee9cf7a4f8ba99811e..334095719e0d5a08972fb19d105b6aa71dc917bf 100644 (file)
@@ -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,
index 8ce10d360870720128a685f68cfe7970f572666d..064b99dceb9dc9c4f173f22ba8fb8c1ba62b46cb 100644 (file)
@@ -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 (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "blkio.throttle.read_bps_device",
+                             &value) < 0) {
+        return -1;
+    }
 
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "blkio.throttle.read_bps_device",
-                                   path,
-                                   &str) < 0)
+    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 (virCgroupGetValueStr(group,
+                             VIR_CGROUP_CONTROLLER_BLKIO,
+                             "blkio.throttle.write_bps_device",
+                             &value) < 0) {
+        return -1;
+    }
 
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "blkio.throttle.write_bps_device",
-                                   path,
-                                   &str) < 0)
+    if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
         return -1;
 
     if (!str) {
index 0cfbc962644077149dc08d8a00a153de5a4c2e42..de3a9dae8a0008b4db141339a6db41eb4f205dc4 100644 (file)
@@ -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 {