mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-17 16:47:50 +00:00
cg: Use relative paths in cgroup dirs image
Before the patch cg tree section from cgroup00 test looked like this
{
cnames: "name=zdtmtst"
dirs: {
path: "/subcg"
children: {
path: "/subcg/subsubcg"
children: <empty>
properties: <empty>
}
properties: <empty>
}
}
this /subsg in the children is excessive. Turn this into directory names.
Now the section looks like
{
cnames: "name=zdtmtst"
dirs: {
dir_name: "subcg"
children: {
dir_name: "subsubcg"
children: <empty>
properties: <empty>
}
properties: <empty>
}
}
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
This commit is contained in:
parent
bf91821f11
commit
bcd1649699
2 changed files with 10 additions and 11 deletions
19
cgroup.c
19
cgroup.c
|
|
@ -644,7 +644,7 @@ error:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int dump_cg_dirs(struct list_head *dirs, size_t n_dirs, CgroupDirEntry ***ents)
|
||||
static int dump_cg_dirs(struct list_head *dirs, size_t n_dirs, CgroupDirEntry ***ents, int poff)
|
||||
{
|
||||
struct cgroup_dir *cur;
|
||||
CgroupDirEntry *cde;
|
||||
|
|
@ -660,12 +660,10 @@ static int dump_cg_dirs(struct list_head *dirs, size_t n_dirs, CgroupDirEntry **
|
|||
|
||||
list_for_each_entry(cur, dirs, siblings) {
|
||||
cgroup_dir_entry__init(cde);
|
||||
|
||||
cde->path = cur->path;
|
||||
|
||||
cde->dir_name = cur->path + poff + 1 /* leading / */;
|
||||
cde->n_children = cur->n_children;
|
||||
if (cur->n_children > 0)
|
||||
if (dump_cg_dirs(&cur->children, cur->n_children, &cde->children) < 0) {
|
||||
if (dump_cg_dirs(&cur->children, cur->n_children, &cde->children, strlen(cur->path)) < 0) {
|
||||
xfree(*ents);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -707,7 +705,7 @@ static int dump_controllers(CgroupEntry *cg)
|
|||
ce->n_cnames = 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) {
|
||||
if (dump_cg_dirs(&cur->heads, cur->n_heads, &ce->dirs, 0) < 0) {
|
||||
xfree(cg->controllers);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -933,7 +931,7 @@ void fini_cgroup(void)
|
|||
}
|
||||
|
||||
static int restore_cgroup_prop(const CgroupPropEntry * cg_prop_entry_p,
|
||||
char *path, int off, const char *dir)
|
||||
char *path, int off)
|
||||
{
|
||||
FILE *f;
|
||||
int cg;
|
||||
|
|
@ -943,7 +941,7 @@ static int restore_cgroup_prop(const CgroupPropEntry * cg_prop_entry_p,
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (snprintf(path + off, PATH_MAX - off, "/%s/%s", dir, cg_prop_entry_p->name) >= PATH_MAX) {
|
||||
if (snprintf(path + off, PATH_MAX - off, "/%s", cg_prop_entry_p->name) >= PATH_MAX) {
|
||||
pr_err("snprintf output was truncated for %s\n", cg_prop_entry_p->name);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -978,6 +976,7 @@ static int prepare_cgroup_dir_properties(char *path, int off, CgroupDirEntry **e
|
|||
for (i = 0; i < n_ents; i++) {
|
||||
CgroupDirEntry *e = ents[i];
|
||||
|
||||
off += sprintf(path + off, "/%s", e->dir_name);
|
||||
/*
|
||||
* Check to see if we made e->properties NULL during restore
|
||||
* because directory already existed and as such we don't want to
|
||||
|
|
@ -985,7 +984,7 @@ static int prepare_cgroup_dir_properties(char *path, int off, CgroupDirEntry **e
|
|||
*/
|
||||
if (e->properties) {
|
||||
for (j = 0; j < e->n_properties; ++j) {
|
||||
if (restore_cgroup_prop(e->properties[j], path, off, e->path) < 0)
|
||||
if (restore_cgroup_prop(e->properties[j], path, off) < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1026,7 +1025,7 @@ static int prepare_cgroup_dirs(char *paux, size_t off, CgroupDirEntry **ents, si
|
|||
for (i = 0; i < n_ents; i++) {
|
||||
e = ents[i];
|
||||
|
||||
sprintf(paux + off, "/%s", e->path);
|
||||
off += sprintf(paux + off, "/%s", e->dir_name);
|
||||
|
||||
/*
|
||||
* Checking to see if file already exists. If not, create it. If
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ message cgroup_prop_entry {
|
|||
}
|
||||
|
||||
message cgroup_dir_entry {
|
||||
required string path = 1;
|
||||
required string dir_name = 1;
|
||||
repeated cgroup_dir_entry children = 2;
|
||||
repeated cgroup_prop_entry properties = 3;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue