From nobody Fri May 3 06:19:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1541635891767187.57292664849479; Wed, 7 Nov 2018 16:11:31 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 12DC23D968; Thu, 8 Nov 2018 00:11:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A9EE601A1; Thu, 8 Nov 2018 00:11:27 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CD9494BB79; Thu, 8 Nov 2018 00:11:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wA7NviNM011894 for ; Wed, 7 Nov 2018 18:57:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 947056887B; Wed, 7 Nov 2018 23:57:44 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-225.phx2.redhat.com [10.3.116.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39C3968D27; Wed, 7 Nov 2018 23:57:44 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 7 Nov 2018 18:57:39 -0500 Message-Id: <20181107235740.4514-2-jferlan@redhat.com> In-Reply-To: <20181107235740.4514-1-jferlan@redhat.com> References: <20181107235740.4514-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Peter.Chubb@data61.csiro.au Subject: [libvirt] [PATCH 1/2] util: Fix virCgroupGetMemoryStat X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 08 Nov 2018 00:11:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Peter Chubb Commit 901d2b9c introduced virCgroupGetMemoryStat and replaced the LXC virLXCCgroupGetMemStat logic in commit e634c7cd0. However, in doing so the replacement wasn't exact as the LXC logic used getline() to process the cgroup controller data, while the new virCgroupGetMemoryStat used "memory.stat" manual buffer read/ processing which neglected to forward through @line in order to read each line in the output. To fix that, we should be sure to carry forward the @line value for each line read updating it beyond that current @newLine value once we've calculated the values that we want. Signed-off-by: John Ferlan Reviewed-by: Pavel Hrdina --- src/util/vircgroupv1.c | 7 ++++++- src/util/vircgroupv2.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 28a74474ee..678ffda35c 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1476,7 +1476,7 @@ virCgroupV1GetMemoryStat(virCgroupPtr group, =20 line =3D stat; =20 - while (line) { + while (line && *line) { char *newLine =3D strchr(line, '\n'); char *valueStr =3D strchr(line, ' '); unsigned long long value; @@ -1506,6 +1506,11 @@ virCgroupV1GetMemoryStat(virCgroupPtr group, inactiveFileVal =3D value >> 10; else if (STREQ(line, "unevictable")) unevictableVal =3D value >> 10; + + if (newLine) + line =3D newLine + 1; + else + break; } =20 *cache =3D cacheVal; diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 32adb06784..541e8e790e 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1068,7 +1068,7 @@ virCgroupV2GetMemoryStat(virCgroupPtr group, =20 line =3D stat; =20 - while (line) { + while (line && *line) { char *newLine =3D strchr(line, '\n'); char *valueStr =3D strchr(line, ' '); unsigned long long value; @@ -1102,6 +1102,11 @@ virCgroupV2GetMemoryStat(virCgroupPtr group, inactiveFileVal =3D value >> 10; else if (STREQ(line, "unevictable")) unevictableVal =3D value >> 10; + + if (newLine) + line =3D newLine + 1; + else + break; } =20 *cache =3D cacheVal; --=20 2.17.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:19:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1541635945469400.68567148389604; Wed, 7 Nov 2018 16:12:25 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 683CE8046A; Thu, 8 Nov 2018 00:12:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2025060C60; Thu, 8 Nov 2018 00:12:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B9E5B4CAA7; Thu, 8 Nov 2018 00:12:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wA7NvjGG011900 for ; Wed, 7 Nov 2018 18:57:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1EEA168D22; Wed, 7 Nov 2018 23:57:45 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-225.phx2.redhat.com [10.3.116.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1FCF68D28; Wed, 7 Nov 2018 23:57:44 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 7 Nov 2018 18:57:40 -0500 Message-Id: <20181107235740.4514-3-jferlan@redhat.com> In-Reply-To: <20181107235740.4514-1-jferlan@redhat.com> References: <20181107235740.4514-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Peter.Chubb@data61.csiro.au Subject: [libvirt] [PATCH 2/2] tests: Augment vcgrouptest to add virCgroupGetMemoryStat X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 08 Nov 2018 00:12:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Add a test to fetch the GetMemoryStat output. This only gets data for v1 only right now since the v2 data from commit 61ff6021 is rather useless returning all 0's. Signed-off-by: John Ferlan Reviewed-by: Pavel Hrdina --- tests/vircgrouptest.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 310e1fb6a2..06c4a8ef5c 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -802,6 +802,64 @@ static int testCgroupGetMemoryUsage(const void *args A= TTRIBUTE_UNUSED) return ret; } =20 + +static int +testCgroupGetMemoryStat(const void *args ATTRIBUTE_UNUSED) +{ + virCgroupPtr cgroup =3D NULL; + int rv, ret =3D -1; + size_t i; + + const unsigned long long expected_values[] =3D { + 1336619008ULL, + 67100672ULL, + 145887232ULL, + 661872640ULL, + 627400704UL, + 3690496ULL + }; + const char* names[] =3D { + "cache", + "active_anon", + "inactive_anon", + "active_file", + "inactive_file", + "unevictable" + }; + unsigned long long values[ARRAY_CARDINALITY(expected_values)]; + + if ((rv =3D virCgroupNewPartition("/virtualmachines", true, + (1 << VIR_CGROUP_CONTROLLER_MEMORY), + &cgroup)) < 0) { + fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", = -rv); + goto cleanup; + } + + if ((rv =3D virCgroupGetMemoryStat(cgroup, &values[0], + &values[1], &values[2], + &values[3], &values[4], + &values[5])) < 0) { + fprintf(stderr, "Could not retrieve GetMemoryStat for /virtualmach= ines cgroup: %d\n", -rv); + goto cleanup; + } + + for (i =3D 0; i < ARRAY_CARDINALITY(expected_values); i++) { + if (expected_values[i] !=3D (values[i] << 10)) { + fprintf(stderr, + "Wrong value (%llu) for %s from virCgroupGetMemoryStat= (expected %llu)\n", + values[i], names[i], expected_values[i]); + goto cleanup; + } + } + + ret =3D 0; + + cleanup: + virCgroupFree(&cgroup); + return ret; +} + + static int testCgroupGetBlkioIoServiced(const void *args ATTRIBUTE_UNUSED) { virCgroupPtr cgroup =3D NULL; @@ -1035,6 +1093,9 @@ mymain(void) if (virTestRun("virCgroupGetMemoryUsage works", testCgroupGetMemoryUsa= ge, NULL) < 0) ret =3D -1; =20 + if (virTestRun("virCgroupGetMemoryStat works", testCgroupGetMemoryStat= , NULL) < 0) + ret =3D -1; + if (virTestRun("virCgroupGetPercpuStats works", testCgroupGetPercpuSta= ts, NULL) < 0) ret =3D -1; cleanupFakeFS(fakerootdir); --=20 2.17.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list