[lxc-devel] [lxcfs/master] sysfs: cpuinfo: show cgroup cpuset value

brauner on Github lxc-bot at linuxcontainers.org
Tue Apr 28 08:57:56 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 414 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200428/88b3a927/attachment.bin>
-------------- next part --------------
From b3c85f5d1af413ffef992b272beb676f95becf19 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 28 Apr 2020 10:35:26 +0200
Subject: [PATCH] sysfs: cpuinfo: show cgroup cpuset value

To stop the immediate bleeding.

Closes #401.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/sysfs_fuse.c | 14 +++++++++-----
 tests/test_proc  |  3 +++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/sysfs_fuse.c b/src/sysfs_fuse.c
index 5bdb2ce..06073c4 100644
--- a/src/sysfs_fuse.c
+++ b/src/sysfs_fuse.c
@@ -96,12 +96,16 @@ static int sys_devices_system_cpu_online_read(char *buf, size_t size,
 	if (use_view)
 		max_cpus = max_cpu_count(cg);
 
-	if (max_cpus == 0)
+	if (use_view) {
+		if (max_cpus > 1)
+			total_len = snprintf(d->buf, d->buflen, "0-%d\n", max_cpus - 1);
+		else
+			total_len = snprintf(d->buf, d->buflen, "0\n");
+	} else if (cpuset) {
+		total_len = snprintf(d->buf, d->buflen, "%s\n", cpuset);
+	} else {
 		return read_file_fuse("/sys/devices/system/cpu/online", buf, size, d);
-	if (max_cpus > 1)
-		total_len = snprintf(d->buf, d->buflen, "0-%d\n", max_cpus - 1);
-	else
-		total_len = snprintf(d->buf, d->buflen, "0\n");
+	}
 	if (total_len < 0 || total_len >= d->buflen)
 		return log_error(0, "Failed to write to cache");
 
diff --git a/tests/test_proc b/tests/test_proc
index fbb38d4..9e16878 100755
--- a/tests/test_proc
+++ b/tests/test_proc
@@ -49,6 +49,9 @@ echo "==> Testing /proc/cpuinfo"
 [ "$(grep "^processor" ${LXCFSDIR}/proc/cpuinfo | wc -l)" = "1" ]
 grep -q "^processor.*0$" ${LXCFSDIR}/proc/cpuinfo || grep -q "^processor 0:.*" ${LXCFSDIR}/proc/cpuinfo
 
+echo "==> Testing /sys/devices/system/cpu/online"
+[ "$(cat ${LXCFSDIR}/sys/devices/system/cpu/online)" = "$(cat ${cpupath}/lxcfs_test_proc/cpuset.cpus)" ]
+
 # Test stat
 echo "==> Testing /proc/stat"
 [ "$(grep "^cpu" ${LXCFSDIR}/proc/stat | wc -l)" = "2" ]


More information about the lxc-devel mailing list