[CRIU] [PATCH 2/2] Attempt to restore cgroups
Tycho Andersen
tycho.andersen at canonical.com
Thu Jul 3 07:23:56 PDT 2014
Ugh, and here's one without the stupid debug statement again, sorry
about that.
During the dump phase, /proc/cgroups is parsed to find co-mounted cgroups.
Then, for each task /proc/self/cgroup is parsed for the cgroups that it is a
member of, and that cgroup is traversed to find any child cgroups which may
also need restoring. All of this information is persisted along with the
original cg_sets, which indicate which cgroups a task is a member of.
On restore, an initial phase creates all the cgroups which were saved and
attempts to restore any peroperties they had. Then the tasks are restored into
their respective cgroups via cg_sets as usual.
Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
cgroup.c | 449 +++++++++++++++++++++++++++++++++++++++++++++++---
cr-dump.c | 3 +
include/cgroup.h | 46 ++++++
include/proc_parse.h | 3 +
include/util.h | 7 +-
mount.c | 3 +
proc_parse.c | 75 ++++++++-
protobuf/cgroup.proto | 16 +-
protobuf/mnt.proto | 1 +
util.c | 34 ++++
10 files changed, 609 insertions(+), 28 deletions(-)
diff --git a/cgroup.c b/cgroup.c
index 1fe5e6d..306bfe3 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -5,6 +5,8 @@
#include <unistd.h>
#include <sys/mount.h>
#include <sys/stat.h>
+#include <ftw.h>
+#include <libgen.h>
#include "xmalloc.h"
#include "cgroup.h"
#include "pstree.h"
@@ -18,7 +20,8 @@
/*
* This structure describes set of controller groups
* a task lives in. The cg_ctl entries are stored in
- * the @ctls list sorted by the .name field.
+ * the @ctls list sorted by the .name field and then
+ * by the .path field.
*/
struct cg_set {
@@ -36,6 +39,10 @@ static struct cg_set *root_cgset; /* Set root item lives in */
static struct cg_set *criu_cgset; /* Set criu process lives in */
static u32 cg_set_ids = 1;
+static LIST_HEAD(cgroups);
+static unsigned int n_cgroups;
+static struct mount_info *cg_mntinfo;
+
static CgSetEntry *find_rst_set_by_id(u32 id)
{
int i;
@@ -118,6 +125,265 @@ static struct cg_set *get_cg_set(struct list_head *ctls, unsigned int n_ctls)
return cs;
}
+struct cg_controller *new_controller(const char *name, int heirarchy)
+{
+ struct cg_controller *nc = xmalloc(sizeof(*nc));
+ if (!nc)
+ return NULL;
+
+ nc->controllers = xmalloc(sizeof(char*));
+ if (!nc->controllers) {
+ xfree(nc);
+ return NULL;
+ }
+
+ nc->controllers[0] = xstrdup(name);
+ if (!nc->controllers[0]) {
+ xfree(nc->controllers);
+ xfree(nc);
+ return NULL;
+ }
+
+ nc->n_controllers = 1;
+ nc->heirarchy = heirarchy;
+
+ nc->n_heads = 0;
+ INIT_LIST_HEAD(&nc->heads);
+
+ return nc;
+}
+
+int parse_cg_info()
+{
+ if (parse_cgroups(&cgroups, &n_cgroups) < 0)
+ return -1;
+
+ cg_mntinfo = parse_mountinfo(getpid(), NULL);
+
+ if (!cg_mntinfo)
+ return -1;
+ return 0;
+}
+
+char *get_cgroup_mount_point(const char *controller)
+{
+ struct mount_info *m;
+ char path[PATH_MAX];
+
+ for (m = cg_mntinfo; m != NULL; m = m->next) {
+ if (strcmp(m->fstype->name, "cgroup") == 0) {
+ char *slash;
+
+ slash = strrchr(m->mountpoint, '/');
+ if (!slash) {
+ pr_err("bad path %s\n", path);
+ return NULL;
+ }
+
+ if (strcmp(slash + 1, controller) == 0) {
+ /* skip the leading '.' in mountpoint */
+ strncpy(path, m->mountpoint + 1, slash - m->mountpoint + 1);
+ path[slash - m->mountpoint] = '\0';
+
+ return xstrdup(path);
+ }
+ }
+ }
+
+ return NULL;
+}
+
+static struct cg_controller *current_controller;
+static char *current_controller_name;
+
+#define EXACT_MATCH 0
+#define PARENT_MATCH 1
+#define NO_MATCH 2
+
+static int find_dir(const char *path, struct list_head *dirs, struct cgroup_dir **rdir)
+{
+ struct cgroup_dir *d;
+ list_for_each_entry(d, dirs, siblings) {
+ if (strcmp(d->path, path) == 0) {
+ *rdir = d;
+ return EXACT_MATCH;
+ }
+
+ if (strstartswith(path, d->path)) {
+ int ret = find_dir(path, &d->children, rdir);
+ if (ret == NO_MATCH) {
+ *rdir = d;
+ return PARENT_MATCH;
+ }
+ return ret;
+
+ }
+ }
+
+ return NO_MATCH;
+}
+
+static int add_cgroup(const char *fpath, const struct stat *sb, int typeflag)
+{
+ struct cgroup_dir *ncd = NULL, *match;
+ int ret = 0;
+ char pbuf[PATH_MAX], *name, *path;
+
+
+ if (typeflag == FTW_D) {
+ FILE *f;
+ int mtype;
+
+ strncpy(pbuf, fpath, PATH_MAX);
+
+ pr_info("adding cgroup %s\n", fpath);
+
+ ncd = xmalloc(sizeof(*ncd));
+ if(!ncd) {
+ ret = -1;
+ goto out;
+ }
+ ncd->path = NULL;
+
+ name = strstr(fpath, current_controller_name);
+ if (!name) {
+ pr_err("%s has no name component (%s)\n", fpath, current_controller_name);
+ ret = -1;
+ goto out;
+ }
+
+ path = strchr(name, '/');
+ if (!path) {
+ pr_err("Bad path %s\n", name);
+ ret = -1;
+ goto out;
+ }
+
+ ncd->path = xstrdup(path);
+ if (!ncd->path) {
+ ret = -1;
+ goto out;
+ }
+
+ mtype = find_dir(path, ¤t_controller->heads, &match);
+
+ switch(mtype) {
+ /* ignore co-mounted cgroups */
+ case EXACT_MATCH :
+ goto out;
+ case PARENT_MATCH :
+ list_add_tail(&ncd->siblings, &match->children);
+ match->n_children++;
+ break;
+ case NO_MATCH :
+ list_add_tail(&ncd->siblings, ¤t_controller->heads);
+ current_controller->n_heads++;
+ break;
+ }
+
+ INIT_LIST_HEAD(&ncd->children);
+ ncd->n_children = 0;
+ ncd->controller = current_controller;
+
+ ncd->flags = 0;
+
+ snprintf(pbuf, PATH_MAX, "%s/memory.limit_in_bytes", fpath);
+ f = fopen(pbuf, "r");
+ if (f) {
+ if (fscanf(f, "%" SCNu64, &ncd->mem_limit) != 1) {
+ pr_err("Failed scanning %s\n", pbuf);
+ ret = -1;
+ goto out;
+ }
+ ncd->flags |= HAS_MEM_LIMIT;
+ fclose(f);
+ }
+
+ snprintf(pbuf, PATH_MAX, "%s/cpu.shares", fpath);
+ f = fopen(pbuf, "r");
+ if (f) {
+ if (fscanf(f, "%" SCNu32, &ncd->cpu_shares) != 1) {
+ pr_err("Failed scanning %s for u32\n", pbuf);
+ ret = -1;
+ goto out;
+ }
+ ncd->flags |= HAS_CPU_SHARES;
+ fclose(f);
+ }
+
+ return 0;
+ }
+
+out:
+ if (ncd) {
+ if (ncd->path)
+ xfree(ncd->path);
+ xfree(ncd);
+ }
+
+ return ret;
+}
+
+static int collect_cgroups(struct list_head *ctls)
+{
+ struct cg_ctl *cc;
+ int ret = 0;
+
+ list_for_each_entry(cc, ctls, l) {
+ char path[PATH_MAX];
+ char *name, *mount_point;
+ struct cg_controller *cg;
+ int i;
+
+ if (strstartswith(cc->name, "name="))
+ name = cc->name + 5;
+ else
+ name = cc->name;
+
+ mount_point = get_cgroup_mount_point(name);
+ if (!mount_point) {
+ pr_err("cgroup mount point for %s not found!\n", name);
+ return -1;
+ }
+
+ snprintf(path, PATH_MAX, "%s/%s%s", mount_point, name, cc->path);
+
+ current_controller = NULL;
+ current_controller_name = name;
+
+ /* Use the previously allocated struct for this controller if
+ * there is one */
+ list_for_each_entry(cg, &cgroups, l) {
+ for (i = 0; i < cg->n_controllers; i++) {
+ if (strcmp(cg->controllers[i], cc->name) == 0) {
+ current_controller = cg;
+ break;
+ }
+ }
+ }
+
+ if (!current_controller) {
+ /* only allow "fake" controllers to be created this way */
+ if (!strstartswith(cc->name, "name=")) {
+ pr_err("controller %s not found\n", cc->name);
+ return -1;
+ } else {
+ struct cg_controller *nc = new_controller(cc->name, -1);
+ list_add_tail(&nc->l, &cg->l);
+ n_cgroups++;
+ current_controller = nc;
+ }
+ }
+
+ if ((ret = ftw(path, add_cgroup, 4)) < 0) {
+ pr_perror("failed walking %s for empty cgroups\n", path);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
int dump_task_cgroup(struct pstree_item *item, u32 *cg_id)
{
int pid;
@@ -134,6 +400,9 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id)
if (parse_task_cgroup(pid, &ctls, &n_ctls))
return -1;
+ if (item == root_item && collect_cgroups(&ctls) < 0)
+ return -1;
+
cs = get_cg_set(&ctls, n_ctls);
if (!cs)
return -1;
@@ -152,6 +421,74 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id)
return 0;
}
+static int dump_cg_dirs(struct list_head *dirs, size_t n_dirs, CgroupDirEntry ***ents)
+{
+ struct cgroup_dir *cur;
+ CgroupDirEntry *cde;
+ void *m;
+ int i = 0;
+
+ m = xmalloc(n_dirs * (sizeof(CgroupDirEntry *) + sizeof(CgroupDirEntry)));
+ *ents = m;
+ if (!m)
+ return -1;
+
+ cde = m + n_dirs * sizeof(CgroupDirEntry *);
+
+ list_for_each_entry(cur, dirs, siblings) {
+ cgroup_dir_entry__init(cde);
+
+ cde->path = cur->path;
+ cde->has_mem_limit = cur->flags & HAS_MEM_LIMIT;
+ cde->mem_limit = cur->mem_limit;
+ cde->has_cpu_shares = cur->flags & HAS_CPU_SHARES;
+ cde->cpu_shares = cur->cpu_shares;
+
+ cde->n_children = cur->n_children;
+ if (cur->n_children > 0)
+ if (dump_cg_dirs(&cur->children, cur->n_children, &cde->children) < 0) {
+ xfree(*ents);
+ return -1;
+ }
+ (*ents)[i++] = cde++;
+ }
+
+ return 0;
+}
+
+static int dump_controllers(CgroupEntry *cg)
+{
+ struct cg_controller *cur;
+ CgControllerEntry *ce;
+ void *m;
+ int i;
+
+ cg->n_controllers = n_cgroups;
+ m = xmalloc(n_cgroups * (sizeof(CgControllerEntry *) + sizeof(CgControllerEntry)));
+ cg->controllers = m;
+ ce = m + cg->n_controllers * sizeof(CgControllerEntry *);
+ if(!m)
+ return -1;
+
+ i = 0;
+ list_for_each_entry(cur, &cgroups, l) {
+ cg_controller_entry__init(ce);
+
+ ce->controllers = cur->controllers;
+ ce->n_controllers = cur->n_controllers;
+ ce->n_dirs = cur->n_heads;
+ if (ce->n_dirs > 0)
+ if (dump_cg_dirs(&cur->heads, cur->n_heads, &ce->dirs) < 0) {
+ xfree(cg->controllers);
+ return -1;
+ }
+ cg->controllers[i++] = ce++;
+ }
+
+ return 0;
+}
+
+
static int dump_sets(CgroupEntry *cg)
{
struct cg_set *set;
@@ -242,6 +579,8 @@ int dump_cgroups(void)
if (dump_sets(&cg))
return -1;
+ if (dump_controllers(&cg))
+ return -1;
pr_info("Writing CG image\n");
return pb_write_one(fdset_fd(glob_fdset, CR_FD_CGROUP), &cg, PB_CGROUP);
@@ -323,6 +662,57 @@ void fini_cgroup(void)
xfree(cg_yard);
}
+static int prepare_cgroup_dirs(char* paux, size_t off, CgroupDirEntry **ents, size_t n_ents)
+{
+ size_t i, my_off;
+ CgroupDirEntry *e;
+
+ for (i = 0; i < n_ents; i++) {
+ e = ents[i];
+
+ my_off = sprintf(paux + off, "/%s", e->path);
+
+ if (mkdirp(paux)) {
+ pr_perror("Can't make cgroup dir %s", paux);
+ return -1;
+ }
+
+ if (e->has_mem_limit) {
+ FILE *f;
+
+ sprintf(paux + my_off + off, "/memory.limit_in_bytes");
+
+ f = fopen(paux, "w+");
+ if (!f) {
+ pr_perror("Couldn't open %s for writing\n", paux);
+ return -1;
+ }
+
+ fprintf(f, "%" SCNu64, e->mem_limit);
+ fclose(f);
+ }
+
+ if (e->has_cpu_shares) {
+ FILE *f;
+
+ sprintf(paux + my_off + off, "/cpu.shares");
+
+ f = fopen(paux, "w+");
+ if (!f) {
+ pr_perror("Couldn't open %s for writing\n", paux);
+ return -1;
+ }
+
+ fprintf(f, "%" SCNu32, e->cpu_shares);
+ fclose(f);
+ }
+
+ prepare_cgroup_dirs(paux, off, e->children, e->n_children);
+ }
+
+ return 0;
+}
+
/*
* Prepare the CGROUP_YARD service descriptor. This guy is
* tmpfs mount with the set of ctl->name directories each
@@ -341,10 +731,10 @@ void fini_cgroup(void)
* them in advance.
*/
-static int prepare_cgroup_sfd(CgSetEntry *root_set)
+static int prepare_cgroup_sfd(CgroupEntry *ce)
{
int off, i;
- char paux[PATH_MAX], aux[128];
+ char paux[PATH_MAX];
pr_info("Preparing cgroups yard\n");
@@ -370,26 +760,45 @@ static int prepare_cgroup_sfd(CgSetEntry *root_set)
goto err;
}
- for (i = 0; i < root_set->n_ctls; i++) {
- CgMemberEntry *ce = root_set->ctls[i];
- char *opt = ce->name;
+ for (i = 0; i < ce->n_controllers; i++) {
+ CgControllerEntry *ctrl = ce->controllers[i];
+ int j, name_off, opt_off;
+ char *name, opt[1024];
+
+ if (ctrl->n_controllers < 1) {
+ pr_err("Each cg_controller_entry must have at least 1 controller");
+ goto err;
+ }
+
+ if (strstartswith(ctrl->controllers[0], "name=")) {
+ name = ctrl->controllers[0] + 5;
+ opt_off = sprintf(opt, "none,%s", ctrl->controllers[0]);
+ } else {
+ name = ctrl->controllers[0];
+ opt_off = sprintf(opt, "%s", ctrl->controllers[0]);
+ }
+
+ for (j = 1; j < ctrl->n_controllers; j++)
+ {
+ name = ctrl->controllers[i];
+ opt_off += sprintf(opt + opt_off, ",%s", ctrl->controllers[i]);
+ }
- if (strstartswith(ce->name, "name=")) {
- sprintf(paux + off, "/%s", ce->name + 5);
- sprintf(aux, "none,%s", ce->name);
- opt = aux;
- } else
- sprintf(paux + off, "/%s", ce->name);
+ name_off = sprintf(paux + off, "/%s", name);
if (mkdir(paux, 0700)) {
- pr_perror("Can't make cgyard subdir");
+ pr_perror("Can't make cgyard subdir %s", paux);
goto err;
}
if (mount("none", paux, "cgroup", 0, opt) < 0) {
- pr_perror("Can't mount %s cgyard", ce->name);
+ pr_perror("Can't mount %s cgyard", paux);
goto err;
}
+
+ if(prepare_cgroup_dirs(paux, off + name_off, ctrl->dirs, ctrl->n_dirs))
+ goto err;
+
}
pr_debug("Opening %s as cg yard\n", cg_yard);
@@ -431,15 +840,5 @@ int prepare_cgroup(void)
n_sets = ce->n_sets;
rst_sets = ce->sets;
- if (n_sets)
- /*
- * We rely on the fact that all sets contain the same
- * set of controllers. This is checked during dump
- * with cg_set_compare(CGCMP_ISSUB) call.
- */
- ret = prepare_cgroup_sfd(rst_sets[0]);
- else
- ret = 0;
-
- return ret;
+ return prepare_cgroup_sfd(ce);
}
diff --git a/cr-dump.c b/cr-dump.c
index 45f1f5f..d8ad0fc 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1776,6 +1776,9 @@ int cr_dump_tasks(pid_t pid)
if (vdso_init())
goto err;
+ if (parse_cg_info())
+ goto err;
+
if (write_img_inventory())
goto err;
diff --git a/include/cgroup.h b/include/cgroup.h
index 148b26f..172a8d1 100644
--- a/include/cgroup.h
+++ b/include/cgroup.h
@@ -1,6 +1,7 @@
#ifndef __CR_CGROUP_H__
#define __CR_CGROUP_H__
#include "asm/int.h"
+#include "list.h"
struct pstree_item;
extern u32 root_cg_set;
int dump_task_cgroup(struct pstree_item *, u32 *);
@@ -8,4 +9,49 @@ int dump_cgroups(void);
int prepare_task_cgroup(struct pstree_item *);
int prepare_cgroup(void);
void fini_cgroup(void);
+
+#define HAS_MEM_LIMIT (1 << 0)
+#define HAS_CPU_SHARES (1 << 1)
+
+struct cg_controller;
+
+/* This describes a particular cgroup path, e.g. the '/lxc/u1' part of
+ * 'blkio/lxc/u1' and any properties it has.
+ */
+struct cgroup_dir {
+ char *path;
+ u64 mem_limit;
+ u32 cpu_shares;
+ unsigned int flags;
+
+ /* this is how children are linked together */
+ struct list_head siblings;
+
+ /* more cgroup_dirs */
+ struct list_head children;
+ unsigned int n_children;
+
+ struct cg_controller *controller;
+};
+
+/* This describes a particular cgroup controller, e.g. blkio or cpuset.
+ * The heads are subdirectories organized in their tree format.
+ */
+struct cg_controller {
+ int heirarchy;
+ unsigned int n_controllers;
+ char **controllers;
+
+ /* cgroup_dirs */
+ struct list_head heads;
+ unsigned int n_heads;
+
+ /* for cgroup list in cgroup.c */
+ struct list_head l;
+};
+struct cg_controller *new_controller(const char *name, int heirarchy);
+
+/* parse all global cgroup information into structures */
+int parse_cg_info();
+
#endif /* __CR_CGROUP_H__ */
diff --git a/include/proc_parse.h b/include/proc_parse.h
index b153328..ff1ea5d 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -5,6 +5,7 @@
#include "asm/types.h"
#include "image.h"
#include "list.h"
+#include "cgroup.h"
#include "protobuf/eventfd.pb-c.h"
#include "protobuf/eventpoll.pb-c.h"
@@ -203,4 +204,6 @@ struct cg_ctl {
extern int parse_task_cgroup(int pid, struct list_head *l, unsigned int *n);
extern void put_ctls(struct list_head *);
+int parse_cgroups(struct list_head *cgroups, unsigned int *n_cgroups);
+
#endif /* __CR_PROC_PARSE_H__ */
diff --git a/include/util.h b/include/util.h
index 22a0f3d..3dc1b1b 100644
--- a/include/util.h
+++ b/include/util.h
@@ -288,7 +288,7 @@ int vaddr_to_pfn(unsigned long vaddr, u64 *pfn);
/*
* Check whether @str starts with @sub
*/
-static inline bool strstartswith(char *str, char *sub)
+static inline bool strstartswith(const char *str, char *sub)
{
while (1) {
if (*sub == '\0') /* end of sub -- match */
@@ -303,4 +303,9 @@ static inline bool strstartswith(char *str, char *sub)
}
}
+/*
+ * mkdir -p
+ */
+int mkdirp(const char* path);
+
#endif /* __CR_UTIL_H__ */
diff --git a/mount.c b/mount.c
index 4d84f48..32410eb 100644
--- a/mount.c
+++ b/mount.c
@@ -861,6 +861,9 @@ static struct fstype fstypes[] = {
}, {
.name = "debugfs",
.code = FSTYPE__DEBUGFS,
+ }, {
+ .name = "cgroup",
+ .code = FSTYPE__CGROUP,
}
};
diff --git a/proc_parse.c b/proc_parse.c
index f2ea897..53877e3 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -1547,7 +1547,7 @@ int parse_task_cgroup(int pid, struct list_head *retl, unsigned int *n)
}
list_for_each_entry(cc, retl, l)
- if (strcmp(cc->name, name) >= 0)
+ if (strcmp(cc->name, name) >= 0 && strcmp(cc->path, path) >= 0)
break;
list_add_tail(&ncc->l, &cc->l);
@@ -1573,3 +1573,76 @@ void put_ctls(struct list_head *l)
xfree(c);
}
}
+
+
+/* Parse and create all the real controllers. This does not include things with
+ * the "name=" prefix, e.g. systemd.
+ */
+int parse_cgroups(struct list_head *cgroups, unsigned int *n_cgroups)
+{
+ FILE *f;
+ char buf[1024], name[1024];
+ int heirarchy, ret = 0;
+ struct cg_controller *cur = NULL;
+
+ f = fopen("/proc/cgroups", "r");
+ if (!f) {
+ pr_perror("failed opening /proc/cgroups");
+ return -1;
+ }
+
+ /* throw away the header */
+ if (!fgets(buf, 1024, f)) {
+ ret = -1;
+ goto out;
+ }
+
+ while(fgets(buf, 1024, f)) {
+ char *n;
+ char found = 0;
+
+ sscanf(buf, "%s %d", name, &heirarchy);
+ list_for_each_entry(cur, cgroups, l) {
+ if (cur->heirarchy == heirarchy) {
+ void *m;
+
+ found = 1;
+ cur->n_controllers++;
+ m = xrealloc(cur->controllers, sizeof(char*) * cur->n_controllers);
+ if(!m) {
+ ret = -1;
+ goto out;
+ }
+
+ cur->controllers = m;
+ if (!cur->controllers) {
+ ret = -1;
+ goto out;
+ }
+
+ n = xstrdup(name);
+ if (!n) {
+ ret = -1;
+ goto out;
+ }
+
+ cur->controllers[cur->n_controllers-1] = n;
+ break;
+ }
+ }
+
+ if (!found) {
+ struct cg_controller *nc = new_controller(name, heirarchy);
+ if (!nc) {
+ ret = -1;
+ goto out;
+ }
+ list_add_tail(&nc->l, &cur->l);
+ (*n_cgroups)++;
+ }
+ }
+
+out:
+ fclose(f);
+ return ret;
+}
diff --git a/protobuf/cgroup.proto b/protobuf/cgroup.proto
index 139a3ad..4be2249 100644
--- a/protobuf/cgroup.proto
+++ b/protobuf/cgroup.proto
@@ -1,3 +1,16 @@
+message cgroup_dir_entry {
+ required string path = 1;
+ optional uint64 mem_limit = 2;
+ optional uint32 cpu_shares = 3;
+ repeated cgroup_dir_entry children = 4;
+}
+
+message cg_controller_entry {
+ required uint32 id = 1;
+ repeated string controllers = 2;
+ repeated cgroup_dir_entry dirs = 3;
+}
+
message cg_member_entry {
required string name = 1;
required string path = 2;
@@ -9,5 +22,6 @@ message cg_set_entry {
}
message cgroup_entry {
- repeated cg_set_entry sets = 1;
+ repeated cg_set_entry sets = 1;
+ repeated cg_controller_entry controllers = 2;
}
diff --git a/protobuf/mnt.proto b/protobuf/mnt.proto
index 63532ee..603bb37 100644
--- a/protobuf/mnt.proto
+++ b/protobuf/mnt.proto
@@ -11,6 +11,7 @@ enum fstype {
SECURITYFS = 9;
FUSECTL = 10;
DEBUGFS = 11;
+ CGROUP = 12;
};
message mnt_entry {
diff --git a/util.c b/util.c
index d697f7a..d4033c9 100644
--- a/util.c
+++ b/util.c
@@ -678,3 +678,37 @@ struct vma_area *alloc_vma_area(void)
return p;
}
+
+int mkdirp(const char* path)
+{
+ size_t i;
+ char made_path[PATH_MAX], *pos;
+
+ if (strlen(path) >= PATH_MAX) {
+ pr_err("path %s is longer than PATH_MAX", path);
+ return -1;
+ }
+
+ strcpy(made_path, path);
+
+ i = 0;
+ if (strchr(made_path, '/') == made_path)
+ i++;
+
+ for (; i < strlen(made_path); i++) {
+ pos = strchr(made_path + i, '/');
+ if (pos)
+ *pos = '\0';
+ if (mkdir(made_path, 0755) < 0 && errno != EEXIST) {
+ pr_perror("couldn't mkdirpat directory\n");
+ return -1;
+ }
+ if (pos) {
+ *pos = '/';
+ i = pos - made_path;
+ } else
+ break;
+ }
+
+ return 0;
+}
--
1.9.1
More information about the CRIU
mailing list