lxcfs: upgrade to 5.0.3

Signed-off-by: vegbir <yangjiaqi16@huawei.com>
This commit is contained in:
vegbir 2023-07-14 03:16:39 +00:00
parent 2728fd1e33
commit 009a8a78f7
28 changed files with 461 additions and 772 deletions

View File

@ -1,28 +1,31 @@
From fdc8835afc38ba10f2d1ef97d19a631e58552a27 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 11:03:32 +0800
Subject: [PATCH 01/17] systemd
From 04c55841409a238f8b12c15395006c5793b4a508 Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Tue, 11 Jul 2023 08:41:53 +0000
Subject: [PATCH 01/16] systemd
append:remove-lxcfs-tools-dependency-for-common-use
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
config/init/systemd/lxcfs.service.in | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/config/init/systemd/lxcfs.service.in b/config/init/systemd/lxcfs.service.in
index 9cd4e59..3d763c6 100644
index 8b43f5a..bae1d08 100644
--- a/config/init/systemd/lxcfs.service.in
+++ b/config/init/systemd/lxcfs.service.in
@@ -5,12 +5,16 @@ Before=lxc.service
Documentation=man:lxcfs(1)
@@ -6,12 +6,16 @@ Documentation=man:lxcfs(1)
[Service]
-ExecStart=/usr/bin/lxcfs @LXCFSTARGETDIR@
+ExecStartPre=/usr/local/bin/lxcfs-tools prestart
OOMScoreAdjust=-1000
-ExecStart=/usr/bin/lxcfs {{LXCFSTARGETDIR}}
+ExecStartPre=-/usr/local/bin/lxcfs-tools prestart
+ExecStart=/usr/bin/lxcfs /var/lib/lxc/lxcfs/
+ExecStartPost=/usr/local/bin/lxcfs-tools remount -a
+ExecStartPost=-/usr/local/bin/lxcfs-tools remount -a
KillMode=process
-Restart=on-failure
-ExecStopPost=-/bin/fusermount -u @LXCFSTARGETDIR@
+ExecStop=/usr/local/bin/lxcfs-tools umount -a
-ExecStopPost=-/bin/fusermount -u {{LXCFSTARGETDIR}}
+ExecStop=-/usr/local/bin/lxcfs-tools umount -a
+ExecStopPost=-/bin/fusermount -u /var/lib/lxc/
Delegate=yes
ExecReload=/bin/kill -USR1 $MAINPID
@ -32,5 +35,5 @@ index 9cd4e59..3d763c6 100644
[Install]
WantedBy=multi-user.target
--
2.27.0
2.41.0

View File

