aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2024-05-08 14:58:27 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2024-05-08 14:00:39 +0000
commit1b2d32887a8dbb6a119f5c5d9078d60346bdffa7 (patch)
tree72789cd48136163a8bd3c2198689d8df29a37966
parentc9c8a52399428c96f35eb4a06decc510ef5c1789 (diff)
main/lxc: add fix for lxc-top with cgroup2HEADmaster
ref: https://gitlab.alpinelinux.org/alpine/aports/-/issues/15607 upstream: https://github.com/lxc/lxc/pull/4439
-rw-r--r--main/lxc/APKBUILD4
-rw-r--r--main/lxc/lxc-top-cgroupv2.patch118
2 files changed, 121 insertions, 1 deletions
diff --git a/main/lxc/APKBUILD b/main/lxc/APKBUILD
index 51ed3d44399..ccf884cf9c7 100644
--- a/main/lxc/APKBUILD
+++ b/main/lxc/APKBUILD
@@ -4,7 +4,7 @@
pkgname=lxc
pkgver=6.0.0
_pkgver=${pkgver/_rc/.rc}
-pkgrel=2
+pkgrel=3
pkgdesc="Userspace interface for the Linux kernel containment features"
url="https://linuxcontainers.org/lxc/"
arch="all"
@@ -37,6 +37,7 @@ subpackages="
$pkgname-user-nic:_user_nic
"
source="https://linuxcontainers.org/downloads/lxc/lxc-$_pkgver.tar.gz
+ lxc-top-cgroupv2.patch
lxc.initd
lxc.confd
"
@@ -175,6 +176,7 @@ _user_nic() {
sha512sums="
acff2fc70cf2c65af37b70a21239482c3d845c408f7132558b54980e4400c23670c63178a3a3dfb239f047f529004df93cd829d728852a8c8647ce6babf7857f lxc-6.0.0.tar.gz
+e7b7a443a71804f21e6225bed98310ccf2cad1a5bc2b9ad397e7d79fcfab6216e10ce02e249fbc0e6df2cfbe13e03320d9690db502027ae008a6f48218b81d17 lxc-top-cgroupv2.patch
db71783366277a68a5c8116604cf845da4780fe4aebdb5820ae2c4fe028cfe52a9c94246db362476f2f195be6a9c2b835edbe521423f116fc66eb50023d6daab lxc.initd
91de43db5369a9e10102933514d674e9c875218a1ff2910dd882e5b9c308f9e430deacb13d1d7e0b2ed1ef682d0bb035aa6f8a6738f54fa2ca3a05acce04e467 lxc.confd
"
diff --git a/main/lxc/lxc-top-cgroupv2.patch b/main/lxc/lxc-top-cgroupv2.patch
new file mode 100644
index 00000000000..a88b8546bd0
--- /dev/null
+++ b/main/lxc/lxc-top-cgroupv2.patch
@@ -0,0 +1,118 @@
+From ba823cc3cd2ea8b7eef714c317a212a9d7b5afe0 Mon Sep 17 00:00:00 2001
+From: Anoop Rachakonda <anooprac@utexas.edu>
+Date: Wed, 1 May 2024 13:56:30 -0500
+Subject: [PATCH] stats_get: Changed paths to be aligned with cgroup2
+ specifications
+
+Closes #4376
+
+Signed-off-by: Devon Schwartz <devon.s.schwartz@utexas.edu>
+---
+ src/lxc/tools/lxc_top.c | 64 ++++++++++++++++++++++++++++++++---------
+ 1 file changed, 51 insertions(+), 13 deletions(-)
+
+diff --git a/src/lxc/tools/lxc_top.c b/src/lxc/tools/lxc_top.c
+index aa6e7209e3..f27025f730 100644
+--- a/src/lxc/tools/lxc_top.c
++++ b/src/lxc/tools/lxc_top.c
+@@ -276,27 +276,33 @@ static uint64_t stat_match_get_int(struct lxc_container *c, const char *item,
+ Total 149327872
+ */
+ static void stat_get_blk_stats(struct lxc_container *c, const char *item,
+- struct blkio_stats *stats) {
++ struct blkio_stats *stats, bool *success) {
+ char buf[4096];
+ int i, len;
+ char **lines, **cols;
++ *success = true;
+
+ len = c->get_cgroup_item(c, item, buf, sizeof(buf));
+ if (len <= 0 || (size_t)len >= sizeof(buf)) {
+ fprintf(stderr, "Unable to read cgroup item %s\n", item);
++ *success = false;
+ return;
+ }
+
+ lines = lxc_string_split_and_trim(buf, '\n');
+- if (!lines)
++ if (!lines) {
++ *success = false;
+ return;
++ }
+
+ memset(stats, 0, sizeof(struct blkio_stats));
+
+ for (i = 0; lines[i]; i++) {
+ cols = lxc_string_split_and_trim(lines[i], ' ');
+- if (!cols)
++ if (!cols) {
++ *success = false;
+ goto out;
++ }
+
+ if (strncmp(cols[1], "Read", strlen(cols[1])) == 0)
+ stats->read += strtoull(cols[2], NULL, 0);
+@@ -314,21 +320,53 @@ static void stat_get_blk_stats(struct lxc_container *c, const char *item,
+ return;
+ }
+
++static void try_cgroup2(struct lxc_container *c, u_int64_t *stat, const char* path_cgroup1, const char* path_cgroup2,
++ const char* match, bool call_match) {
++
++ int ret_cgroup2;
++
++ if (call_match) {
++ ret_cgroup2 = stat_match_get_int(c, path_cgroup2, match, 1);
++ if (ret_cgroup2 < 0) {
++ *stat = stat_match_get_int(c, path_cgroup1, match, 1);
++ }
++
++ } else {
++ ret_cgroup2 = stat_get_int(c, path_cgroup2);
++
++ if (ret_cgroup2 < 0) {
++ *stat = stat_get_int(c, path_cgroup1);
++ } else {
++ *stat = ret_cgroup2;
++ }
++ }
++}
++
++
+ static void stats_get(struct lxc_container *c, struct container_stats *ct, struct stats *total)
+ {
+ ct->c = c;
+- ct->stats->mem_used = stat_get_int(c, "memory.usage_in_bytes");
+- ct->stats->mem_limit = stat_get_int(c, "memory.limit_in_bytes");
+- ct->stats->memsw_used = stat_get_int(c, "memory.memsw.usage_in_bytes");
+- ct->stats->memsw_limit = stat_get_int(c, "memory.memsw.limit_in_bytes");
++
++ // handle stat_get_int cases
++ try_cgroup2(c, &(ct->stats->mem_used), "memory.usage_in_bytes", "memory.current", NULL, false);
++ try_cgroup2(c, &(ct->stats->mem_limit), "memory.limit_in_bytes", "memory.max", NULL, false);
++ try_cgroup2(c, &(ct->stats->memsw_used), "memory.memsw.usage_in_bytes", "memory.swap.current", NULL, false);
++ try_cgroup2(c, &(ct->stats->memsw_limit), "memory.memsw.limit_in_bytes", "memory.swap.max", NULL, false);
++ try_cgroup2(c, &(ct->stats->cpu_use_nanos), "cpuacct.usage", "cpu.stat", NULL, false);
++ try_cgroup2(c, &(ct->stats->cpu_use_user), "cpuacct.stat", "cpu.stat", "user", true);
++ try_cgroup2(c, &(ct->stats->cpu_use_sys), "cpuacct.stat", "cpu.stat", "system", true);
++
++ // singular cgroup2 case for get blk stats
++ bool success;
++ stat_get_blk_stats(c, "io.stat", &ct->stats->io_service_bytes, &success);
++ if (!success) {
++ stat_get_blk_stats(c, "blkio.throttle.io_service_bytes", &ct->stats->io_service_bytes, &success);
++ }
++
++ // paths only exist in cgroup1
+ ct->stats->kmem_used = stat_get_int(c, "memory.kmem.usage_in_bytes");
+ ct->stats->kmem_limit = stat_get_int(c, "memory.kmem.limit_in_bytes");
+- ct->stats->cpu_use_nanos = stat_get_int(c, "cpuacct.usage");
+- ct->stats->cpu_use_user = stat_match_get_int(c, "cpuacct.stat", "user", 1);
+- ct->stats->cpu_use_sys = stat_match_get_int(c, "cpuacct.stat", "system", 1);
+-
+- stat_get_blk_stats(c, "blkio.throttle.io_service_bytes", &ct->stats->io_service_bytes);
+- stat_get_blk_stats(c, "blkio.throttle.io_serviced", &ct->stats->io_serviced);
++ stat_get_blk_stats(c, "blkio.throttle.io_serviced", &ct->stats->io_serviced, &success);
+
+ if (total) {
+ total->mem_used = total->mem_used + ct->stats->mem_used;