[libvirt] [PATCH 0/2] cgroups v2 fixes

*** BLURB HERE *** Pavel Hrdina (2): vircgroupv2: fix parsing multiple values in single file vircgroupv2: fix virCgroupV2GetCpuCfsQuota for "max" value src/util/vircgroupv2.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) -- 2.21.0

Our virStrToLong* helpers converts string to integers where it wraps strtol standard function. After the conversion happens and there are some remaining invalid characters our helpers will fail if the second argument is NULL. We need to pass pointer to string in cases where there are multiple values in a single file. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1741825 Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/util/vircgroupv2.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index e36c36685b..59ef2e6397 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -673,7 +673,7 @@ virCgroupV2GetBlkioWeight(virCgroupPtr group, tmp = value; } - if (virStrToLong_ui(tmp, NULL, 10, weight) < 0) { + if (virStrToLong_ui(tmp, &tmp, 10, weight) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), tmp); @@ -869,7 +869,7 @@ virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group, if (!str) { *weight = 0; - } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) { + } else if (virStrToLong_ui(str, &str, 10, weight) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); @@ -939,7 +939,7 @@ virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group, if (STREQLEN(tmp, "max", 3)) { *riops = 0; - } else if (virStrToLong_ui(tmp, NULL, 10, riops) < 0) { + } else if (virStrToLong_ui(tmp, &tmp, 10, riops) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); @@ -1010,7 +1010,7 @@ virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group, if (STREQLEN(tmp, "max", 3)) { *wiops = 0; - } else if (virStrToLong_ui(tmp, NULL, 10, wiops) < 0) { + } else if (virStrToLong_ui(tmp, &tmp, 10, wiops) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); @@ -1081,7 +1081,7 @@ virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group, if (STREQLEN(tmp, "max", 3)) { *rbps = 0; - } else if (virStrToLong_ull(tmp, NULL, 10, rbps) < 0) { + } else if (virStrToLong_ull(tmp, &tmp, 10, rbps) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); @@ -1152,7 +1152,7 @@ virCgroupV2GetBlkioDeviceWriteBps(virCgroupPtr group, if (STREQLEN(tmp, "max", 3)) { *wbps = 0; - } else if (virStrToLong_ull(tmp, NULL, 10, wbps) < 0) { + } else if (virStrToLong_ull(tmp, &tmp, 10, wbps) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); @@ -1535,7 +1535,7 @@ virCgroupV2GetCpuCfsPeriod(virCgroupPtr group, return -1; } - if (virStrToLong_ull(tmp, NULL, 10, cfs_period) < 0) { + if (virStrToLong_ull(tmp, &tmp, 10, cfs_period) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to parse value '%s' from cpu.max."), str); return -1; @@ -1585,7 +1585,7 @@ virCgroupV2GetCpuCfsQuota(virCgroupPtr group, if (STREQLEN(str, "max", 3)) *cfs_quota = ULLONG_MAX / 1000; - if (virStrToLong_ll(str, NULL, 10, cfs_quota) < 0) { + if (virStrToLong_ll(str, &str, 10, cfs_quota) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to parse value '%s' from cpu.max."), str); return -1; -- 2.21.0

If the first value in cpu.max is "max" return from function. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1741837 Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/util/vircgroupv2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 59ef2e6397..c62ee0d933 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1582,8 +1582,10 @@ virCgroupV2GetCpuCfsQuota(virCgroupPtr group, return -1; } - if (STREQLEN(str, "max", 3)) + if (STREQLEN(str, "max", 3)) { *cfs_quota = ULLONG_MAX / 1000; + return 0; + } if (virStrToLong_ll(str, &str, 10, cfs_quota) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, -- 2.21.0

On Tue, Aug 20, 2019 at 14:51:21 +0200, Pavel Hrdina wrote:
*** BLURB HERE ***
You too?
Pavel Hrdina (2): vircgroupv2: fix parsing multiple values in single file vircgroupv2: fix virCgroupV2GetCpuCfsQuota for "max" value
src/util/vircgroupv2.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>

On Tue, Aug 20, 2019 at 05:04:59PM +0200, Jiri Denemark wrote:
On Tue, Aug 20, 2019 at 14:51:21 +0200, Pavel Hrdina wrote:
*** BLURB HERE ***
You too?
Just a mistake :).
Pavel Hrdina (2): vircgroupv2: fix parsing multiple values in single file vircgroupv2: fix virCgroupV2GetCpuCfsQuota for "max" value
src/util/vircgroupv2.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Thanks
participants (2)
-
Jiri Denemark
-
Pavel Hrdina