@ -1,33 +0,0 @@
From 246b0b52ad671fc37a2bc289701260e5128ecd1f Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 11:11:05 +0800
Subject: [PATCH 02/17] remove-sysvinit-upstart
---
config/init/Makefile.am | 2 +-
configure.ac | 2 --
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/config/init/Makefile.am b/config/init/Makefile.am
index e2ffe28..3439c97 100644
--- a/config/init/Makefile.am
+++ b/config/init/Makefile.am
@@ -1 +1 @@
-SUBDIRS = systemd sysvinit upstart
+SUBDIRS = systemd
diff --git a/configure.ac b/configure.ac
index ccea4ec..d15ac50 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,8 +45,6 @@ AC_CONFIG_FILES([
config/init/Makefile
config/init/systemd/Makefile
config/init/systemd/lxcfs.service
- config/init/sysvinit/Makefile
- config/init/upstart/Makefile
doc/Makefile
--
2.27.0

View File

@ -1,17 +1,25 @@
From d6234626d7240952da42902b7ef513d56d5a18a7 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 11:32:37 +0800
Subject: [PATCH 03/17] show-dev-name-in-container
From a6346a7a51385ee588a624775a91ce7ac3fb4dd3 Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Tue, 11 Jul 2023 09:18:09 +0000
Subject: [PATCH 02/16] show dev name in container
append: fix hang
append: limit-stat-by-quota-period-setting
append: fix-proc-diskstats-show-in-container
append: proc_fuse fix wait child process hang
append: fix deadlock problem when subprocess exit
append: fix dev read memory leak in container
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
src/proc_fuse.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 143 insertions(+), 2 deletions(-)
src/proc_fuse.c | 183 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 181 insertions(+), 2 deletions(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index 94168c9..7372a36 100644
index 23e0b43..4503373 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -27,6 +27,7 @@
@@ -28,6 +28,7 @@
#include <sys/socket.h>
#include <sys/syscall.h>
#include <sys/sysinfo.h>
@ -19,13 +27,40 @@ index 94168c9..7372a36 100644
#include <sys/vfs.h>
#include "proc_fuse.h"
@@ -448,6 +449,132 @@ static void get_blkio_io_value(char *str, unsigned major, unsigned minor,
@@ -43,6 +44,26 @@
#include "proc_cpuview.h"
#include "utils.h"
+static pthread_mutex_t container_dev_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static void lock_mutex(pthread_mutex_t *l)
+{
+ int ret;
+
+ ret = pthread_mutex_lock(l);
+ if (ret)
+ log_exit("%s - returned %d\n", strerror(ret), ret);
+}
+
+static void unlock_mutex(pthread_mutex_t *l)
+{
+ int ret;
+
+ ret = pthread_mutex_unlock(l);
+ if (ret)
+ log_exit("%s - returned %d\n", strerror(ret), ret);
+}
+
struct memory_stat {
uint64_t hierarchical_memory_limit;
uint64_t hierarchical_memsw_limit;
@@ -473,6 +494,146 @@ static void get_blkio_io_value(char *str, unsigned major, unsigned minor,
}
}
+struct devinfo {
+ char *name;
+ int major, minor;
+ unsigned int major, minor;
+ struct devinfo *next;
+};
+
@ -43,7 +78,7 @@ index 94168c9..7372a36 100644
+ struct dirent *ptr;
+ struct stat dev_stat;
+ struct devinfo *head = NULL, *end;
+ char fpath[100], dev_name[100];
+ char fpath[261], dev_name[256];
+ pid_t child_pid;
+ int mypipe[2];
+ int dev_num;
@ -62,6 +97,16 @@ index 94168c9..7372a36 100644
+ return head;
+ }
+ if (child_pid == 0) {
+ /* Disallow signal reception in child process */
+ sigset_t oldset;
+ sigset_t newset;
+ sigemptyset(&newset);
+ sigaddset(&newset, SIGTERM);
+ sigaddset(&newset, SIGINT);
+ sigaddset(&newset, SIGHUP);
+ sigaddset(&newset, SIGQUIT);
+ sigprocmask(SIG_BLOCK,&newset,&oldset);
+
+ close(mypipe[0]);
+ stream = fdopen(mypipe[1], "w");
+ if (stream == NULL) {
@ -87,28 +132,31 @@ index 94168c9..7372a36 100644
+ continue;
+ }
+ memset(fpath, 0, sizeof(fpath));
+ snprintf(fpath, 99, "/dev/%s", ptr->d_name);
+ snprintf(fpath, 261, "/dev/%s", ptr->d_name);
+ stat(fpath, &dev_stat);
+ fprintf(stream, "%s %d ", ptr->d_name, dev_stat.st_rdev);
+ fprintf(stream, "%s %ld ", ptr->d_name, dev_stat.st_rdev);
+ fflush(stream);
+ }
+ closedir(dir);
+ stat("/", &dev_stat);
+ dev_num = dev_stat.st_dev & (~0xf);
+ dev_num = dev_stat.st_dev;
+ fprintf(stream, "sda %d end 0 ", dev_num);
+ fflush(stream);
+child_out:
+ fclose(stream);
+ exit(0);
+ _exit(EXIT_SUCCESS);
+ }
+
+child_out:
+ close(mypipe[1]);
+ stream = fdopen(mypipe[0], "r");
+ if (stream == NULL) {
+ lxcfs_error("Error opening pipe for reading: %s\n", strerror(errno));
+ goto err;
+ }
+ while (fscanf(stream, "%100s%d", dev_name, &dev_num) == 2) {
+ wait_for_pid(child_pid);
+ child_pid = 0;
+ memset(dev_name, 0, sizeof(dev_name));
+ while (fscanf(stream, "%255s%d", dev_name, &dev_num) == 2) {
+ if (dev_num == 0) {
+ break;
+ }
@ -127,6 +175,7 @@ index 94168c9..7372a36 100644
+ end->name = must_copy_string(dev_name);
+ end->major = major(dev_num);
+ end->minor = minor(dev_num);
+ memset(dev_name, 0, sizeof(dev_name));
+ }
+err:
+ if (stream)
@ -152,7 +201,7 @@ index 94168c9..7372a36 100644
struct lxcfs_diskstats {
unsigned int major; /* 1 - major number */
unsigned int minor; /* 2 - minor mumber */
@@ -480,6 +607,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -505,6 +666,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
__do_fclose FILE *f = NULL;
struct fuse_context *fc = fuse_get_context();
struct file_info *d = INTTYPE_TO_PTR(fi->fh);
@ -160,11 +209,13 @@ index 94168c9..7372a36 100644
struct lxcfs_diskstats stats = {};
/* helper fields */
uint64_t read_service_time, write_service_time, discard_service_time, read_wait_time,
@@ -549,13 +677,22 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -574,14 +736,26 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
if (!f)
return 0;
+ lock_mutex(&container_dev_mutex);
+ container_devinfo = container_dev_read(initpid);
+ unlock_mutex(&container_dev_mutex);
+
while (getline(&line, &linelen, f) != -1) {
ssize_t l;
@ -174,16 +225,18 @@ index 94168c9..7372a36 100644
i = sscanf(line, "%u %u %71s", &stats.major, &stats.minor, stats.dev_name);
if (i != 3)
continue;
+ for (ptr = container_devinfo; ptr != NULL; ptr = ptr->next) {
+ if (stats.major == ptr->major && stats.minor == ptr->minor) {
+ snprintf(stats.dev_name, sizeof(stats.dev_name), "%s", ptr->name);
+ stats.dev_name[71] = '\0';
+ }
+ }
+
get_blkio_io_value(io_serviced_str, stats.major, stats.minor, "Read", &stats.read);
get_blkio_io_value(io_serviced_str, stats.major, stats.minor, "Write", &stats.write);
@@ -620,10 +757,14 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
get_blkio_io_value(io_serviced_str, stats.major, stats.minor, "Discard", &stats.discard);
@@ -664,10 +838,14 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
continue;
l = snprintf(cache, cache_size, "%s", lbuf);
@ -200,6 +253,14 @@ index 94168c9..7372a36 100644
cache += l;
cache_size -= l;
@@ -679,6 +857,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
if (total_len > size)
total_len = size;
memcpy(buf, d->buf, total_len);
+ free_devinfo_list(container_devinfo);
return total_len;
}
--
2.27.0
2.41.0

View File

@ -1,17 +1,18 @@
From 1901edf2908551cf862f3deabf23acbda55d2dea Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 11:52:05 +0800
Subject: [PATCH 04/17] lxcfs-fix-cpuinfo-print
From 2a7730cfc9d7ca747b6ff4c99a1fc6508f667b27 Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Tue, 11 Jul 2023 09:26:08 +0000
Subject: [PATCH 03/16] lxcfs fix cpuinfo print
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
src/proc_cpuview.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/proc_cpuview.c b/src/proc_cpuview.c
index 9f6a55e..75006a6 100644
index 89f3666..0cf37eb 100644
--- a/src/proc_cpuview.c
+++ b/src/proc_cpuview.c
@@ -970,7 +970,17 @@ int proc_cpuinfo_read(char *buf, size_t size, off_t offset,
@@ -1048,7 +1048,17 @@ int proc_cpuinfo_read(char *buf, size_t size, off_t offset,
}
if (am_printing) {
@ -31,5 +32,5 @@ index 9f6a55e..75006a6 100644
return log_error(0, "Failed to write cache");
if ((size_t)l >= cache_size)
--
2.27.0
2.41.0

View File

@ -1,17 +1,18 @@
From a4f9b85c4ed1cc5128bcb6650cc8989310558769 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 12:06:31 +0800
Subject: [PATCH 05/17] fix-memory-leak
From b2c83183e7ace5049bab265ec3084335165ff570 Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Wed, 12 Jul 2023 07:07:16 +0000
Subject: [PATCH 04/16] fix memory leak
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
src/proc_fuse.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index 7372a36..bcd624d 100644
index 4503373..c615e8e 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -278,6 +278,8 @@ static uint64_t get_min_memlimit(const char *cgroup, bool swap)
@@ -304,6 +304,8 @@ static uint64_t get_min_memlimit(const char *cgroup, bool swap)
return log_error_errno(0, ENOMEM, "Failed to allocate memory");
retlimit = get_memlimit(copy, swap);
@ -20,7 +21,7 @@ index 7372a36..bcd624d 100644
/*
* If the cgroup doesn't start with / (probably won't happen), dirname()
@@ -346,6 +348,8 @@ static int proc_swaps_read(char *buf, size_t size, off_t offset,
@@ -409,6 +411,8 @@ static int proc_swaps_read(char *buf, size_t size, off_t offset,
prune_init_slice(cgroup);
memlimit = get_min_memlimit(cgroup, false);
@ -29,7 +30,7 @@ index 7372a36..bcd624d 100644
ret = cgroup_ops->get_memory_current(cgroup_ops, cgroup, &memusage_str);
if (ret < 0)
@@ -1329,6 +1333,8 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
@@ -1442,6 +1446,8 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
return read_file_fuse("/proc/meminfo", buf, size, d);
memlimit = get_min_memlimit(cgroup, false);
@ -38,7 +39,7 @@ index 7372a36..bcd624d 100644
/*
* Following values are allowed to fail, because swapaccount might be
@@ -1361,9 +1367,9 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
@@ -1456,9 +1462,9 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
memusage /= 1024;
memlimit /= 1024;
@ -50,5 +51,5 @@ index 7372a36..bcd624d 100644
memset(lbuf, 0, 100);
if (startswith(line, "MemTotal:")) {
--
2.27.0
2.41.0

View File

@ -1,8 +1,9 @@
From 90fc9cd959bc6231eb3ddad5c74865d35e9f372d Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 14:12:57 +0800
Subject: [PATCH 06/17] fix-concurrency-problem
From fb10b60dd72ba36752978c0740b66b572ded4feb Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Wed, 12 Jul 2023 07:19:20 +0000
Subject: [PATCH 05/16] fix concurrency problem
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
src/cgroups/cgroup_utils.c | 21 +++++++++++++--------
src/cgroups/cgroup_utils.h | 2 +-
@ -80,10 +81,10 @@ index f431686..d4c8598 100644
extern char *readat_file(int fd, const char *path);
extern char *read_file_strip_newline(const char *fnam);
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index bcd624d..0aaab71 100644
index c615e8e..80db328 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -1530,6 +1530,9 @@ __lxcfs_fuse_ops int proc_read(const char *path, char *buf, size_t size,
@@ -1736,6 +1736,9 @@ __lxcfs_fuse_ops int proc_read(const char *path, char *buf, size_t size,
{
struct file_info *f = INTTYPE_TO_PTR(fi->fh);
@ -94,5 +95,5 @@ index bcd624d..0aaab71 100644
case LXC_TYPE_PROC_MEMINFO:
if (liblxcfs_functional())
--
2.27.0
2.41.0

View File

@ -1,19 +1,20 @@
From 7691f5c4a87d5fbc0f48fa96bba70b4ab9b52c65 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 14:45:12 +0800
Subject: [PATCH 07/17] set-null-after-free
From 615f5343cd8180308fa4b1a42faf17686c9f7651 Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Wed, 12 Jul 2023 07:48:40 +0000
Subject: [PATCH 06/16] set null after free
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
src/cgroup_fuse.c | 26 +++++++++++++++++++++-----
src/cgroup_fuse.c | 27 ++++++++++++++++++++++-----
src/cgroups/cgfsng.c | 5 ++++-
src/cgroups/cgroup_utils.c | 4 +++-
src/lxcfs.c | 4 ++++
src/memory_utils.h | 4 +++-
src/proc_loadavg.c | 5 ++++-
6 files changed, 39 insertions(+), 9 deletions(-)
6 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/src/cgroup_fuse.c b/src/cgroup_fuse.c
index 5c22fd1..b396bbc 100644
index 693b67d..0d4dd10 100644
--- a/src/cgroup_fuse.c
+++ b/src/cgroup_fuse.c
@@ -179,7 +179,7 @@ static bool is_child_cgroup(const char *controller, const char *cgroup,
@ -52,7 +53,7 @@ index 5c22fd1..b396bbc 100644
return answer;
}
@@ -612,6 +614,7 @@ __lxcfs_fuse_ops int cg_getattr(const char *path, struct stat *sb)
@@ -613,6 +615,7 @@ __lxcfs_fuse_ops int cg_getattr(const char *path, struct stat *sb)
out:
free(cgdir);
@ -60,7 +61,7 @@ index 5c22fd1..b396bbc 100644
return ret;
}
@@ -734,7 +737,9 @@ __lxcfs_fuse_ops int cg_mkdir(const char *path, mode_t mode)
@@ -735,7 +738,9 @@ __lxcfs_fuse_ops int cg_mkdir(const char *path, mode_t mode)
out:
free(cgdir);
@ -70,7 +71,7 @@ index 5c22fd1..b396bbc 100644
return ret;
}
@@ -869,7 +874,9 @@ __lxcfs_fuse_ops int cg_rmdir(const char *path)
@@ -870,7 +875,9 @@ __lxcfs_fuse_ops int cg_rmdir(const char *path)
out:
free(cgdir);
@ -80,7 +81,7 @@ index 5c22fd1..b396bbc 100644
return ret;
}
@@ -958,6 +965,7 @@ __lxcfs_fuse_ops int cg_chmod(const char *path, mode_t mode)
@@ -959,6 +966,7 @@ __lxcfs_fuse_ops int cg_chmod(const char *path, mode_t mode)
out:
free_key(k);
free(cgdir);
@ -88,7 +89,7 @@ index 5c22fd1..b396bbc 100644
return ret;
}
@@ -1067,7 +1075,7 @@ __lxcfs_fuse_ops int cg_chown(const char *path, uid_t uid, gid_t gid)
@@ -1068,7 +1076,7 @@ __lxcfs_fuse_ops int cg_chown(const char *path, uid_t uid, gid_t gid)
out:
free_key(k);
free(cgdir);
@ -97,7 +98,7 @@ index 5c22fd1..b396bbc 100644
return ret;
}
@@ -1139,6 +1147,7 @@ __lxcfs_fuse_ops int cg_open(const char *path, struct fuse_file_info *fi)
@@ -1140,6 +1148,7 @@ __lxcfs_fuse_ops int cg_open(const char *path, struct fuse_file_info *fi)
out:
free(cgdir);
@ -105,7 +106,7 @@ index 5c22fd1..b396bbc 100644
return ret;
}
@@ -1280,6 +1289,7 @@ static bool do_read_pids(pid_t tpid, const char *contrl, const char *cg,
@@ -1281,6 +1290,7 @@ static bool do_read_pids(pid_t tpid, const char *contrl, const char *cg,
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sock) < 0) {
perror("socketpair");
free(tmpdata);
@ -113,7 +114,7 @@ index 5c22fd1..b396bbc 100644
return false;
}
@@ -1331,6 +1341,7 @@ next:
@@ -1332,6 +1342,7 @@ next:
out:
free(tmpdata);
@ -121,7 +122,7 @@ index 5c22fd1..b396bbc 100644
if (cpid != -1)
wait_for_pid(cpid);
if (sock[0] != -1) {
@@ -1408,6 +1419,7 @@ __lxcfs_fuse_ops int cg_read(const char *path, char *buf, size_t size,
@@ -1409,6 +1420,7 @@ __lxcfs_fuse_ops int cg_read(const char *path, char *buf, size_t size,
out:
free(data);
@ -129,15 +130,15 @@ index 5c22fd1..b396bbc 100644
return ret;
}
@@ -1989,6 +2001,7 @@ __lxcfs_fuse_ops int cg_readdir(const char *path, void *buf,
@@ -1995,6 +2007,7 @@ __lxcfs_fuse_ops int cg_readdir(const char *path, void *buf,
if (nextcg) {
ret = DIR_FILLER(filler, buf, nextcg, NULL, 0);
ret = dir_filler(filler, buf, nextcg, 0);
free(nextcg);
+ nextcg = NULL;
if (ret != 0) {
ret = -EIO;
goto out;
@@ -2024,8 +2037,10 @@ __lxcfs_fuse_ops int cg_readdir(const char *path, void *buf,
@@ -2030,9 +2043,12 @@ __lxcfs_fuse_ops int cg_readdir(const char *path, void *buf,
out:
free_keys(list);
if (clist) {
@ -147,9 +148,11 @@ index 5c22fd1..b396bbc 100644
+ clist[i] = NULL;
+ }
free(clist);
+ clist = NULL;
}
return ret;
@@ -2095,5 +2110,6 @@ __lxcfs_fuse_ops int cg_access(const char *path, int mode)
}
@@ -2101,5 +2117,6 @@ __lxcfs_fuse_ops int cg_access(const char *path, int mode)
out:
free(cgdir);
@ -157,10 +160,10 @@ index 5c22fd1..b396bbc 100644
return ret;
}
diff --git a/src/cgroups/cgfsng.c b/src/cgroups/cgfsng.c
index 3eb4227..781923c 100644
index 72a4503..e2d9807 100644
--- a/src/cgroups/cgfsng.c
+++ b/src/cgroups/cgfsng.c
@@ -875,7 +875,7 @@ static int cg_hybrid_init(struct cgroup_ops *ops)
@@ -891,7 +891,7 @@ static int cg_hybrid_init(struct cgroup_ops *ops)
prune_init_scope(base_cgroup);
if (type == CGROUP2_SUPER_MAGIC) {
@ -169,7 +172,7 @@ index 3eb4227..781923c 100644
cgv2_ctrl_path = must_make_path(mountpoint, base_cgroup,
"cgroup.controllers",
@@ -883,6 +883,7 @@ static int cg_hybrid_init(struct cgroup_ops *ops)
@@ -899,6 +899,7 @@ static int cg_hybrid_init(struct cgroup_ops *ops)
controller_list = cg_unified_get_controllers(cgv2_ctrl_path);
free(cgv2_ctrl_path);
@ -177,7 +180,7 @@ index 3eb4227..781923c 100644
if (!controller_list)
controller_list = cg_unified_make_empty_controller();
}
@@ -897,7 +898,9 @@ static int cg_hybrid_init(struct cgroup_ops *ops)
@@ -913,7 +914,9 @@ static int cg_hybrid_init(struct cgroup_ops *ops)
next:
free_string_list(controller_list);
free(mountpoint);
@ -213,10 +216,10 @@ index 1224971..d32a520 100644
return true;
diff --git a/src/lxcfs.c b/src/lxcfs.c
index e24ebed..361ce71 100644
index 92ed991..e9155ca 100644
--- a/src/lxcfs.c
+++ b/src/lxcfs.c
@@ -1237,10 +1237,12 @@ int main(int argc, char *argv[])
@@ -1357,10 +1357,12 @@ int main(int argc, char *argv[])
if (append_comma_separate(&new_fuse_opts, token)) {
lxcfs_error("Failed to copy fuse argument \"%s\"", token);
free(dup);
@ -229,7 +232,7 @@ index e24ebed..361ce71 100644
}
if (append_comma_separate(&new_fuse_opts, "allow_other,entry_timeout=0.5,attr_timeout=0.5")) {
@@ -1306,7 +1308,9 @@ out:
@@ -1426,7 +1428,9 @@ out:
if (pidfile)
unlink(pidfile);
free(new_fuse_opts);
@ -240,7 +243,7 @@ index e24ebed..361ce71 100644
exit(ret);
}
diff --git a/src/memory_utils.h b/src/memory_utils.h
index c689c8e..a7e4a58 100644
index c689c8e..13343e1 100644
--- a/src/memory_utils.h
+++ b/src/memory_utils.h
@@ -67,8 +67,10 @@ static inline void free_disarm_function(void *ptr)
@ -256,7 +259,7 @@ index c689c8e..a7e4a58 100644
}
}
diff --git a/src/proc_loadavg.c b/src/proc_loadavg.c
index 5f9bec7..c8daf35 100644
index b7411c4..8cd1e02 100644
--- a/src/proc_loadavg.c
+++ b/src/proc_loadavg.c
@@ -436,10 +436,13 @@ static int refresh_load(struct load_node *p, const char *path)
@ -275,5 +278,5 @@ index 5f9bec7..c8daf35 100644
}
--
2.27.0
2.41.0

View File

@ -1,26 +1,18 @@
From b0097ee3a4b0ac445271badac153293053bd03e1 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Tue, 30 Nov 2021 15:10:23 +0800
Subject: [PATCH 09/17] limit-stat-by-quota-period-setting
From ded1a411d27dde558cc3d057cd65909e9cba1974 Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Wed, 12 Jul 2023 08:25:20 +0000
Subject: [PATCH 07/16] limit stat by quota period setting
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
src/proc_fuse.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
src/proc_fuse.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index 48c4e68..c6c32c7 100644
index 80db328..dfcd72c 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -549,7 +549,7 @@ struct devinfo* container_dev_read(pid_t pid) {
memset(fpath, 0, sizeof(fpath));
snprintf(fpath, 99, "/dev/%s", ptr->d_name);
stat(fpath, &dev_stat);
- fprintf(stream, "%s %d ", ptr->d_name, dev_stat.st_rdev);
+ fprintf(stream, "%s %ld ", ptr->d_name, dev_stat.st_rdev);
fflush(stream);
}
closedir(dir);
@@ -1031,6 +1031,8 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
@@ -1079,6 +1079,8 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
size_t linelen = 0, total_len = 0;
int curcpu = -1; /* cpu numbering starts at 0 */
int physcpu = 0;
@ -29,7 +21,7 @@ index 48c4e68..c6c32c7 100644
uint64_t user = 0, nice = 0, system = 0, idle = 0, iowait = 0, irq = 0,
softirq = 0, steal = 0, guest = 0, guest_nice = 0;
uint64_t user_sum = 0, nice_sum = 0, system_sum = 0, idle_sum = 0,
@@ -1079,6 +1081,13 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
@@ -1127,6 +1129,13 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
if (!cpuset)
return 0;
@ -43,7 +35,7 @@ index 48c4e68..c6c32c7 100644
f = fopen_cached("/proc/stat", "re", &fopen_cache);
if (!f)
return 0;
@@ -1127,6 +1136,9 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
@@ -1175,6 +1184,9 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
continue;
}
@ -54,5 +46,5 @@ index 48c4e68..c6c32c7 100644
continue;
--
2.27.0
2.41.0

View File

@ -1,17 +1,18 @@
From 784830ba0066dae7a181df2b82795dda57427127 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Tue, 30 Nov 2021 15:23:01 +0800
Subject: [PATCH 10/17] diskstats-support-devicemapper-device
From 21c359672300c687ad9b1f28c4c1be4ca00f590a Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Wed, 12 Jul 2023 08:31:21 +0000
Subject: [PATCH 08/16] diskstats support devicemapper device
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
src/proc_fuse.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 55 insertions(+), 1 deletion(-)
src/proc_fuse.c | 99 ++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 77 insertions(+), 22 deletions(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index c6c32c7..a613688 100644
index dfcd72c..f68212d 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -611,6 +611,15 @@ void free_devinfo_list(struct devinfo *ptr)
@@ -638,6 +638,15 @@ void free_devinfo_list(struct devinfo *ptr)
}
}
@ -27,7 +28,7 @@ index c6c32c7..a613688 100644
struct lxcfs_diskstats {
unsigned int major; /* 1 - major number */
unsigned int minor; /* 2 - minor mumber */
@@ -653,6 +662,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -680,6 +689,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
size_t linelen = 0, total_len = 0;
int i = 0;
int ret;
@ -35,7 +36,7 @@ index c6c32c7..a613688 100644
if (offset) {
size_t left;
@@ -720,6 +730,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -747,6 +757,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
while (getline(&line, &linelen, f) != -1) {
ssize_t l;
char lbuf[256];
@ -43,7 +44,7 @@ index c6c32c7..a613688 100644
memset(stats.dev_name, 0, sizeof(stats.dev_name));
i = sscanf(line, "%u %u %71s", &stats.major, &stats.minor, stats.dev_name);
@@ -729,9 +740,14 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -757,9 +768,14 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
if (stats.major == ptr->major && stats.minor == ptr->minor) {
snprintf(stats.dev_name, sizeof(stats.dev_name), "%s", ptr->name);
stats.dev_name[71] = '\0';
@ -58,12 +59,62 @@ index c6c32c7..a613688 100644
get_blkio_io_value(io_serviced_str, stats.major, stats.minor, "Read", &stats.read);
get_blkio_io_value(io_serviced_str, stats.major, stats.minor, "Write", &stats.write);
get_blkio_io_value(io_serviced_str, stats.major, stats.minor, "Discard", &stats.discard);
@@ -791,8 +807,46 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -800,27 +816,28 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
if (stats.read || stats.write || stats.read_merged || stats.write_merged ||
stats.read_sectors || stats.write_sectors || stats.read_ticks ||
stats.write_ticks || stats.ios_pgr || stats.total_ticks || stats.rq_ticks ||
- stats.discard_merged || stats.discard_sectors || stats.discard_ticks)
- snprintf(
- lbuf,
- 256,
- "%u %u" /* major, minor */
- " %s" /* dev_name */
- " %" PRIu64 /* read */
- " %" PRIu64 /* read_merged */
- " %" PRIu64 /* read_sectors */
- " %" PRIu64 /* read_ticks */
- " %" PRIu64 /* write */
- " %" PRIu64 /* write_merged */
- " %" PRIu64 /* write_sectors */
- " %" PRIu64 /* write_ticks */
- " %" PRIu64 /* ios_pgr */
- " %" PRIu64 /* total_ticks */
- " %" PRIu64 /* rq_ticks */
- " %" PRIu64 /* discard_merged */
- " %" PRIu64 /* discard_sectors */
- " %" PRIu64 /* discard_ticks */
- "\n",
+ stats.discard_merged || stats.discard_sectors || stats.discard_ticks) {
+ if (need_record_diskstats(stats.major, stats.minor)) {
+ sscanf(line, "%u %u %71s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+ &stats.major,
+ &stats.minor,
+ tmp_dev_name,
+ &stats.read,
+ &stats.read_merged,
+ &stats.read_sectors,
+ &stats.read_ticks,
+ &stats.write,
+ &stats.write_merged,
+ &stats.write_sectors,
+ &stats.write_ticks,
+ &stats.ios_pgr,
+ &stats.total_ticks,
+ &stats.rq_ticks,
+ &stats.discard_merged,
+ &stats.discard_sectors,
+ &stats.discard_ticks);
+ }
+ snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
stats.major,
stats.minor,
stats.dev_name,
@@ -838,8 +855,46 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
stats.discard_merged,
stats.discard_sectors,
stats.discard_ticks);
- else
+ else if (need_record_diskstats(stats.major, stats.minor)) {
+ } else if (need_record_diskstats(stats.major, stats.minor)) {
+ sscanf(line, "%u %u %71s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+ &stats.major,
+ &stats.minor,
@ -107,5 +158,5 @@ index c6c32c7..a613688 100644
l = snprintf(cache, cache_size, "%s", lbuf);
if (l < 0) {
--
2.27.0
2.41.0

View File

@ -1,79 +0,0 @@
From 0025ea3988eefdf9a7a0eff5d55d2524c105c485 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 14:54:20 +0800
Subject: [PATCH 08/17] fix-hang
---
src/proc_fuse.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index 0aaab71..48c4e68 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -43,6 +43,26 @@
#include "proc_cpuview.h"
#include "utils.h"
+static pthread_mutex_t container_dev_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static void lock_mutex(pthread_mutex_t *l)
+{
+ int ret;
+
+ ret = pthread_mutex_lock(l);
+ if (ret)
+ log_exit("%s - returned %d\n", strerror(ret), ret);
+}
+
+static void unlock_mutex(pthread_mutex_t *l)
+{
+ int ret;
+
+ ret = pthread_mutex_unlock(l);
+ if (ret)
+ log_exit("%s - returned %d\n", strerror(ret), ret);
+}
+
struct memory_stat {
uint64_t hierarchical_memory_limit;
uint64_t hierarchical_memsw_limit;
@@ -492,6 +512,16 @@ struct devinfo* container_dev_read(pid_t pid) {
return head;
}
if (child_pid == 0) {
+ /* Disallow signal reception in child process */
+ sigset_t oldset;
+ sigset_t newset;
+ sigemptyset(&newset);
+ sigaddset(&newset, SIGTERM);
+ sigaddset(&newset, SIGINT);
+ sigaddset(&newset, SIGHUP);
+ sigaddset(&newset, SIGQUIT);
+ sigprocmask(SIG_BLOCK,&newset,&oldset);
+
close(mypipe[0]);
stream = fdopen(mypipe[1], "w");
if (stream == NULL) {
@@ -538,6 +568,8 @@ child_out:
lxcfs_error("Error opening pipe for reading: %s\n", strerror(errno));
goto err;
}
+ wait_for_pid(child_pid);
+ child_pid = 0;
while (fscanf(stream, "%100s%d", dev_name, &dev_num) == 2) {
if (dev_num == 0) {
break;
@@ -681,7 +713,9 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
if (!f)
return 0;
+ lock_mutex(&container_dev_mutex);
container_devinfo = container_dev_read(initpid);
+ unlock_mutex(&container_dev_mutex);
while (getline(&line, &linelen, f) != -1) {
ssize_t l;
--
2.27.0

View File

@ -1,32 +1,33 @@
From f4486dde281016cda897f1564dcb8ca0303f2fbf Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 16:01:12 +0800
Subject: [PATCH 11/17] lxcfs-add-proc-partitions
From 60b82439ccb656ffe79c6499d251627404fd388c Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Wed, 12 Jul 2023 08:42:05 +0000
Subject: [PATCH 09/16] lxcfs add proc partitions
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
src/bindings.h | 3 ++
src/proc_fuse.c | 131 +++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 126 insertions(+), 8 deletions(-)
src/proc_fuse.c | 137 ++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 131 insertions(+), 9 deletions(-)
diff --git a/src/bindings.h b/src/bindings.h
index cd7d466..91d44c7 100644
index 8d9d6eb..fcf408a 100644
--- a/src/bindings.h
+++ b/src/bindings.h
@@ -55,6 +55,9 @@ enum lxcfs_virt_t {
LXC_TYPE_PROC_LOADAVG,
#define LXC_TYPE_PROC_LOADAVG_PATH "/proc/loadavg"
@@ -60,6 +60,9 @@ enum lxcfs_virt_t {
LXC_TYPE_PROC_SLABINFO,
#define LXC_TYPE_PROC_SLABINFO_PATH "/proc/slabinfo"
+ LXC_TYPE_PROC_PARTITIONS,
+#define LXC_TYPE_PROC_PARTITIONS_PATH "/proc/partitions"
+
LXC_TYPE_SYS,
LXC_TYPE_SYS_DEVICES,
LXC_TYPE_SYS_DEVICES_SYSTEM,
LXC_TYPE_SYS_DEVICES_SYSTEM_CPU,
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index a613688..72f6de6 100644
index f68212d..e1896dd 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -118,13 +118,14 @@ __lxcfs_fuse_ops int proc_getattr(const char *path, struct stat *sb)
@@ -119,14 +119,15 @@ __lxcfs_fuse_ops int proc_getattr(const char *path, struct stat *sb)
return 0;
}
@ -36,7 +37,8 @@ index a613688..72f6de6 100644
- strcmp(path, "/proc/stat") == 0 ||
- strcmp(path, "/proc/diskstats") == 0 ||
- strcmp(path, "/proc/swaps") == 0 ||
- strcmp(path, "/proc/loadavg") == 0) {
- strcmp(path, "/proc/loadavg") == 0 ||
- strcmp(path, "/proc/slabinfo") == 0) {
+ if (strcmp(path, "/proc/meminfo") == 0 ||
+ strcmp(path, "/proc/cpuinfo") == 0 ||
+ strcmp(path, "/proc/uptime") == 0 ||
@ -44,30 +46,31 @@ index a613688..72f6de6 100644
+ strcmp(path, "/proc/diskstats") == 0 ||
+ strcmp(path, "/proc/swaps") == 0 ||
+ strcmp(path, "/proc/loadavg") == 0 ||
+ strcmp(path, "/proc/slabinfo") == 0 ||
+ strcmp(path, "/proc/partitions") == 0) {
sb->st_size = get_procfile_size(path);
sb->st_mode = S_IFREG | 00444;
sb->st_nlink = 1;
@@ -146,7 +147,8 @@ __lxcfs_fuse_ops int proc_readdir(const char *path, void *buf,
DIR_FILLER(filler, buf, "uptime", NULL, 0) != 0 ||
DIR_FILLER(filler, buf, "diskstats", NULL, 0) != 0 ||
DIR_FILLER(filler, buf, "swaps", NULL, 0) != 0 ||
- DIR_FILLER(filler, buf, "loadavg", NULL, 0) != 0)
+ DIR_FILLER(filler, buf, "loadavg", NULL, 0) != 0 ||
+ DIR_FILLER(filler, buf, "partitions", NULL, 0) != 0)
@@ -149,7 +150,8 @@ __lxcfs_fuse_ops int proc_readdir(const char *path, void *buf,
dir_filler(filler, buf, "diskstats", 0) != 0 ||
dir_filler(filler, buf, "swaps", 0) != 0 ||
dir_filler(filler, buf, "loadavg", 0) != 0 ||
- dir_filler(filler, buf, "slabinfo", 0) != 0)
+ dir_filler(filler, buf, "slabinfo", 0) != 0 ||
+ dir_filler(filler, buf, "partitions", 0) != 0)
return -EINVAL;
return 0;
@@ -171,6 +173,8 @@ __lxcfs_fuse_ops int proc_open(const char *path, struct fuse_file_info *fi)
type = LXC_TYPE_PROC_SWAPS;
else if (strcmp(path, "/proc/loadavg") == 0)
@@ -176,6 +178,8 @@ __lxcfs_fuse_ops int proc_open(const char *path, struct fuse_file_info *fi)
type = LXC_TYPE_PROC_LOADAVG;
else if (strcmp(path, "/proc/slabinfo") == 0)
type = LXC_TYPE_PROC_SLABINFO;
+ else if (strcmp(path, "/proc/partitions") == 0)
+ type = LXC_TYPE_PROC_PARTITIONS;
if (type == -1)
return -ENOENT;
@@ -872,6 +876,111 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -921,6 +925,115 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
return total_len;
}
@ -91,14 +94,18 @@ index a613688..72f6de6 100644
+ FILE *f = NULL;
+
+ if (offset > 0){
+ size_t left;
+
+ if (offset > d->size)
+ return -EINVAL;
+ if (d->cached == 0)
+ return 0;
+ int left = d->size - offset;
+ total_len = left > size ? size: left;
+
+ if (!d->cached)
+ return 0;
+
+ left = d->size - offset;
+ total_len = left > size ? size: left;
+ memcpy(buf, cache + offset, total_len);
+
+ return total_len;
+ }
+
@ -148,7 +155,7 @@ index a613688..72f6de6 100644
+ rv = 0;
+ goto err;
+ }
+ if (l >= cache_size) {
+ if ((size_t)l >= cache_size) {
+ lxcfs_error("%s\n", "Internal error: truncated write to cache.");
+ rv = 0;
+ goto err;
@ -179,9 +186,9 @@ index a613688..72f6de6 100644
#ifdef RELOADTEST
static inline void iwashere(void)
{
@@ -1676,6 +1785,12 @@ __lxcfs_fuse_ops int proc_read(const char *path, char *buf, size_t size,
@@ -1855,6 +1968,12 @@ __lxcfs_fuse_ops int proc_read(const char *path, char *buf, size_t size,
return read_file_fuse_with_offset(LXC_TYPE_PROC_LOADAVG_PATH,
return read_file_fuse_with_offset(LXC_TYPE_PROC_SLABINFO_PATH,
buf, size, offset, f);
+ case LXC_TYPE_PROC_PARTITIONS:
+ if(liblxcfs_functional())
@ -193,5 +200,5 @@ index a613688..72f6de6 100644
return -EINVAL;
--
2.27.0
2.41.0

View File

@ -1,17 +1,18 @@
From a0d132e43d22153908e392b8274570bacd9cb6ce Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 16:10:39 +0800
Subject: [PATCH 12/17] lxcfs-proc_diskstats_read-func-obtain-data-from-blki
From b610b5534da182a7618d396da481e22624e5e7cf Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Wed, 12 Jul 2023 08:53:42 +0000
Subject: [PATCH 10/16] lxcfs proc_diskstats_read func obtain data from blki
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
src/cgroups/cgfsng.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/cgroups/cgfsng.c b/src/cgroups/cgfsng.c
index 781923c..e50c87d 100644
index e2d9807..15b4539 100644
--- a/src/cgroups/cgfsng.c
+++ b/src/cgroups/cgfsng.c
@@ -751,7 +751,11 @@ static int cgfsng_get_io(struct cgroup_ops *ops, const char *cgroup,
@@ -767,7 +767,11 @@ static int cgfsng_get_io(struct cgroup_ops *ops, const char *cgroup,
static int cgfsng_get_io_service_bytes(struct cgroup_ops *ops,
const char *cgroup, char **value)
{
@ -24,7 +25,7 @@ index 781923c..e50c87d 100644
}
static int cgfsng_get_io_service_time(struct cgroup_ops *ops,
@@ -763,7 +767,11 @@ static int cgfsng_get_io_service_time(struct cgroup_ops *ops,
@@ -779,7 +783,11 @@ static int cgfsng_get_io_service_time(struct cgroup_ops *ops,
static int cgfsng_get_io_serviced(struct cgroup_ops *ops, const char *cgroup,
char **value)
{
@ -38,5 +39,5 @@ index 781923c..e50c87d 100644
static int cgfsng_get_io_merged(struct cgroup_ops *ops, const char *cgroup,
--
2.27.0
2.41.0

View File

@ -0,0 +1,41 @@
From 4e468a948874f661a53b498ac1a30012c7860fd1 Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Fri, 14 Jul 2023 07:54:27 +0000
Subject: [PATCH 11/16] add secure compile option in meson
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
Makefile | 2 +-
meson.build | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 94f2021..38fbe04 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
.PHONY: all
all: meson
- ninja -C build
+ ninja -v -C build
.PHONY: meson
meson:
diff --git a/meson.build b/meson.build
index 379757f..56338b6 100644
--- a/meson.build
+++ b/meson.build
@@ -109,6 +109,9 @@ possible_cc_flags = [
'-Wreturn-local-addr',
'-fsanitize=cfi',
'-Wstringop-overflow',
+ '-ftrapv',
+ '-fPIC',
+ '-O2 -D_FORTIFY_SOURCE=2',
]
possible_link_flags = [
--
2.41.0

View File

@ -1,17 +1,18 @@
From 7418289cfc1e14dc4aa71fd473a083a75fda75a7 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 20:21:46 +0800
Subject: [PATCH 15/17] lxcfs-adapt-4.18-kernel
From 390636cc3246ecaaea6903ae4f97552248b663c5 Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Fri, 14 Jul 2023 09:02:39 +0000
Subject: [PATCH 12/16] lxcfs adapt 4.18 kernel
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
src/proc_fuse.c | 69 +++++++++++++++++++++----------------------------
1 file changed, 30 insertions(+), 39 deletions(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index 0d5ba89..a72d6a2 100644
index e1896dd..fa5b055 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -659,8 +659,8 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -686,8 +686,8 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
struct devinfo *container_devinfo = NULL, *ptr = NULL;
struct lxcfs_diskstats stats = {};
/* helper fields */
@ -22,7 +23,7 @@ index 0d5ba89..a72d6a2 100644
char *cache = d->buf;
size_t cache_size = d->buflen;
size_t linelen = 0, total_len = 0;
@@ -699,29 +699,15 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -726,29 +726,15 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
return read_file_fuse("/proc/diskstats", buf, size, d);
}
@ -55,7 +56,7 @@ index 0d5ba89..a72d6a2 100644
f = fopen_cached("/proc/diskstats", "re", &fopen_cache);
if (!f)
@@ -756,9 +742,11 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -784,9 +770,11 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
get_blkio_io_value(io_serviced_str, stats.major, stats.minor, "Write", &stats.write);
get_blkio_io_value(io_serviced_str, stats.major, stats.minor, "Discard", &stats.discard);
@ -70,7 +71,7 @@ index 0d5ba89..a72d6a2 100644
get_blkio_io_value(io_service_bytes_str, stats.major, stats.minor, "Read", &stats.read_sectors);
stats.read_sectors = stats.read_sectors / 512;
@@ -767,26 +755,29 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -795,26 +783,29 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
get_blkio_io_value(io_service_bytes_str, stats.major, stats.minor, "Discard", &stats.discard_sectors);
stats.discard_sectors = stats.discard_sectors / 512;
@ -118,5 +119,5 @@ index 0d5ba89..a72d6a2 100644
memset(lbuf, 0, 256);
if (stats.read || stats.write || stats.read_merged || stats.write_merged ||
--
2.27.0
2.41.0

View File

@ -1,25 +0,0 @@
From cc7fb353c259830179c7371afb7b141c0f8290ae Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 16:48:55 +0800
Subject: [PATCH 13/17] add-secure-compile-option-in-Makefile
---
src/Makefile.am | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/Makefile.am b/src/Makefile.am
index 2734334..437a377 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,6 +6,8 @@ AM_LDFLAGS = $(FUSE_LIBS) -pthread
#AM_CFLAGS += -DVERBOSE
AM_CFLAGS += -DRUNTIME_PATH=\"$(RUNTIME_PATH)\"
+AM_CFLAGS += -Wl,-z,now -fPIE
+AM_LDFLAGS += -Wl,-z,now -pie
liblxcfs_la_SOURCES = api_extensions.h \
bindings.c bindings.h \
--
2.27.0

View File

@ -1,19 +1,20 @@
From ed5823bf5b0d8bd425417d9b3590ece248fe1655 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Sat, 26 Nov 2022 11:48:14 +0800
Subject: [PATCH] enable cfs option to show correct proc cpuinfo view
From 9b853f8d16f08e837ec330c5906e918ebac70d78 Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Sat, 15 Jul 2023 03:43:12 +0000
Subject: [PATCH 13/16] enable cfs option to show correct proc cpuinfo view
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
config/init/systemd/lxcfs.service.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/config/init/systemd/lxcfs.service.in b/config/init/systemd/lxcfs.service.in
index bdaa2fa..3ee006b 100644
index bae1d08..c3bfd0f 100644
--- a/config/init/systemd/lxcfs.service.in
+++ b/config/init/systemd/lxcfs.service.in
@@ -6,7 +6,7 @@ Documentation=man:lxcfs(1)
@@ -7,7 +7,7 @@ Documentation=man:lxcfs(1)
[Service]
OOMScoreAdjust=-1000
ExecStartPre=-/usr/local/bin/lxcfs-tools prestart
-ExecStart=/usr/bin/lxcfs /var/lib/lxc/lxcfs/
+ExecStart=/usr/bin/lxcfs --enable-cfs /var/lib/lxc/lxcfs/
@ -21,5 +22,5 @@ index bdaa2fa..3ee006b 100644
KillMode=process
ExecStop=-/usr/local/bin/lxcfs-tools umount -a
--
2.30.0
2.41.0

View File

@ -1,15 +1,15 @@
From e3ca16cd280bea10a63e959623fd6625f7b868ce Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 24 Nov 2022 15:53:53 +0800
Subject: [PATCH] fix pidfd_open&pidfd_send_signal function compilation bug in
glibc2.36+
From 35b8b46aeea72d27d931b0bc767ce1e8d3b32db4 Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Sat, 15 Jul 2023 04:25:53 +0000
Subject: [PATCH 14/16] fix pidfd_open pidfd_send_signal function compilation
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
src/utils.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/utils.h b/src/utils.h
index 18d85a7..ab2da0f 100644
index 7ed021a..5f19946 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -46,6 +46,9 @@ static inline int pidfd_open(pid_t pid, unsigned int flags)
@ -33,5 +33,5 @@ index 18d85a7..ab2da0f 100644
extern FILE *fopen_cached(const char *path, const char *mode,
--
2.30.0
2.41.0

View File

@ -1,128 +0,0 @@
From 6710b6d777e4e25b1ce78a4cb9736e7e65f15aa2 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Tue, 30 Nov 2021 15:26:26 +0800
Subject: [PATCH 14/17] fix-proc-diskstats-show-in-container
---
src/proc_fuse.c | 98 +++++++++++++++++++++++++++++--------------------
1 file changed, 59 insertions(+), 39 deletions(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index 72f6de6..0d5ba89 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -792,7 +792,64 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
if (stats.read || stats.write || stats.read_merged || stats.write_merged ||
stats.read_sectors || stats.write_sectors || stats.read_ticks ||
stats.write_ticks || stats.ios_pgr || stats.total_ticks || stats.rq_ticks ||
- stats.discard_merged || stats.discard_sectors || stats.discard_ticks)
+ stats.discard_merged || stats.discard_sectors || stats.discard_ticks) {
+ if (need_record_diskstats(stats.major, stats.minor)) {
+ sscanf(line, "%u %u %71s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+ &stats.major,
+ &stats.minor,
+ tmp_dev_name,
+ &stats.read,
+ &stats.read_merged,
+ &stats.read_sectors,
+ &stats.read_ticks,
+ &stats.write,
+ &stats.write_merged,
+ &stats.write_sectors,
+ &stats.write_ticks,
+ &stats.ios_pgr,
+ &stats.total_ticks,
+ &stats.rq_ticks,
+ &stats.discard_merged,
+ &stats.discard_sectors,
+ &stats.discard_ticks);
+ }
+ snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+ stats.major,
+ stats.minor,
+ stats.dev_name,
+ stats.read,
+ stats.read_merged,
+ stats.read_sectors,
+ stats.read_ticks,
+ stats.write,
+ stats.write_merged,
+ stats.write_sectors,
+ stats.write_ticks,
+ stats.ios_pgr,
+ stats.total_ticks,
+ stats.rq_ticks,
+ stats.discard_merged,
+ stats.discard_sectors,
+ stats.discard_ticks);
+ } else if (need_record_diskstats(stats.major, stats.minor)) {
+ sscanf(line, "%u %u %71s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+ &stats.major,
+ &stats.minor,
+ tmp_dev_name,
+ &stats.read,
+ &stats.read_merged,
+ &stats.read_sectors,
+ &stats.read_ticks,
+ &stats.write,
+ &stats.write_merged,
+ &stats.write_sectors,
+ &stats.write_ticks,
+ &stats.ios_pgr,
+ &stats.total_ticks,
+ &stats.rq_ticks,
+ &stats.discard_merged,
+ &stats.discard_sectors,
+ &stats.discard_ticks);
snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
stats.major,
stats.minor,
@@ -811,44 +868,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
stats.discard_merged,
stats.discard_sectors,
stats.discard_ticks);
- else if (need_record_diskstats(stats.major, stats.minor)) {
- sscanf(line, "%u %u %71s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
- &stats.major,
- &stats.minor,
- tmp_dev_name,
- &stats.read,
- &stats.read_merged,
- &stats.read_sectors,
- &stats.read_ticks,
- &stats.write,
- &stats.write_merged,
- &stats.write_sectors,
- &stats.write_ticks,
- &stats.ios_pgr,
- &stats.total_ticks,
- &stats.rq_ticks,
- &stats.discard_merged,
- &stats.discard_sectors,
- &stats.discard_ticks);
- snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
- stats.major,
- stats.minor,
- stats.dev_name,
- stats.read,
- stats.read_merged,
- stats.read_sectors,
- stats.read_ticks,
- stats.write,
- stats.write_merged,
- stats.write_sectors,
- stats.write_ticks,
- stats.ios_pgr,
- stats.total_ticks,
- stats.rq_ticks,
- stats.discard_merged,
- stats.discard_sectors,
- stats.discard_ticks);
- } else {
+ } else {
continue;
}
--
2.27.0

View File

@ -1,17 +1,18 @@
From d928f8d073f87fdacaf9e93b616f5b84695036e3 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Wed, 22 Mar 2023 15:31:34 +0800
Subject: [PATCH] proc: fix /proc/diskstats output format
From 19bedb98bf93ac67d78cc0606d66e03217e15cbb Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Sat, 15 Jul 2023 08:15:57 +0000
Subject: [PATCH 15/16] proc fix proc diskstats output format
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
src/proc_fuse.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index fe81cad..ce22974 100644
index fa5b055..97bfff8 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -784,10 +784,10 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -810,10 +810,10 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
memset(lbuf, 0, 256);
if (stats.read || stats.write || stats.read_merged || stats.write_merged ||
stats.read_sectors || stats.write_sectors || stats.read_ticks ||
@ -24,7 +25,7 @@ index fe81cad..ce22974 100644
&stats.major,
&stats.minor,
tmp_dev_name,
@@ -802,11 +802,12 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -828,11 +828,12 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
&stats.ios_pgr,
&stats.total_ticks,
&stats.rq_ticks,
@ -38,7 +39,7 @@ index fe81cad..ce22974 100644
stats.major,
stats.minor,
stats.dev_name,
@@ -821,11 +822,17 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
@@ -847,11 +848,17 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
stats.ios_pgr,
stats.total_ticks,
stats.rq_ticks,
@ -52,40 +53,40 @@ index fe81cad..ce22974 100644
+ continue;
+ }
} else if (need_record_diskstats(stats.major, stats.minor)) {
- sscanf(line, "%u %u %71s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+ sscanf(line, "%u %u %71s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
&stats.major,
&stats.minor,
tmp_dev_name,
@@ -840,10 +847,11 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
&stats.ios_pgr,
&stats.total_ticks,
&stats.rq_ticks,
- sscanf(line, "%u %u %71s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+ sscanf(line, "%u %u %71s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
&stats.major,
&stats.minor,
tmp_dev_name,
@@ -866,10 +873,11 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
&stats.ios_pgr,
&stats.total_ticks,
&stats.rq_ticks,
+ &stats.discard,
&stats.discard_merged,
&stats.discard_sectors,
&stats.discard_ticks);
- snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+ ret = snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
stats.major,
stats.minor,
stats.dev_name,
@@ -858,9 +866,15 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
stats.ios_pgr,
stats.total_ticks,
stats.rq_ticks,
&stats.discard_merged,
&stats.discard_sectors,
&stats.discard_ticks);
- snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+ ret = snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
stats.major,
stats.minor,
stats.dev_name,
@@ -884,9 +892,15 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
stats.ios_pgr,
stats.total_ticks,
stats.rq_ticks,
+ stats.discard,
stats.discard_merged,
stats.discard_sectors,
stats.discard_ticks);
stats.discard_merged,
stats.discard_sectors,
stats.discard_ticks);
+ if(ret >= 256) {
+ lxcfs_error("Insufficient buffer for %u:%u %s diskstats",
+ stats.major, stats.minor, stats.dev_name);
+ continue;
+ }
} else {
} else {
continue;
}
--
2.30.0
2.41.0

View File

@ -0,0 +1,48 @@
From 4dadabe36fb3277996870869c62d5cffab72f781 Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Mon, 17 Jul 2023 08:36:34 +0000
Subject: [PATCH 16/16] adapt meson build & install
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
Makefile | 2 +-
config/init/meson.build | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 38fbe04..891d7ad 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ all: meson
.PHONY: meson
meson:
- [ -d build ] || meson setup build/
+ [ -d build ] || meson setup build/ --prefix=/usr
.PHONY: dist
dist: meson
diff --git a/config/init/meson.build b/config/init/meson.build
index 8445955..c781b59 100644
--- a/config/init/meson.build
+++ b/config/init/meson.build
@@ -2,7 +2,7 @@
if 'systemd' in init_script
systemd = dependency('systemd')
- systemd_system_unit_dir = get_option('prefix') + systemd.get_pkgconfig_variable('systemdsystemunitdir')
+ systemd_system_unit_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
systemd_service = custom_target(
'lxcfs.service',
input: 'systemd/lxcfs.service.in',
@@ -14,6 +14,7 @@ if 'systemd' in init_script
'@OUTPUT@',
],
install: true,
+ install_mode: 'rw-r--r--',
install_dir: systemd_system_unit_dir)
endif
--
2.41.0

View File

@ -1,31 +0,0 @@
From 035571472fa6c5772cc6ac467cad7f8ffb9e1d8e Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 20:26:45 +0800
Subject: [PATCH 16/17] remove-lxcfs-tools-dependency-for-common-use
---
config/init/systemd/lxcfs.service.in | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/config/init/systemd/lxcfs.service.in b/config/init/systemd/lxcfs.service.in
index 3d763c6..bdaa2fa 100644
--- a/config/init/systemd/lxcfs.service.in
+++ b/config/init/systemd/lxcfs.service.in
@@ -5,11 +5,11 @@ Before=lxc.service
Documentation=man:lxcfs(1)
[Service]
-ExecStartPre=/usr/local/bin/lxcfs-tools prestart
+ExecStartPre=-/usr/local/bin/lxcfs-tools prestart
ExecStart=/usr/bin/lxcfs /var/lib/lxc/lxcfs/
-ExecStartPost=/usr/local/bin/lxcfs-tools remount -a
+ExecStartPost=-/usr/local/bin/lxcfs-tools remount -a
KillMode=process
-ExecStop=/usr/local/bin/lxcfs-tools umount -a
+ExecStop=-/usr/local/bin/lxcfs-tools umount -a
ExecStopPost=-/bin/fusermount -u /var/lib/lxc/
Delegate=yes
ExecReload=/bin/kill -USR1 $MAINPID
--
2.27.0

View File

@ -1,29 +0,0 @@
From 798bb221b5862418bfb965dc93ce785c743919ff Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 20:30:09 +0800
Subject: [PATCH 17/17] proc_fuse-fix-wait-child-process-hang
---
src/proc_fuse.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index a72d6a2..d02f841 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -561,11 +561,11 @@ struct devinfo* container_dev_read(pid_t pid) {
dev_num = dev_stat.st_dev & (~0xf);
fprintf(stream, "sda %d end 0 ", dev_num);
fflush(stream);
+child_out:
fclose(stream);
exit(0);
}
-child_out:
close(mypipe[1]);
stream = fdopen(mypipe[0], "r");
if (stream == NULL) {
--
2.27.0

View File

@ -1,25 +0,0 @@
From 4ad5ee6eafcdef8178adf1cea53ab8a617d3fd78 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Wed, 15 Dec 2021 17:19:01 +0800
Subject: [PATCH] fix deadlock problem when subprocess exit
---
src/proc_fuse.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index d02f841..0f66c40 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -563,7 +563,7 @@ struct devinfo* container_dev_read(pid_t pid) {
fflush(stream);
child_out:
fclose(stream);
- exit(0);
+ _exit(EXIT_SUCCESS);
}
close(mypipe[1]);
--
2.32.0 (Apple Git-132)

View File

@ -1,59 +0,0 @@
From d67982ddf6d742b92799d1fb2e4c89e8ff87d95b Mon Sep 17 00:00:00 2001
From: zhangsong234 <zhangsong34@huawei.com>
Date: Wed, 11 May 2022 15:55:47 +0800
Subject: [PATCH] fix dev read memory leak in container
Signed-off-by: zhangsong234 <zhangsong34@huawei.com>
---
src/proc_fuse.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index 0f66c40..6051e9a 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -497,7 +497,7 @@ struct devinfo* container_dev_read(pid_t pid) {
struct dirent *ptr;
struct stat dev_stat;
struct devinfo *head = NULL, *end;
- char fpath[100], dev_name[100];
+ char fpath[100], dev_name[101];
pid_t child_pid;
int mypipe[2];
int dev_num;
@@ -558,7 +558,7 @@ struct devinfo* container_dev_read(pid_t pid) {
}
closedir(dir);
stat("/", &dev_stat);
- dev_num = dev_stat.st_dev & (~0xf);
+ dev_num = dev_stat.st_dev;
fprintf(stream, "sda %d end 0 ", dev_num);
fflush(stream);
child_out:
@@ -574,6 +574,7 @@ child_out:
}
wait_for_pid(child_pid);
child_pid = 0;
+ memset(dev_name, 0, sizeof(dev_name));
while (fscanf(stream, "%100s%d", dev_name, &dev_num) == 2) {
if (dev_num == 0) {
break;
@@ -593,6 +594,7 @@ child_out:
end->name = must_copy_string(dev_name);
end->major = major(dev_num);
end->minor = minor(dev_num);
+ memset(dev_name, 0, sizeof(dev_name));
}
err:
if (stream)
@@ -883,6 +885,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
if (total_len > size)
total_len = size;
memcpy(buf, d->buf, total_len);
+ free_devinfo_list(container_devinfo);
return total_len;
}
--
1.8.3.1

View File

@ -1,109 +0,0 @@
From 765d4c48aeaad779008f82ff6643d9cdbe917bd1 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Wed, 22 Mar 2023 09:31:04 +0800
Subject: [PATCH] cpuview: fix possible use-after-free in find_proc_stat_node
Signed-off-by: yangjiaqi <yangjiaqi16@huawei.com>
---
src/proc_cpuview.c | 36 ++++++++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/src/proc_cpuview.c b/src/proc_cpuview.c
index 75006a6..207a6df 100644
--- a/src/proc_cpuview.c
+++ b/src/proc_cpuview.c
@@ -171,6 +171,7 @@ static struct cg_proc_stat *add_proc_stat_node(struct cg_proc_stat *new_node)
}
out_rwlock_unlock:
+ pthread_mutex_lock(&rv->lock);
pthread_rwlock_unlock(&head->lock);
return move_ptr(rv);
}
@@ -224,6 +225,7 @@ static bool cgroup_supports(const char *controller, const char *cgroup,
return faccessat(cfd, path, F_OK, 0) == 0;
}
+/* should be called with wr-locked list */
static struct cg_proc_stat *prune_proc_stat_list(struct cg_proc_stat *node)
{
struct cg_proc_stat *first = NULL;
@@ -232,6 +234,31 @@ static struct cg_proc_stat *prune_proc_stat_list(struct cg_proc_stat *node)
if (!cgroup_supports("cpu", node->cg, "cpu.shares")) {
struct cg_proc_stat *cur = node;
+ /*
+ * We need to ensure that no one referenced this node,
+ * because we are going to remove it from the list and free memory.
+ *
+ * If we can't grab the lock then just keep this node for now.
+ */
+ if (pthread_mutex_trylock(&cur->lock))
+ goto next;
+
+ /*
+ * Yes, we can put lock back just after taking it, as we ensured
+ * that we are only one user of it right now.
+ *
+ * It follows from three facts:
+ * - we are under pthread_rwlock_wrlock(hash_table_bucket)
+ * - pthread_mutex_lock is taken by find_proc_stat_node()
+ * with pthread_rwlock_rdlock(hash_table_bucket) held.
+ * - pthread_mutex_lock is taken by add_proc_stat_node()
+ * with pthread_rwlock_wrlock(hash_table_bucket) held.
+ *
+ * It means that nobody can get a pointer to (cur) node in a parallel
+ * thread and all old users of (cur) node have released pthread_mutex_lock(cur).
+ */
+ pthread_mutex_unlock(&cur->lock);
+
if (prev)
prev->next = node->next;
else
@@ -242,6 +269,7 @@ static struct cg_proc_stat *prune_proc_stat_list(struct cg_proc_stat *node)
free_proc_stat_node(cur);
} else {
+next:
if (!first)
first = node;
prev = node;
@@ -279,6 +307,7 @@ static struct cg_proc_stat *find_proc_stat_node(struct cg_proc_stat_head *head,
{
struct cg_proc_stat *node;
+ prune_proc_stat_history();
pthread_rwlock_rdlock(&head->lock);
if (!head->next) {
@@ -289,15 +318,16 @@ static struct cg_proc_stat *find_proc_stat_node(struct cg_proc_stat_head *head,
node = head->next;
do {
- if (strcmp(cg, node->cg) == 0)
+ if (strcmp(cg, node->cg) == 0) {
+ pthread_mutex_lock(&node->lock);
goto out;
+ }
} while ((node = node->next));
node = NULL;
out:
pthread_rwlock_unlock(&head->lock);
- prune_proc_stat_history();
return node;
}
@@ -318,8 +348,6 @@ static struct cg_proc_stat *find_or_create_proc_stat_node(struct cpuacct_usage *
lxcfs_debug("New stat node (%d) for %s\n", cpu_count, cg);
}
- pthread_mutex_lock(&node->lock);
-
/*
* If additional CPUs on the host have been enabled, CPU usage counter
* arrays have to be expanded.
--
2.30.0

Binary file not shown.

BIN
lxcfs-5.0.3.tar.gz Normal file

Binary file not shown.

View File

@ -3,39 +3,32 @@
#Basic Information
Name: lxcfs
Version: 4.0.11
Release: 8
Version: 5.0.3
Release: 1
Summary: FUSE filesystem for LXC
License: LGPL 2.1+
URL: http://linuxcontainers.org
Source: https://linuxcontainers.org/downloads/%{name}/%{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Patch9001: 0001-systemd.patch
Patch9002: 0002-remove-sysvinit-upstart.patch
Patch9003: 0003-show-dev-name-in-container.patch
Patch9004: 0004-lxcfs-fix-cpuinfo-print.patch
Patch9005: 0005-fix-memory-leak.patch
Patch9006: 0006-fix-concurrency-problem.patch
Patch9007: 0007-set-null-after-free.patch
Patch9008: 0008-fix-hang.patch
Patch9009: 0009-limit-stat-by-quota-period-setting.patch
Patch9010: 0010-diskstats-support-devicemapper-device.patch
Patch9011: 0011-lxcfs-add-proc-partitions.patch
Patch9012: 0012-lxcfs-proc_diskstats_read-func-obtain-data-from-blki.patch
Patch9013: 0013-add-secure-compile-option-in-Makefile.patch
Patch9014: 0014-fix-proc-diskstats-show-in-container.patch
Patch9015: 0015-lxcfs-adapt-4.18-kernel.patch
Patch9016: 0016-remove-lxcfs-tools-dependency-for-common-use.patch
Patch9017: 0017-proc_fuse-fix-wait-child-process-hang.patch
Patch9018: 0018-fix-deadlock-problem-when-subprocess-exit.patch
Patch9019: 0019-fix-dev-read-memory-leak-in-container.patch
Patch9020: 0020-enable-cfs-option-to-show-correct-proc-cpuinfo-view.patch
Patch9021: 0021-fix-pidfd_open-pidfd_send_signal-function-compilatio.patch
Patch9022: 0022-cpuview-fix-possible-use-after-free-in-find_proc_sta.patch
Patch9023: 0023-proc-fix-proc-diskstats-output-format.patch
Patch9002: 0002-show-dev-name-in-container.patch
Patch9003: 0003-lxcfs-fix-cpuinfo-print.patch
Patch9004: 0004-fix-memory-leak.patch
Patch9005: 0005-fix-concurrency-problem.patch
Patch9006: 0006-set-null-after-free.patch
Patch9007: 0007-limit-stat-by-quota-period-setting.patch
Patch9008: 0008-diskstats-support-devicemapper-device.patch
Patch9009: 0009-lxcfs-add-proc-partitions.patch
Patch9010: 0010-lxcfs-proc_diskstats_read-func-obtain-data-from-blki.patch
Patch9011: 0011-add-secure-compile-option-in-meson.patch
Patch9012: 0012-lxcfs-adapt-4.18-kernel.patch
Patch9013: 0013-enable-cfs-option-to-show-correct-proc-cpuinfo-view.patch
Patch9014: 0014-fix-pidfd_open-pidfd_send_signal-function-compilatio.patch
Patch9015: 0015-proc-fix-proc-diskstats-output-format.patch
Patch9016: 0016-adapt-meson-build-install.patch
#Dependency
BuildRequires: autoconf automake libtool help2man
BuildRequires: meson python3-jinja2 help2man
BuildRequires: fuse-devel libattr-devel
BuildRequires: gcc systemd-units
Requires: fuse-libs
@ -49,15 +42,11 @@ any runtime, written in C using libfuse and glib.
%autosetup -p1
%build
autoreconf --force --install
%configure
make tests
make %{?_smp_mflags}
%install
make install DESTDIR=%{buildroot} %{?_smp_mflags}
install -d -m 0755 %{buildroot}%{_unitdir}
install -p -m 0644 config/init/systemd/*.service %{buildroot}%{_unitdir}/
make install DESTDIR=%{buildroot} %{?_smp_mflags}
install -d -m 0755 %{buildroot}%{_sbindir}
ln -sf service %{buildroot}%{_sbindir}/rc%{name}
install -d -m 0755 %{buildroot}%{_includedir}/%{name}
@ -89,11 +78,16 @@ fi
%dir %{_localstatedir}/lib/lxc/%{name}
%dir %{_libdir}/%{name}
%{_libdir}/%{name}/lib%{name}.so
%exclude %{_libdir}/%{name}/lib%{name}.la
%{_mandir}/man1/*
%{_unitdir}/*
%changelog
* Mon July 17 2023 yangjiaqi <yangjiaqi16@huawei.com> - 5.0.3-1
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:upgrade to 5.0.3
* Wed Mar 22 2023 yangjiaqi <yangjiaqi16@huawei.com> - 4.0.11-8
- Type:bugfix
- CVE:NA