cgroups: more consistent naming

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner 2018-01-31 17:09:13 +01:00
parent 6b38e644cb
commit a3926f6a95
No known key found for this signature in database
GPG Key ID: 8EB056D53EECB12D

View File

@ -432,7 +432,7 @@ static ssize_t get_max_cpus(char *cpulist)
} }
#define __ISOL_CPUS "/sys/devices/system/cpu/isolated" #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; char *lastslash, *fpath, oldv;
int ret; int ret;
@ -613,7 +613,7 @@ bad:
* Since the h->base_path is populated by init or ourselves, we know * Since the h->base_path is populated by init or ourselves, we know
* it is already initialized. * 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; char *cgpath, *clonechildrenpath, v, *slash;
@ -650,7 +650,7 @@ static bool handle_cpuset_hierarchy(struct hierarchy *h, char *cgname)
} }
/* Make sure any isolated cpus are removed from cpuset.cpus. */ /* 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."); SYSERROR("Failed to remove isolated cpus.");
free(clonechildrenpath); free(clonechildrenpath);
free(cgpath); free(cgpath);
@ -772,8 +772,8 @@ static bool all_controllers_found(void)
* options. But we simply assume that the mountpoint must be * options. But we simply assume that the mountpoint must be
* /sys/fs/cgroup/controller-list * /sys/fs/cgroup/controller-list
*/ */
static char **get_controllers_on_hybrid_layout(char **klist, char **nlist, static char **cg_hybrid_get_controllers(char **klist, char **nlist, char *line,
char *line, int type) int type)
{ {
/* the fourth field is /sys/fs/cgroup/comma-delimited-controller-list */ /* the fourth field is /sys/fs/cgroup/comma-delimited-controller-list */
int i; int i;
@ -877,7 +877,7 @@ static struct hierarchy *add_hierarchy(char **clist, char *mountpoint,
* Get a copy of the mountpoint from @line, which is a line from * Get a copy of the mountpoint from @line, which is a line from
* /proc/self/mountinfo * /proc/self/mountinfo
*/ */
static char *get_mountpoint_on_hybrid_layout(char *line) static char *cg_hybrid_get_mountpoint(char *line)
{ {
int i; int i;
char *p2; char *p2;
@ -958,7 +958,7 @@ static bool controller_in_clist(char *cgline, char *c)
* @basecginfo is a copy of /proc/$$/cgroup. Return the current * @basecginfo is a copy of /proc/$$/cgroup. Return the current
* cgroup for @controller * 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; char *p = basecginfo;
@ -1086,7 +1086,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; int k;
char **it; char **it;
@ -1110,7 +1111,7 @@ static void lxc_cgfsng_print_debuginfo(const struct cgfsng_handler_data *d)
* At startup, parse_hierarchies finds all the info we need about * At startup, parse_hierarchies finds all the info we need about
* cgroup mountpoints and current cgroups, and stores it in @d. * cgroup mountpoints and current cgroups, and stores it in @d.
*/ */
static bool cg_init_hybrid(void) static bool cg_hybrid_init(void)
{ {
int ret; int ret;
char *basecginfo; char *basecginfo;
@ -1175,7 +1176,7 @@ static bool cg_init_hybrid(void)
cgroup_layout = CGROUP_LAYOUT_HYBRID; 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) if (!controller_list && type == CGROUP_SUPER_MAGIC)
continue; continue;
@ -1183,16 +1184,16 @@ static bool cg_init_hybrid(void)
if (controller_list_is_dup(hierarchies, controller_list)) if (controller_list_is_dup(hierarchies, controller_list))
goto next; goto next;
mountpoint = get_mountpoint_on_hybrid_layout(line); mountpoint = cg_hybrid_get_mountpoint(line);
if (!mountpoint) { if (!mountpoint) {
CGFSNG_DEBUG("Failed parsing mountpoint from \"%s\"\n", line); CGFSNG_DEBUG("Failed parsing mountpoint from \"%s\"\n", line);
goto next; goto next;
} }
if (type == CGROUP_SUPER_MAGIC) 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 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) { if (!base_cgroup) {
CGFSNG_DEBUG("Failed to find current cgroup\n"); CGFSNG_DEBUG("Failed to find current cgroup\n");
goto next; goto next;
@ -1269,7 +1270,7 @@ static int cg_is_pure_unified(void) {
} }
/* Get current cgroup from /proc/self/cgroup for the cgroupfs v2 hierarchy. */ /* 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 *basecginfo;
char *base_cgroup; char *base_cgroup;
@ -1301,7 +1302,7 @@ cleanup_on_err:
return copy; return copy;
} }
static int cg_init_unified(void) static int cg_unified_init(void)
{ {
int ret; int ret;
char *mountpoint, *subtree_path; char *mountpoint, *subtree_path;
@ -1315,7 +1316,7 @@ static int cg_init_unified(void)
if (ret != CGROUP2_SUPER_MAGIC) if (ret != CGROUP2_SUPER_MAGIC)
return 0; return 0;
base_cgroup = cg_get_current_cgroup_unified(); base_cgroup = cg_unified_get_current_cgroup();
if (!base_cgroup) if (!base_cgroup)
return -EINVAL; return -EINVAL;
prune_init_scope(base_cgroup); prune_init_scope(base_cgroup);
@ -1361,14 +1362,14 @@ static bool cg_init(void)
} }
cgroup_use = must_copy_string(tmp); cgroup_use = must_copy_string(tmp);
ret = cg_init_unified(); ret = cg_unified_init();
if (ret < 0) if (ret < 0)
return false; return false;
if (ret == CGROUP2_SUPER_MAGIC) if (ret == CGROUP2_SUPER_MAGIC)
return true; return true;
return cg_init_hybrid(); return cg_hybrid_init();
} }
static void *cgfsng_init(struct lxc_handler *handler) static void *cgfsng_init(struct lxc_handler *handler)
@ -1562,7 +1563,7 @@ struct cgroup_ops *cgfsng_ops_init(void)
return &cgfsng_ops; 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; char **it;
size_t i, parts_len; size_t i, parts_len;
@ -1636,7 +1637,7 @@ static bool create_path_for_hierarchy(struct hierarchy *h, char *cgname)
return false; return false;
} }
if (!handle_cpuset_hierarchy(h, cgname)) { if (!cg_legacy_handle_cpuset_hierarchy(h, cgname)) {
ERROR("Failed to handle cgroupfs v1 cpuset controller"); ERROR("Failed to handle cgroupfs v1 cpuset controller");
return false; return false;
} }
@ -1647,7 +1648,7 @@ static bool create_path_for_hierarchy(struct hierarchy *h, char *cgname)
return false; 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) static void remove_path_for_hierarchy(struct hierarchy *h, char *cgname)
@ -1871,7 +1872,7 @@ static bool cgfsng_chown(void *hdata, struct lxc_conf *conf)
/* mount cgroup-full if requested */ /* mount cgroup-full if requested */
static int mount_cgroup_full(int type, struct hierarchy *h, char *dest, 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) if (type < LXC_AUTO_CGROUP_FULL_RO || type > LXC_AUTO_CGROUP_FULL_MIXED)
return 0; return 0;
@ -1910,6 +1911,7 @@ static bool cg_mount_needs_subdirs(int type)
{ {
if (type >= LXC_AUTO_CGROUP_FULL_RO) if (type >= LXC_AUTO_CGROUP_FULL_RO)
return false; return false;
return true; return true;
} }
@ -1918,10 +1920,9 @@ static bool cg_mount_needs_subdirs(int type)
* created, remount controller ro if needed and bindmount the * created, remount controller ro if needed and bindmount the
* cgroupfs onto controll/the/cg/path * cgroupfs onto controll/the/cg/path
*/ */
static int static int do_secondstage_mounts_if_needed(int type, struct hierarchy *h,
do_secondstage_mounts_if_needed(int type, struct hierarchy *h, char *controllerpath, char *cgpath,
char *controllerpath, char *cgpath, const char *container_cgroup)
const char *container_cgroup)
{ {
if (type == LXC_AUTO_CGROUP_RO || type == LXC_AUTO_CGROUP_MIXED) { if (type == LXC_AUTO_CGROUP_RO || type == LXC_AUTO_CGROUP_MIXED) {
if (mount(controllerpath, controllerpath, "cgroup", MS_BIND, NULL) < 0) { if (mount(controllerpath, controllerpath, "cgroup", MS_BIND, NULL) < 0) {
@ -2132,6 +2133,7 @@ static int cgfsng_nrtasks(void *hdata) {
if (!d || !d->container_cgroup || !hierarchies) if (!d || !d->container_cgroup || !hierarchies)
return -1; return -1;
path = must_make_path(hierarchies[0]->fullcgpath, NULL); path = must_make_path(hierarchies[0]->fullcgpath, NULL);
count = recursive_count_nrtasks(path); count = recursive_count_nrtasks(path);
free(path); free(path);
@ -2161,7 +2163,6 @@ static bool cgfsng_escape()
return true; return true;
} }
/* TODO: handle the unified cgroup hierarchy */
static int cgfsng_num_hierarchies(void) static int cgfsng_num_hierarchies(void)
{ {
int i; int i;
@ -2172,7 +2173,6 @@ static int cgfsng_num_hierarchies(void)
return i; return i;
} }
/* TODO: handle the unified cgroup hierarchy */
static bool cgfsng_get_hierarchies(int n, char ***out) static bool cgfsng_get_hierarchies(int n, char ***out)
{ {
int i; int i;
@ -2243,9 +2243,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 * created when we started the container in the latter case we create our own
* cgroup for the attaching process. * cgroup for the attaching process.
*/ */
static int cg_attach_unified(const struct hierarchy *h, const char *name, static int __cg_unified_attach(const struct hierarchy *h, const char *name,
const char *lxcpath, const char *pidstr, const char *lxcpath, const char *pidstr,
size_t pidstr_len, const char *controller) size_t pidstr_len, const char *controller)
{ {
int ret; int ret;
size_t len; size_t len;
@ -2323,7 +2323,8 @@ static bool cgfsng_attach(const char *name, const char *lxcpath, pid_t pid)
struct hierarchy *h = hierarchies[i]; struct hierarchy *h = hierarchies[i];
if (h->version == CGROUP2_SUPER_MAGIC) { 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) if (ret < 0)
return false; return false;
@ -2504,7 +2505,8 @@ out:
* Called from setup_limits - here we have the container's cgroup_data because * Called from setup_limits - here we have the container's cgroup_data because
* we created the cgroups * 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; char *fullpath, *p;
/* "b|c <2^64-1>:<2^64-1> r|w|m" = 47 chars max */ /* "b|c <2^64-1>:<2^64-1> r|w|m" = 47 chars max */
@ -2542,9 +2544,9 @@ static int lxc_cgroup_set_data(const char *filename, const char *value, struct c
return ret; return ret;
} }
static bool __cgfsng_setup_limits_legacy(void *hdata, static bool __cg_legacy_setup_limits(void *hdata,
struct lxc_list *cgroup_settings, struct lxc_list *cgroup_settings,
bool do_devices) bool do_devices)
{ {
struct cgfsng_handler_data *d = hdata; struct cgfsng_handler_data *d = hdata;
struct lxc_list *iterator, *sorted_cgroup_settings, *next; struct lxc_list *iterator, *sorted_cgroup_settings, *next;
@ -2562,7 +2564,7 @@ static bool __cgfsng_setup_limits_legacy(void *hdata,
cg = iterator->elem; cg = iterator->elem;
if (do_devices == !strncmp("devices", cg->subsystem, 7)) { 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)) { if (do_devices && (errno == EACCES || errno == EPERM)) {
WARN("Error setting %s to %s for %s", WARN("Error setting %s to %s for %s",
cg->subsystem, cg->value, d->name); cg->subsystem, cg->value, d->name);
@ -2587,8 +2589,8 @@ out:
return ret; return ret;
} }
static bool __cgfsng_setup_limits_unified(void *hdata, static bool __cg_unified_setup_limits(void *hdata,
struct lxc_list *cgroup_settings) struct lxc_list *cgroup_settings)
{ {
struct lxc_list *iterator; struct lxc_list *iterator;
struct hierarchy *h = unified; struct hierarchy *h = unified;
@ -2623,11 +2625,11 @@ static bool cgfsng_setup_limits(void *hdata, struct lxc_conf *conf,
{ {
bool bret; bool bret;
bret = __cgfsng_setup_limits_legacy(hdata, &conf->cgroup, do_devices); bret = __cg_legacy_setup_limits(hdata, &conf->cgroup, do_devices);
if (!bret) if (!bret)
return false; return false;
return __cgfsng_setup_limits_unified(hdata, &conf->cgroup2); return __cg_unified_setup_limits(hdata, &conf->cgroup2);
} }
static struct cgroup_ops cgfsng_ops = { static struct cgroup_ops cgfsng_ops = {