[lxc-devel] [lxcfs/master] bugfixes

brauner on Github lxc-bot at linuxcontainers.org
Thu Mar 5 08:36:55 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 365 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200305/d273a553/attachment.bin>
-------------- next part --------------
From 84d6e376aad3c09a73bd94cf82f2b951f25924f2 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 5 Mar 2020 09:28:14 +0100
Subject: [PATCH 1/5] proc_fuse: remove stray logging

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/proc_fuse.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index 7cb95f8..9b931ec 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -760,7 +760,6 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
 	}
 
 	pid_t initpid = lookup_initpid_in_store(fc->pid);
-	lxcfs_v("initpid: %d\n", initpid);
 	if (initpid <= 0)
 		initpid = fc->pid;
 

From 605e157d68ef3e09ec26563c8ce7d6eeef59480b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 5 Mar 2020 09:30:29 +0100
Subject: [PATCH 2/5] proc_fuse: remove {} from single-ling if-statement

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/proc_fuse.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index 9b931ec..d8526fc 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -768,9 +768,8 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
 	 * we should return host os's /proc contents.
 	 * in some case cpuacct_usage.all in "/" will larger then /proc/stat
 	 */
-	if (initpid == 1) {
+	if (initpid == 1)
 	    return read_file_fuse("/proc/stat", buf, size, d);
-	}
 
 	cg = get_pid_cgroup(initpid, "cpuset");
 	lxcfs_v("cg: %s\n", cg);

From dd2026647c63e4b92037dfd33b65ed80425586f7 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 5 Mar 2020 09:31:08 +0100
Subject: [PATCH 3/5] proc_fuse: remove stray logging

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/proc_fuse.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index d8526fc..b1495ec 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -772,7 +772,6 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
 	    return read_file_fuse("/proc/stat", buf, size, d);
 
 	cg = get_pid_cgroup(initpid, "cpuset");
-	lxcfs_v("cg: %s\n", cg);
 	if (!cg)
 		return read_file_fuse("/proc/stat", buf, size, d);
 	prune_init_slice(cg);

From 7b3674807fe82b07a2c188e790a3f015f92c2f3c Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 5 Mar 2020 09:31:46 +0100
Subject: [PATCH 4/5] proc_fuse: coding style

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/proc_fuse.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index b1495ec..f8a5369 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -748,14 +748,19 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
 	size_t cache_size = d->buflen - CPUALL_MAX_SIZE;
 	int cg_cpu_usage_size = 0;
 
-	if (offset){
+	if (offset) {
+		int left;
+
 		if (offset > d->size)
 			return -EINVAL;
+
 		if (!d->cached)
 			return 0;
-		int left = d->size - offset;
-		total_len = left > size ? size: left;
+
+		left = d->size - offset;
+		total_len = left > size ? size : left;
 		memcpy(buf, d->buf + offset, total_len);
+
 		return total_len;
 	}
 

From a9f0d6235ee56cc20f80f561cdd2304f67427c18 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 5 Mar 2020 09:35:47 +0100
Subject: [PATCH 5/5] tree-wide: handle shared pid namespaces

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

diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index f8a5369..392d10d 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -273,6 +273,7 @@ static int proc_swaps_read(char *buf, size_t size, off_t offset,
 	pid_t initpid = lookup_initpid_in_store(fc->pid);
 	if (initpid <= 1 || is_shared_pidns(initpid))
 		initpid = fc->pid;
+
 	cg = get_pid_cgroup(initpid, "memory");
 	if (!cg)
 		return read_file_fuse("/proc/swaps", buf, size, d);
@@ -405,6 +406,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
 	pid_t initpid = lookup_initpid_in_store(fc->pid);
 	if (initpid <= 1 || is_shared_pidns(initpid))
 		initpid = fc->pid;
+
 	cg = get_pid_cgroup(initpid, "blkio");
 	if (!cg)
 		return read_file_fuse("/proc/diskstats", buf, size, d);
@@ -765,7 +767,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
 	}
 
 	pid_t initpid = lookup_initpid_in_store(fc->pid);
-	if (initpid <= 0)
+	if (initpid <= 1 || is_shared_pidns(initpid))
 		initpid = fc->pid;
 
 	/*
diff --git a/src/sysfs_fuse.c b/src/sysfs_fuse.c
index 988cc03..94f6565 100644
--- a/src/sysfs_fuse.c
+++ b/src/sysfs_fuse.c
@@ -76,8 +76,9 @@ static int sys_devices_system_cpu_online_read(char *buf, size_t size,
 	}
 
 	initpid = lookup_initpid_in_store(fc->pid);
-	if (initpid <= 0)
+	if (initpid <= 1 || is_shared_pidns(initpid))
 		initpid = fc->pid;
+
 	cg = get_pid_cgroup(initpid, "cpuset");
 	if (!cg)
 		return read_file_fuse("/sys/devices/system/cpu/online", buf, size, d);


More information about the lxc-devel mailing list