From 56a081d7b97e00eb44573fd7948c40aea78dfb4d Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Wed, 31 Jan 2018 17:09:13 +0100 Subject: [PATCH] cgroups: more consistent naming Signed-off-by: Christian Brauner --- src/lxc/cgroups/cgfsng.c | 84 ++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index 37204c81f..9314f727d 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -424,7 +424,7 @@ static ssize_t get_max_cpus(char *cpulist) } #define __ISOL_CPUS "/sys/devices/system/cpu/isolated" -static bool filter_and_set_cpus(char *path, bool am_initialized) +static bool cg_legacy_filter_and_set_cpus(char *path, bool am_initialized) { char *lastslash, *fpath, oldv; int ret; @@ -605,7 +605,7 @@ bad: * Since the h->base_path is populated by init or ourselves, we know * it is already initialized. */ -static bool handle_cpuset_hierarchy(struct hierarchy *h, char *cgname) +static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname) { char *cgpath, *clonechildrenpath, v, *slash; @@ -642,7 +642,7 @@ static bool handle_cpuset_hierarchy(struct hierarchy *h, char *cgname) } /* Make sure any isolated cpus are removed from cpuset.cpus. */ - if (!filter_and_set_cpus(cgpath, v == '1')) { + if (!cg_legacy_filter_and_set_cpus(cgpath, v == '1')) { SYSERROR("Failed to remove isolated cpus."); free(clonechildrenpath); free(cgpath); @@ -764,8 +764,8 @@ static bool all_controllers_found(void) * options. But we simply assume that the mountpoint must be * /sys/fs/cgroup/controller-list */ -static char **get_controllers_on_hybrid_layout(char **klist, char **nlist, - char *line, int type) +static char **cg_hybrid_get_controllers(char **klist, char **nlist, char *line, + int type) { /* the fourth field is /sys/fs/cgroup/comma-delimited-controller-list */ int i; @@ -869,7 +869,7 @@ static struct hierarchy *add_hierarchy(char **clist, char *mountpoint, * Get a copy of the mountpoint from @line, which is a line from * /proc/self/mountinfo */ -static char *get_mountpoint_on_hybrid_layout(char *line) +static char *cg_hybrid_get_mountpoint(char *line) { int i; char *p2; @@ -950,7 +950,7 @@ static bool controller_in_clist(char *cgline, char *c) * @basecginfo is a copy of /proc/$$/cgroup. Return the current * cgroup for @controller */ -static char *get_current_cgroup(char *basecginfo, char *controller, int type) +static char *cg_hybrid_get_current_cgroup(char *basecginfo, char *controller, int type) { char *p = basecginfo; @@ -1076,7 +1076,8 @@ static void lxc_cgfsng_print_hierarchies() } } -static void lxc_cgfsng_print_basecg_debuginfo(char *basecginfo, char **klist, char **nlist) +static void lxc_cgfsng_print_basecg_debuginfo(char *basecginfo, char **klist, + char **nlist) { int k; char **it; @@ -1100,7 +1101,7 @@ static void lxc_cgfsng_print_debuginfo(const struct cgfsng_handler_data *d) * At startup, parse_hierarchies finds all the info we need about * cgroup mountpoints and current cgroups, and stores it in @d. */ -static bool cg_init_hybrid(void) +static bool cg_hybrid_init(void) { int ret; char *basecginfo; @@ -1165,7 +1166,7 @@ static bool cg_init_hybrid(void) cgroup_layout = CGROUP_LAYOUT_HYBRID; } - controller_list = get_controllers_on_hybrid_layout(klist, nlist, line, type); + controller_list = cg_hybrid_get_controllers(klist, nlist, line, type); if (!controller_list && type == CGROUP_SUPER_MAGIC) continue; @@ -1173,16 +1174,16 @@ static bool cg_init_hybrid(void) if (controller_list_is_dup(hierarchies, controller_list)) goto next; - mountpoint = get_mountpoint_on_hybrid_layout(line); + mountpoint = cg_hybrid_get_mountpoint(line); if (!mountpoint) { CGFSNG_DEBUG("Failed parsing mountpoint from \"%s\"\n", line); goto next; } if (type == CGROUP_SUPER_MAGIC) - base_cgroup = get_current_cgroup(basecginfo, controller_list[0], CGROUP_SUPER_MAGIC); + base_cgroup = cg_hybrid_get_current_cgroup(basecginfo, controller_list[0], CGROUP_SUPER_MAGIC); else - base_cgroup = get_current_cgroup(basecginfo, NULL, CGROUP2_SUPER_MAGIC); + base_cgroup = cg_hybrid_get_current_cgroup(basecginfo, NULL, CGROUP2_SUPER_MAGIC); if (!base_cgroup) { CGFSNG_DEBUG("Failed to find current cgroup\n"); goto next; @@ -1259,7 +1260,7 @@ static int cg_is_pure_unified(void) { } /* Get current cgroup from /proc/self/cgroup for the cgroupfs v2 hierarchy. */ -static char *cg_get_current_cgroup_unified(void) +static char *cg_unified_get_current_cgroup(void) { char *basecginfo; char *base_cgroup; @@ -1291,7 +1292,7 @@ cleanup_on_err: return copy; } -static int cg_init_unified(void) +static int cg_unified_init(void) { int ret; char *mountpoint, *subtree_path; @@ -1305,7 +1306,7 @@ static int cg_init_unified(void) if (ret != CGROUP2_SUPER_MAGIC) return 0; - base_cgroup = cg_get_current_cgroup_unified(); + base_cgroup = cg_unified_get_current_cgroup(); if (!base_cgroup) return -EINVAL; prune_init_scope(base_cgroup); @@ -1351,14 +1352,14 @@ static bool cg_init(void) } cgroup_use = must_copy_string(tmp); - ret = cg_init_unified(); + ret = cg_unified_init(); if (ret < 0) return false; if (ret == CGROUP2_SUPER_MAGIC) return true; - return cg_init_hybrid(); + return cg_hybrid_init(); } static void *cgfsng_init(struct lxc_handler *handler) @@ -1544,7 +1545,7 @@ struct cgroup_ops *cgfsng_ops_init(void) return &cgfsng_ops; } -static bool handle_unified_hierarchy(struct hierarchy *h, char *cgname) +static bool cg_unified_create_cgroup(struct hierarchy *h, char *cgname) { char **it; size_t i, parts_len; @@ -1618,7 +1619,7 @@ static bool create_path_for_hierarchy(struct hierarchy *h, char *cgname) return false; } - if (!handle_cpuset_hierarchy(h, cgname)) { + if (!cg_legacy_handle_cpuset_hierarchy(h, cgname)) { ERROR("Failed to handle cgroupfs v1 cpuset controller"); return false; } @@ -1629,7 +1630,7 @@ static bool create_path_for_hierarchy(struct hierarchy *h, char *cgname) return false; } - return handle_unified_hierarchy(h, cgname); + return cg_unified_create_cgroup(h, cgname); } static void remove_path_for_hierarchy(struct hierarchy *h, char *cgname) @@ -1850,7 +1851,7 @@ static bool cgfsng_chown(void *hdata, struct lxc_conf *conf) /* mount cgroup-full if requested */ static int mount_cgroup_full(int type, struct hierarchy *h, char *dest, - char *container_cgroup) + char *container_cgroup) { if (type < LXC_AUTO_CGROUP_FULL_RO || type > LXC_AUTO_CGROUP_FULL_MIXED) return 0; @@ -1889,6 +1890,7 @@ static bool cg_mount_needs_subdirs(int type) { if (type >= LXC_AUTO_CGROUP_FULL_RO) return false; + return true; } @@ -1897,10 +1899,9 @@ static bool cg_mount_needs_subdirs(int type) * created, remount controller ro if needed and bindmount the * cgroupfs onto controll/the/cg/path */ -static int -do_secondstage_mounts_if_needed(int type, struct hierarchy *h, - char *controllerpath, char *cgpath, - const char *container_cgroup) +static int do_secondstage_mounts_if_needed(int type, struct hierarchy *h, + char *controllerpath, char *cgpath, + const char *container_cgroup) { if (type == LXC_AUTO_CGROUP_RO || type == LXC_AUTO_CGROUP_MIXED) { if (mount(controllerpath, controllerpath, "cgroup", MS_BIND, NULL) < 0) { @@ -2111,6 +2112,7 @@ static int cgfsng_nrtasks(void *hdata) { if (!d || !d->container_cgroup || !hierarchies) return -1; + path = must_make_path(hierarchies[0]->fullcgpath, NULL); count = recursive_count_nrtasks(path); free(path); @@ -2140,7 +2142,6 @@ static bool cgfsng_escape() return true; } -/* TODO: handle the unified cgroup hierarchy */ static int cgfsng_num_hierarchies(void) { int i; @@ -2151,7 +2152,6 @@ static int cgfsng_num_hierarchies(void) return i; } -/* TODO: handle the unified cgroup hierarchy */ static bool cgfsng_get_hierarchies(int n, char ***out) { int i; @@ -2222,9 +2222,9 @@ static char *build_full_cgpath_from_monitorpath(struct hierarchy *h, * created when we started the container in the latter case we create our own * cgroup for the attaching process. */ -static int cg_attach_unified(const struct hierarchy *h, const char *name, - const char *lxcpath, const char *pidstr, - size_t pidstr_len, const char *controller) +static int __cg_unified_attach(const struct hierarchy *h, const char *name, + const char *lxcpath, const char *pidstr, + size_t pidstr_len, const char *controller) { int ret; size_t len; @@ -2302,7 +2302,8 @@ static bool cgfsng_attach(const char *name, const char *lxcpath, pid_t pid) struct hierarchy *h = hierarchies[i]; if (h->version == CGROUP2_SUPER_MAGIC) { - ret = cg_attach_unified(h, name, lxcpath, pidstr, len, h->controllers[0]); + ret = __cg_unified_attach(h, name, lxcpath, pidstr, len, + h->controllers[0]); if (ret < 0) return false; @@ -2483,7 +2484,8 @@ out: * Called from setup_limits - here we have the container's cgroup_data because * we created the cgroups */ -static int lxc_cgroup_set_data(const char *filename, const char *value, struct cgfsng_handler_data *d) +static int cg_legacy_set_data(const char *filename, const char *value, + struct cgfsng_handler_data *d) { char *fullpath, *p; /* "b|c <2^64-1>:<2^64-1> r|w|m" = 47 chars max */ @@ -2521,9 +2523,9 @@ static int lxc_cgroup_set_data(const char *filename, const char *value, struct c return ret; } -static bool __cgfsng_setup_limits_legacy(void *hdata, - struct lxc_list *cgroup_settings, - bool do_devices) +static bool __cg_legacy_setup_limits(void *hdata, + struct lxc_list *cgroup_settings, + bool do_devices) { struct cgfsng_handler_data *d = hdata; struct lxc_list *iterator, *sorted_cgroup_settings, *next; @@ -2541,7 +2543,7 @@ static bool __cgfsng_setup_limits_legacy(void *hdata, cg = iterator->elem; if (do_devices == !strncmp("devices", cg->subsystem, 7)) { - if (lxc_cgroup_set_data(cg->subsystem, cg->value, d)) { + if (cg_legacy_set_data(cg->subsystem, cg->value, d)) { if (do_devices && (errno == EACCES || errno == EPERM)) { WARN("Error setting %s to %s for %s", cg->subsystem, cg->value, d->name); @@ -2566,8 +2568,8 @@ out: return ret; } -static bool __cgfsng_setup_limits_unified(void *hdata, - struct lxc_list *cgroup_settings) +static bool __cg_unified_setup_limits(void *hdata, + struct lxc_list *cgroup_settings) { INFO("Setting limits on the unified cgroup hierarchy is not supported"); return true; @@ -2578,11 +2580,11 @@ static bool cgfsng_setup_limits(void *hdata, struct lxc_conf *conf, { bool bret; - bret = __cgfsng_setup_limits_legacy(hdata, &conf->cgroup, do_devices); + bret = __cg_legacy_setup_limits(hdata, &conf->cgroup, do_devices); if (!bret) return false; - return __cgfsng_setup_limits_unified(NULL, NULL); + return __cg_unified_setup_limits(NULL, NULL); } static struct cgroup_ops cgfsng_ops = { -- 2.47.2