From 10bd6c74aa383403fae5ef7f4aec98d28246d972 Mon Sep 17 00:00:00 2001 Message-Id: <10bd6c74aa383403fae5ef7f4aec98d28246d972@dist-git> From: Pavel Hrdina Date: Tue, 2 Jul 2019 15:13:25 +0200 Subject: [PATCH] util: vircgroup: move virCgroupGetValueStr out of virCgroupGetValueForBlkDev MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko (cherry picked from commit c23829f18a9b104466af88eb909a3fd9660b9cbe) Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1658890 Signed-off-by: Pavel Hrdina Message-Id: <72fe6534d0e19e271bac2aeb35bac028e67cfac2.1562073117.git.phrdina@redhat.com> Reviewed-by: Ján Tomko --- 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 769e23a523..37f6def08d 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -538,20 +538,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 bdb3d493b1..aec38e2ac5 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -102,10 +102,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 58bd20d636..e51db6ee1f 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 749efa199b..e9bb331dd4 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -787,15 +787,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) { @@ -841,17 +844,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 { @@ -909,17 +915,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 { @@ -977,17 +986,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 { @@ -1045,17 +1057,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.22.0