Skip to content

Commit

Permalink
cgfsng: next generation filesystem-backed cgroup implementation
Browse files Browse the repository at this point in the history
This makes simplifying assumptions:  all usable cgroups must be
mounted under /sys/fs/cgroup/controller or /sys/fs/cgroup/contr1,contr2.

Currently this will only work with cgroup namespaces, because
lxc.mount.auto = cgroup is not implemented.  So cgfsng_ops_init()
returns NULL if cgroup namespaces are not enabled.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
  • Loading branch information
hallyn committed Mar 5, 2016
1 parent 6861fb2 commit ccb4cab
Show file tree
Hide file tree
Showing 10 changed files with 1,518 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/lxc/Makefile.am
Expand Up @@ -89,6 +89,7 @@ liblxc_so_SOURCES = \
error.h error.c \
parse.c parse.h \
cgfs.c \
cgfsng.c \
cgroup.c cgroup.h \
lxc.h \
initutils.c initutils.h \
Expand Down
24 changes: 2 additions & 22 deletions src/lxc/cgfs.c
Expand Up @@ -141,7 +141,6 @@ static int do_cgroup_set(const char *cgroup_path, const char *sub_filename, cons
static bool cgroup_devices_has_allow_or_deny(struct cgfs_data *d, char *v, bool for_allow);
static int do_setup_cgroup_limits(struct cgfs_data *d, struct lxc_list *cgroup_settings, bool do_devices);
static int cgroup_recursive_task_count(const char *cgroup_path);
static int count_lines(const char *fn);
static int handle_cgroup_settings(struct cgroup_mount_point *mp, char *cgroup_path);
static bool init_cpuset_if_needed(struct cgroup_mount_point *mp, const char *path);

Expand Down Expand Up @@ -2116,7 +2115,7 @@ static int cgroup_recursive_task_count(const char *cgroup_path)
if (r >= 0)
n += r;
} else if (!strcmp(dent->d_name, "tasks")) {
r = count_lines(sub_path);
r = lxc_count_file_lines(sub_path);
if (r >= 0)
n += r;
}
Expand All @@ -2128,25 +2127,6 @@ static int cgroup_recursive_task_count(const char *cgroup_path)
return n;
}

static int count_lines(const char *fn)
{
FILE *f;
char *line = NULL;
size_t sz = 0;
int n = 0;

f = fopen_cloexec(fn, "r");
if (!f)
return -1;

while (getline(&line, &sz, f) != -1) {
n++;
}
free(line);
fclose(f);
return n;
}

static int handle_cgroup_settings(struct cgroup_mount_point *mp,
char *cgroup_path)
{
Expand Down Expand Up @@ -2420,7 +2400,7 @@ static const char *cgfs_canonical_path(void *hdata)
return path;
}

static bool cgfs_escape(void)
static bool cgfs_escape(void *hdata)
{
struct cgroup_meta_data *md;
int i;
Expand Down

0 comments on commit ccb4cab

Please sign in to comment.