Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static bool has_versioned_opts;
static bool memory_is_cgroupv2;
static __u32 host_personality;
static char runtime_path[PATH_MAX] = DEFAULT_RUNTIME_PATH;
static char force_render_cgroup[PATH_MAX] = "";


static volatile sig_atomic_t reload_successful;
Expand Down Expand Up @@ -917,6 +918,18 @@ bool set_runtime_path(const char* new_path)
}
}

void set_force_render_cgroup(const char* new_path)
{
if (new_path && strlen(new_path) < PATH_MAX) {
if (new_path[0]) {
strlcpy(force_render_cgroup, new_path, sizeof(force_render_cgroup));
lxcfs_info("Using force render cgroup %s", force_render_cgroup);
}
} else {
lxcfs_error("%s\n", "Failed to overwrite the force render cgroup");
}
}

void lxcfslib_init(void)
{
__do_close int init_ns = -EBADF, root_fd = -EBADF,
Expand Down Expand Up @@ -1043,6 +1056,9 @@ void *lxcfs_fuse_init(struct fuse_conn_info *conn, void *data)
if (opts && opts->version >= 2) {
set_runtime_path(opts->runtime_path);
}
if (opts && opts->version >= 5) {
set_force_render_cgroup(opts->force_render_cgroup);
}

/* initialize the library */
lxcfslib_init();
Expand Down
1 change: 1 addition & 0 deletions src/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ struct lxcfs_opts {
char runtime_path[PATH_MAX];
bool zswap_off;
bool psi_poll_on;
char force_render_cgroup[PATH_MAX];
};

typedef enum lxcfs_opt_t {
Expand Down
13 changes: 12 additions & 1 deletion src/lxcfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

void *dlopen_handle;
static char runtime_path[PATH_MAX] = DEFAULT_RUNTIME_PATH;
static char force_render_cgroup[PATH_MAX] = "";


/* Functions to keep track of number of threads using the library */
Expand Down Expand Up @@ -926,6 +927,7 @@ static void usage(void)
lxcfs_info(" --enable-cgroup Enable cgroup emulation code");
lxcfs_info(" --runtime-dir=DIR Path to use as the runtime directory.");
lxcfs_info(" Default is %s", DEFAULT_RUNTIME_PATH);
lxcfs_info(" --force-render-cgroup Make procfs/sysfs render in view of cgroup in args");
exit(EXIT_FAILURE);
}

Expand Down Expand Up @@ -977,6 +979,7 @@ static const struct option long_options[] = {
{"enable-pidfd", no_argument, 0, 0 },
{"enable-cgroup", no_argument, 0, 0 },
{"enable-psi-poll", no_argument, 0, 0 },
{"force-render-cgroup", required_argument, 0, 0 },

{"pidfile", required_argument, 0, 'p' },
{"runtime-dir", required_argument, 0, 0 },
Expand Down Expand Up @@ -1040,6 +1043,7 @@ int main(int argc, char *argv[])
char *const *new_argv;
struct lxcfs_opts *opts;
char *runtime_path_arg = NULL;
char *force_render_cgroup_arg = NULL;

opts = malloc(sizeof(struct lxcfs_opts));
if (opts == NULL) {
Expand All @@ -1052,7 +1056,7 @@ int main(int argc, char *argv[])
opts->use_pidfd = false;
opts->use_cfs = false;
opts->psi_poll_on = false;
opts->version = 4;
opts->version = 5;

while ((c = getopt_long(argc, argv, "dulfhvso:p:", long_options, &idx)) != -1) {
switch (c) {
Expand All @@ -1067,6 +1071,8 @@ int main(int argc, char *argv[])
opts->psi_poll_on = true;
else if (strcmp(long_options[idx].name, "runtime-dir") == 0)
runtime_path_arg = optarg;
else if (strcmp(long_options[idx].name, "force-render-cgroup") == 0)
force_render_cgroup_arg = optarg;
else
usage();
break;
Expand Down Expand Up @@ -1127,6 +1133,11 @@ int main(int argc, char *argv[])
lxcfs_info("runtime path set to %s", runtime_path);
}
strlcpy(opts->runtime_path, runtime_path, sizeof(opts->runtime_path));
if (force_render_cgroup_arg) {
strlcpy(force_render_cgroup, force_render_cgroup_arg, sizeof(force_render_cgroup));
lxcfs_info("force render cgroup set to %s", force_render_cgroup);
}
strlcpy(opts->force_render_cgroup, force_render_cgroup, sizeof(opts->force_render_cgroup));

fuse_argv[fuse_argc++] = argv[0];
if (debug)
Expand Down
29 changes: 17 additions & 12 deletions src/proc_cpuview.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,18 +977,23 @@ int proc_cpuinfo_read(char *buf, size_t size, off_t offset,
return total_len;
}

pid_t initpid = lookup_initpid_in_store(fc->pid);
if (initpid <= 1 || is_shared_pidns(initpid))
initpid = fc->pid;

cg = get_pid_cgroup(initpid, "cpuset");
if (!cg)
return read_file_fuse("proc/cpuinfo", buf, size, d);
prune_init_slice(cg);
cpu_cg = get_pid_cgroup(initpid, "cpu");
if (!cpu_cg)
return read_file_fuse("proc/cpuinfo", buf, size, d);
prune_init_slice(cpu_cg);
if (opts && opts->force_render_cgroup[0]) {
cg = strdup(opts->force_render_cgroup);
cpu_cg = strdup(opts->force_render_cgroup);
} else {
pid_t initpid = lookup_initpid_in_store(fc->pid);
if (initpid <= 1 || is_shared_pidns(initpid))
initpid = fc->pid;

cg = get_pid_cgroup(initpid, "cpuset");
if (!cg)
return read_file_fuse("proc/cpuinfo", buf, size, d);
prune_init_slice(cg);
cpu_cg = get_pid_cgroup(initpid, "cpu");
if (!cpu_cg)
return read_file_fuse("proc/cpuinfo", buf, size, d);
prune_init_slice(cpu_cg);
}
cpuset = get_cpuset(cg);
if (!cpuset)
return 0;
Expand Down
Loading