The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxcfs/pull/339
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From dbb1f822e2bcc4255be2f61843a9e75ebbf39366 Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Tue, 3 Mar 2020 15:30:11 +0100 Subject: [PATCH 1/5] tree-wide: make fopen() calls cloexec Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- cgroup_fuse.c | 6 +++--- cgroups/cgfsng.c | 4 ++-- cgroups/cgroup_utils.c | 2 +- proc_cpuview.c | 2 +- proc_fuse.c | 12 ++++++------ proc_loadavg.c | 2 +- utils.c | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cgroup_fuse.c b/cgroup_fuse.c index 2ff2ea6..a50c12e 100644 --- a/cgroup_fuse.c +++ b/cgroup_fuse.c @@ -407,7 +407,7 @@ static bool is_privileged_over(pid_t pid, uid_t uid, uid_t victim, bool req_ns_r ret = snprintf(fpath, PROCLEN, "/proc/%d/uid_map", pid); if (ret < 0 || ret >= PROCLEN) return false; - FILE *f = fopen(fpath, "r"); + FILE *f = fopen(fpath, "re"); if (!f) return false; @@ -1601,7 +1601,7 @@ static void get_pid_creds(pid_t pid, uid_t *uid, gid_t *gid) *uid = -1; *gid = -1; sprintf(line, "/proc/%d/status", pid); - if ((f = fopen(line, "r")) == NULL) { + if ((f = fopen(line, "re")) == NULL) { lxcfs_error("Error opening %s: %s\n", line, strerror(errno)); return; } @@ -1635,7 +1635,7 @@ static bool hostuid_to_ns(uid_t uid, pid_t pid, uid_t *answer) char line[400]; sprintf(line, "/proc/%d/uid_map", pid); - if ((f = fopen(line, "r")) == NULL) { + if ((f = fopen(line, "re")) == NULL) { return false; } diff --git a/cgroups/cgfsng.c b/cgroups/cgfsng.c index d5b6aff..80ad98a 100644 --- a/cgroups/cgfsng.c +++ b/cgroups/cgfsng.c @@ -372,7 +372,7 @@ static int get_existing_subsystems(char ***klist, char ***nlist) __do_fclose FILE *f = NULL; size_t len = 0; - f = fopen("/proc/self/cgroup", "r"); + f = fopen("/proc/self/cgroup", "re"); if (!f) return -1; @@ -805,7 +805,7 @@ static int cg_hybrid_init(struct cgroup_ops *ops) if (ret < 0) return log_error_errno(-1, errno, "Failed to retrieve available legacy cgroup controllers"); - f = fopen("/proc/self/mountinfo", "r"); + f = fopen("/proc/self/mountinfo", "re"); if (!f) return log_error_errno(-1, errno, "Failed to open \"/proc/self/mountinfo\""); diff --git a/cgroups/cgroup_utils.c b/cgroups/cgroup_utils.c index 805ee32..af9b403 100644 --- a/cgroups/cgroup_utils.c +++ b/cgroups/cgroup_utils.c @@ -557,7 +557,7 @@ char *read_file(const char *fnam) char *buf = NULL; size_t len = 0, fulllen = 0; - f = fopen(fnam, "r"); + f = fopen(fnam, "re"); if (!f) return NULL; while ((linelen = getline(&line, &len, f)) != -1) { diff --git a/proc_cpuview.c b/proc_cpuview.c index 6212547..15cb972 100644 --- a/proc_cpuview.c +++ b/proc_cpuview.c @@ -908,7 +908,7 @@ int proc_cpuinfo_read(char *buf, size_t size, off_t offset, if (use_view) max_cpus = max_cpu_count(cg); - f = fopen("/proc/cpuinfo", "r"); + f = fopen("/proc/cpuinfo", "re"); if (!f) return 0; diff --git a/proc_fuse.c b/proc_fuse.c index afe11a2..ea389b7 100644 --- a/proc_fuse.c +++ b/proc_fuse.c @@ -121,7 +121,7 @@ int proc_readdir(const char *path, void *buf, fuse_fill_dir_t filler, static off_t get_procfile_size(const char *which) { - FILE *f = fopen(which, "r"); + FILE *f = fopen(which, "re"); char *line = NULL; size_t len = 0; ssize_t sz, answer = 0; @@ -304,7 +304,7 @@ static int proc_swaps_read(char *buf, size_t size, off_t offset, __do_fclose FILE *f = NULL; size_t linelen = 0; - f = fopen("/proc/meminfo", "r"); + f = fopen("/proc/meminfo", "re"); if (!f) return 0; @@ -438,7 +438,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset, return read_file_fuse("/proc/diskstats", buf, size, d); } - f = fopen("/proc/diskstats", "r"); + f = fopen("/proc/diskstats", "re"); if (!f) return 0; @@ -571,7 +571,7 @@ static uint64_t get_reaper_start_time(pid_t pid) return 0; } - f = fopen(path, "r"); + f = fopen(path, "re"); if (!f) { /* Caller can check for EINVAL on 0. */ errno = EINVAL; @@ -787,7 +787,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset, if (read_cpuacct_usage_all(cg, cpuset, &cg_cpu_usage, &cg_cpu_usage_size) != 0) lxcfs_v("%s\n", "proc_stat_read failed to read from cpuacct, falling back to the host's /proc/stat"); - f = fopen("/proc/stat", "r"); + f = fopen("/proc/stat", "re"); if (!f) return 0; @@ -1095,7 +1095,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset, memlimit /= 1024; memusage /= 1024; - f = fopen("/proc/meminfo", "r"); + f = fopen("/proc/meminfo", "re"); if (!f) return 0; diff --git a/proc_loadavg.c b/proc_loadavg.c index 31dd968..9b7e21c 100644 --- a/proc_loadavg.c +++ b/proc_loadavg.c @@ -431,7 +431,7 @@ static int refresh_load(struct load_node *p, char *path) goto err_out; } - f = fopen(proc_path, "r"); + f = fopen(proc_path, "re"); if (f != NULL) { while (getline(&line, &linelen, f) != -1) { /* Find State */ diff --git a/utils.c b/utils.c index e49bc4f..5c81415 100644 --- a/utils.c +++ b/utils.c @@ -337,7 +337,7 @@ int read_file_fuse(const char *path, char *buf, size_t size, struct file_info *d char *cache = d->buf; size_t cache_size = d->buflen; - f = fopen(path, "r"); + f = fopen(path, "re"); if (!f) return 0; From 757a63e7c72a542f73fc7fde1c6944effa6dfec2 Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Tue, 3 Mar 2020 16:02:33 +0100 Subject: [PATCH 2/5] tree-wide: introduce and use fopen_cached() Closes #257. Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- bindings.c | 3 +- cgroups/cgfsng.c | 4 ++- cpuset_parse.c | 3 +- proc_cpuview.c | 3 +- proc_fuse.c | 15 ++++++---- proc_loadavg.c | 3 +- utils.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ utils.h | 3 ++ 8 files changed, 94 insertions(+), 11 deletions(-) diff --git a/bindings.c b/bindings.c index 9adc60d..64e6eeb 100644 --- a/bindings.c +++ b/bindings.c @@ -474,10 +474,11 @@ static bool has_fs_type(const struct statfs *fs, fs_type_magic magic_val) static bool is_on_ramfs(void) { __do_free char *line = NULL; + __do_free void *fopen_cache = NULL; __do_fclose FILE *f = NULL; size_t len = 0; - f = fopen("/proc/self/mountinfo", "re"); + f = fopen_cached("/proc/self/mountinfo", "re", &fopen_cache); if (!f) return false; diff --git a/cgroups/cgfsng.c b/cgroups/cgfsng.c index 80ad98a..f8d2349 100644 --- a/cgroups/cgfsng.c +++ b/cgroups/cgfsng.c @@ -41,6 +41,7 @@ #include "../config.h" #include "../macro.h" #include "../memory_utils.h" +#include "../utils.h" #include "cgroup.h" #include "cgroup2_devices.h" #include "cgroup_utils.h" @@ -789,6 +790,7 @@ static int cg_hybrid_init(struct cgroup_ops *ops) { __do_free char *basecginfo = NULL; __do_free char *line = NULL; + __do_free void *fopen_cache = NULL; __do_fclose FILE *f = NULL; int ret; size_t len = 0; @@ -805,7 +807,7 @@ static int cg_hybrid_init(struct cgroup_ops *ops) if (ret < 0) return log_error_errno(-1, errno, "Failed to retrieve available legacy cgroup controllers"); - f = fopen("/proc/self/mountinfo", "re"); + f = fopen_cached("/proc/self/mountinfo", "re", &fopen_cache); if (!f) return log_error_errno(-1, errno, "Failed to open \"/proc/self/mountinfo\""); diff --git a/cpuset_parse.c b/cpuset_parse.c index f67f557..b1b3109 100644 --- a/cpuset_parse.c +++ b/cpuset_parse.c @@ -56,8 +56,7 @@ bool cpu_in_cpuset(int cpu, const char *cpuset) ret = cpuset_getrange(c, &a, &b); if (ret == 1 && cpu == a) /* "1" or "1,6" */ return true; - - if (ret == 2 && cpu >= a && cpu <= b) /* range match */ + else if (ret == 2 && cpu >= a && cpu <= b) /* range match */ return true; } diff --git a/proc_cpuview.c b/proc_cpuview.c index 15cb972..c25b4f5 100644 --- a/proc_cpuview.c +++ b/proc_cpuview.c @@ -866,6 +866,7 @@ int proc_cpuinfo_read(char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { __do_free char *cg = NULL, *cpuset = NULL, *line = NULL; + __do_free void *fopen_cache = NULL; __do_fclose FILE *f = NULL; struct fuse_context *fc = fuse_get_context(); struct file_info *d = INTTYPE_TO_PTR(fi->fh); @@ -908,7 +909,7 @@ int proc_cpuinfo_read(char *buf, size_t size, off_t offset, if (use_view) max_cpus = max_cpu_count(cg); - f = fopen("/proc/cpuinfo", "re"); + f = fopen_cached("/proc/cpuinfo", "re", &fopen_cache); if (!f) return 0; diff --git a/proc_fuse.c b/proc_fuse.c index ea389b7..0646cc6 100644 --- a/proc_fuse.c +++ b/proc_fuse.c @@ -301,10 +301,11 @@ static int proc_swaps_read(char *buf, size_t size, off_t offset, /* When no mem + swap limit is specified or swapaccount=0*/ if (!memswlimit) { __do_free char *line = NULL; + __do_free void *fopen_cache = NULL; __do_fclose FILE *f = NULL; size_t linelen = 0; - f = fopen("/proc/meminfo", "re"); + f = fopen_cached("/proc/meminfo", "re", &fopen_cache); if (!f) return 0; @@ -367,6 +368,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset, *io_merged_str = NULL, *io_service_bytes_str = NULL, *io_wait_time_str = NULL, *io_service_time_str = NULL, *line = NULL; + __do_free void *fopen_cache = NULL; __do_fclose FILE *f = NULL; struct fuse_context *fc = fuse_get_context(); struct file_info *d = INTTYPE_TO_PTR(fi->fh); @@ -438,7 +440,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset, return read_file_fuse("/proc/diskstats", buf, size, d); } - f = fopen("/proc/diskstats", "re"); + f = fopen_cached("/proc/diskstats", "re", &fopen_cache); if (!f) return 0; @@ -542,6 +544,7 @@ static double get_reaper_busy(pid_t task) static uint64_t get_reaper_start_time(pid_t pid) { + __do_free void *fopen_cache = NULL; __do_fclose FILE *f = NULL; int ret; uint64_t starttime; @@ -571,7 +574,7 @@ static uint64_t get_reaper_start_time(pid_t pid) return 0; } - f = fopen(path, "re"); + f = fopen_cached(path, "re", &fopen_cache); if (!f) { /* Caller can check for EINVAL on 0. */ errno = EINVAL; @@ -726,6 +729,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { __do_free char *cg = NULL, *cpuset = NULL, *line = NULL; + __do_free void *fopen_cache = NULL; __do_free struct cpuacct_usage *cg_cpu_usage = NULL; __do_fclose FILE *f = NULL; struct fuse_context *fc = fuse_get_context(); @@ -787,7 +791,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset, if (read_cpuacct_usage_all(cg, cpuset, &cg_cpu_usage, &cg_cpu_usage_size) != 0) lxcfs_v("%s\n", "proc_stat_read failed to read from cpuacct, falling back to the host's /proc/stat"); - f = fopen("/proc/stat", "re"); + f = fopen_cached("/proc/stat", "re", &fopen_cache); if (!f) return 0; @@ -1030,6 +1034,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset, __do_free char *cgroup = NULL, *line = NULL, *memusage_str = NULL, *memstat_str = NULL, *memswlimit_str = NULL, *memswusage_str = NULL; + __do_free void *fopen_cache = NULL; __do_fclose FILE *f = NULL; struct fuse_context *fc = fuse_get_context(); struct lxcfs_opts *opts = (struct lxcfs_opts *) fuse_get_context()->private_data; @@ -1095,7 +1100,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset, memlimit /= 1024; memusage /= 1024; - f = fopen("/proc/meminfo", "re"); + f = fopen_cached("/proc/meminfo", "re", &fopen_cache); if (!f) return 0; diff --git a/proc_loadavg.c b/proc_loadavg.c index 9b7e21c..e48fcab 100644 --- a/proc_loadavg.c +++ b/proc_loadavg.c @@ -411,6 +411,7 @@ static int refresh_load(struct load_node *p, char *path) continue; } while ((file = readdir(dp)) != NULL) { + __do_free void *fopen_cache = NULL; __do_fclose FILE *f = NULL; if (strncmp(file->d_name, ".", 1) == 0) @@ -431,7 +432,7 @@ static int refresh_load(struct load_node *p, char *path) goto err_out; } - f = fopen(proc_path, "re"); + f = fopen_cached(proc_path, "re", &fopen_cache); if (f != NULL) { while (getline(&line, &linelen, f) != -1) { /* Find State */ diff --git a/utils.c b/utils.c index 5c81415..0bc99c1 100644 --- a/utils.c +++ b/utils.c @@ -406,3 +406,74 @@ int wait_for_pid(pid_t pid) return -1; return 0; } + +static ssize_t read_nointr(int fd, void *buf, size_t count) +{ + ssize_t ret; +again: + ret = read(fd, buf, count); + if (ret < 0 && errno == EINTR) + goto again; + + return ret; +} + +static void *must_realloc(void *orig, size_t sz) +{ + void *ret; + + do { + ret = realloc(orig, sz); + } while (!ret); + + return ret; +} + +static char *file_to_buf(const char *path, size_t *length) +{ + __do_close_prot_errno int fd = -EBADF; + __do_free char *copy = NULL; + char buf[PATH_MAX]; + + if (!length) + return NULL; + + fd = open(path, O_RDONLY | O_CLOEXEC); + if (fd < 0) + return NULL; + + *length = 0; + for (;;) { + int n; + char *old = copy; + + n = read_nointr(fd, buf, sizeof(buf)); + if (n < 0) + return NULL; + if (!n) + break; + + copy = must_realloc(old, (*length + n) * sizeof(*old)); + memcpy(copy + *length, buf, n); + *length += n; + } + + return move_ptr(copy); +} + +FILE *fopen_cached(const char *path, const char *mode, void **caller_freed_buffer) +{ + __do_free char *buf = NULL; + size_t len = 0; + FILE *f; + + buf = file_to_buf(path, &len); + if (!buf) + return NULL; + + f = fmemopen(buf, len, mode); + if (!f) + return NULL; + *caller_freed_buffer = move_ptr(buf); + return f; +} diff --git a/utils.h b/utils.h index f366150..7450fb6 100644 --- a/utils.h +++ b/utils.h @@ -71,4 +71,7 @@ static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info, } #endif +extern FILE *fopen_cached(const char *path, const char *mode, + void **caller_freed_buffer); + #endif /* __LXCFS_UTILS_H */ From 89113f7ef11fb7ba6e521edbfa2729d2778b4a45 Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Tue, 3 Mar 2020 16:40:02 +0100 Subject: [PATCH 3/5] config: allow system service file to set custom target path Closes #238. Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- config/init/systemd/{lxcfs.service => lxcfs.service.in} | 4 ++-- configure.ac | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) rename config/init/systemd/{lxcfs.service => lxcfs.service.in} (73%) diff --git a/config/init/systemd/lxcfs.service b/config/init/systemd/lxcfs.service.in similarity index 73% rename from config/init/systemd/lxcfs.service rename to config/init/systemd/lxcfs.service.in index af20e5a..9cd4e59 100644 --- a/config/init/systemd/lxcfs.service +++ b/config/init/systemd/lxcfs.service.in @@ -5,10 +5,10 @@ Before=lxc.service Documentation=man:lxcfs(1) [Service] -ExecStart=/usr/bin/lxcfs /var/lib/lxcfs/ +ExecStart=/usr/bin/lxcfs @LXCFSTARGETDIR@ KillMode=process Restart=on-failure -ExecStopPost=-/bin/fusermount -u /var/lib/lxcfs +ExecStopPost=-/bin/fusermount -u @LXCFSTARGETDIR@ Delegate=yes ExecReload=/bin/kill -USR1 $MAINPID diff --git a/configure.ac b/configure.ac index dbe26e7..fe799e4 100644 --- a/configure.ac +++ b/configure.ac @@ -17,6 +17,7 @@ AC_CONFIG_FILES([ config/Makefile config/init/Makefile config/init/systemd/Makefile + config/init/systemd/lxcfs.service config/init/sysvinit/Makefile config/init/upstart/Makefile share/Makefile From b00731345042b42bae9d058ba8fc64c57695efac Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Tue, 3 Mar 2020 17:04:45 +0100 Subject: [PATCH 4/5] lxcfs: improve help and add long options Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- lxcfs.c | 57 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/lxcfs.c b/lxcfs.c index 28a1b48..880aa94 100644 --- a/lxcfs.c +++ b/lxcfs.c @@ -957,16 +957,22 @@ const struct fuse_operations lxcfs_ops = { static void usage() { - fprintf(stderr, "Usage:\n"); + fprintf(stderr, "Usage: lxcfs <directory>\n"); fprintf(stderr, "\n"); - fprintf(stderr, "lxcfs [-f|-d] -u -l -n [-p pidfile] mountpoint\n"); - fprintf(stderr, " -f running foreground by default; -d enable debug output \n"); - fprintf(stderr, " -l use loadavg \n"); - fprintf(stderr, " -u no swap \n"); - fprintf(stderr, " Default pidfile is %s/lxcfs.pid\n", RUNTIME_PATH); - fprintf(stderr, "lxcfs -h\n"); - fprintf(stderr, "lxcfs -v\n"); - exit(1); + fprintf(stderr, "lxcfs set up fuse- and cgroup-based virtualizing filesystem\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Options :\n"); + fprintf(stderr, "-d, --debug Run lxcfs with debugging enabled\n"); + fprintf(stderr, "-f, --foreground Run lxcfs in the foreground\n"); + fprintf(stderr, "-n, --help Print help\n"); + fprintf(stderr, "-l, --enable-loadavg Enable loadavg virtualization\n"); + fprintf(stderr, "-o Options to pass directly through fuse\n"); + fprintf(stderr, "-p, --pidfile=FILE Path to use for storing lxcfs pid\n"); + fprintf(stderr, " Default pidfile is %s/lxcfs.pid\n", RUNTIME_PATH); + fprintf(stderr, "-u, --disable-swap Disable swap virtualization\n"); + fprintf(stderr, "-v, --version Print lxcfs version\n"); + fprintf(stderr, "--enable-pidfd Use pidfd for process tracking\n"); + exit(EXIT_FAILURE); } static inline bool is_help(char *w) @@ -1065,7 +1071,7 @@ int main(int argc, char *argv[]) int ret = EXIT_FAILURE; char *pidfile = NULL, *saveptr = NULL, *token = NULL, *v = NULL; char pidfile_buf[STRLITERALLEN(RUNTIME_PATH) + STRLITERALLEN("/lxcfs.pid") + 1] = {}; - bool debug = false, nonempty = false; + bool debug = false, foreground = false, nonempty = false; bool load_use = false; /* * what we pass to fuse_main is: @@ -1085,15 +1091,32 @@ int main(int argc, char *argv[]) /* accomodate older init scripts */ swallow_arg(&argc, argv, "-s"); - swallow_arg(&argc, argv, "-f"); + + /* -f / --foreground */ + foreground = swallow_arg(&argc, argv, "-f"); + if (swallow_arg(&argc, argv, "--foreground")) + foreground = true; + + /* -d / --debug */ debug = swallow_arg(&argc, argv, "-d"); - if (swallow_arg(&argc, argv, "-l")) + if (swallow_arg(&argc, argv, "--debug")) + debug = true; + + if (foreground && debug) + log_exit("Both --debug and --forgreound specified"); + + /* -l / --enable-loadavg */ + load_use = swallow_arg(&argc, argv, "-l"); + if (swallow_arg(&argc, argv, "--enable-loadavg")) load_use = true; - if (swallow_arg(&argc, argv, "-u")) + + /* -u / --disable-swap */ + opts->swap_off = swallow_arg(&argc, argv, "-u"); + if (swallow_arg(&argc, argv, "--disable-swap")) opts->swap_off = true; - if (swallow_arg(&argc, argv, "--pidfd")) - opts->use_pidfd = true; + /* --enable-pidfd */ + opts->use_pidfd = swallow_arg(&argc, argv, "--enable-pidfd"); if (swallow_option(&argc, argv, "-o", &v)) { /* Parse multiple values */ @@ -1111,8 +1134,12 @@ int main(int argc, char *argv[]) free(v); v = NULL; } + + /* -p / --pidfile */ if (swallow_option(&argc, argv, "-p", &v)) pidfile = v; + if (!pidfile && swallow_option(&argc, argv, "--pidfile", &v)) + pidfile = v; if (argc == 2 && is_version(argv[1])) { fprintf(stderr, "%s\n", VERSION); From e3f2bf6ff9638a7b73efa06eddbabb775b5a3756 Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Tue, 3 Mar 2020 17:16:23 +0100 Subject: [PATCH 5/5] lxcfs: add --disable-cfs Closes #298. Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- bindings.h | 1 + lxcfs.c | 5 +++++ proc_cpuview.c | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bindings.h b/bindings.h index d995518..64a9be5 100644 --- a/bindings.h +++ b/bindings.h @@ -66,6 +66,7 @@ struct file_info { struct lxcfs_opts { bool swap_off; bool use_pidfd; + bool use_cfs; }; extern pid_t lookup_initpid_in_store(pid_t qpid); diff --git a/lxcfs.c b/lxcfs.c index 880aa94..57f4759 100644 --- a/lxcfs.c +++ b/lxcfs.c @@ -963,6 +963,7 @@ static void usage() fprintf(stderr, "\n"); fprintf(stderr, "Options :\n"); fprintf(stderr, "-d, --debug Run lxcfs with debugging enabled\n"); + fprintf(stderr, "--disable-cfs Disable cpu virtualization via cpu shares\n"); fprintf(stderr, "-f, --foreground Run lxcfs in the foreground\n"); fprintf(stderr, "-n, --help Print help\n"); fprintf(stderr, "-l, --enable-loadavg Enable loadavg virtualization\n"); @@ -1088,6 +1089,7 @@ int main(int argc, char *argv[]) } opts->swap_off = false; opts->use_pidfd = false; + opts->use_cfs = true; /* accomodate older init scripts */ swallow_arg(&argc, argv, "-s"); @@ -1118,6 +1120,9 @@ int main(int argc, char *argv[]) /* --enable-pidfd */ opts->use_pidfd = swallow_arg(&argc, argv, "--enable-pidfd"); + /* --disable-cfs */ + opts->use_cfs = swallow_arg(&argc, argv, "--disable-cfs"); + if (swallow_option(&argc, argv, "-o", &v)) { /* Parse multiple values */ for (; (token = strtok_r(v, ",", &saveptr)); v = NULL) { diff --git a/proc_cpuview.c b/proc_cpuview.c index c25b4f5..8321840 100644 --- a/proc_cpuview.c +++ b/proc_cpuview.c @@ -869,6 +869,7 @@ int proc_cpuinfo_read(char *buf, size_t size, off_t offset, __do_free void *fopen_cache = NULL; __do_fclose FILE *f = NULL; struct fuse_context *fc = fuse_get_context(); + struct lxcfs_opts *opts = (struct lxcfs_opts *)fc->private_data; struct file_info *d = INTTYPE_TO_PTR(fi->fh); size_t linelen = 0, total_len = 0; bool am_printing = false, firstline = true, is_s390x = false; @@ -905,7 +906,9 @@ int proc_cpuinfo_read(char *buf, size_t size, off_t offset, if (!cpuset) return 0; - use_view = cgroup_ops->can_use_cpuview(cgroup_ops); + if (cgroup_ops->can_use_cpuview(cgroup_ops) && opts->use_cfs) + use_view = true; + if (use_view) max_cpus = max_cpu_count(cg);
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel