Commit bcd16496 authored by Pavel Emelyanov's avatar Pavel Emelyanov

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: 's avatarPavel Emelyanov <xemul@parallels.com>
Acked-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
parent bf91821f
...@@ -644,7 +644,7 @@ error: ...@@ -644,7 +644,7 @@ error:
return -1; 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; struct cgroup_dir *cur;
CgroupDirEntry *cde; CgroupDirEntry *cde;
...@@ -660,12 +660,10 @@ static int dump_cg_dirs(struct list_head *dirs, size_t n_dirs, CgroupDirEntry ** ...@@ -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) { list_for_each_entry(cur, dirs, siblings) {
cgroup_dir_entry__init(cde); cgroup_dir_entry__init(cde);
cde->dir_name = cur->path + poff + 1 /* leading / */;
cde->path = cur->path;
cde->n_children = cur->n_children; cde->n_children = cur->n_children;
if (cur->n_children > 0) 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); xfree(*ents);
return -1; return -1;
} }
...@@ -707,7 +705,7 @@ static int dump_controllers(CgroupEntry *cg) ...@@ -707,7 +705,7 @@ static int dump_controllers(CgroupEntry *cg)
ce->n_cnames = cur->n_controllers; ce->n_cnames = cur->n_controllers;
ce->n_dirs = cur->n_heads; ce->n_dirs = cur->n_heads;
if (ce->n_dirs > 0) 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); xfree(cg->controllers);
return -1; return -1;
} }
...@@ -933,7 +931,7 @@ void fini_cgroup(void) ...@@ -933,7 +931,7 @@ void fini_cgroup(void)
} }
static int restore_cgroup_prop(const CgroupPropEntry * cg_prop_entry_p, static int restore_cgroup_prop(const CgroupPropEntry * cg_prop_entry_p,
char *path, int off, const char *dir) char *path, int off)
{ {
FILE *f; FILE *f;
int cg; int cg;
...@@ -943,7 +941,7 @@ static int restore_cgroup_prop(const CgroupPropEntry * cg_prop_entry_p, ...@@ -943,7 +941,7 @@ static int restore_cgroup_prop(const CgroupPropEntry * cg_prop_entry_p,
return -1; 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); pr_err("snprintf output was truncated for %s\n", cg_prop_entry_p->name);
return -1; return -1;
} }
...@@ -978,6 +976,7 @@ static int prepare_cgroup_dir_properties(char *path, int off, CgroupDirEntry **e ...@@ -978,6 +976,7 @@ static int prepare_cgroup_dir_properties(char *path, int off, CgroupDirEntry **e
for (i = 0; i < n_ents; i++) { for (i = 0; i < n_ents; i++) {
CgroupDirEntry *e = 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 * Check to see if we made e->properties NULL during restore
* because directory already existed and as such we don't want to * 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 ...@@ -985,7 +984,7 @@ static int prepare_cgroup_dir_properties(char *path, int off, CgroupDirEntry **e
*/ */
if (e->properties) { if (e->properties) {
for (j = 0; j < e->n_properties; ++j) { 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; return -1;
} }
} }
...@@ -1026,7 +1025,7 @@ static int prepare_cgroup_dirs(char *paux, size_t off, CgroupDirEntry **ents, si ...@@ -1026,7 +1025,7 @@ static int prepare_cgroup_dirs(char *paux, size_t off, CgroupDirEntry **ents, si
for (i = 0; i < n_ents; i++) { for (i = 0; i < n_ents; i++) {
e = 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 * Checking to see if file already exists. If not, create it. If
......
...@@ -4,7 +4,7 @@ message cgroup_prop_entry { ...@@ -4,7 +4,7 @@ message cgroup_prop_entry {
} }
message cgroup_dir_entry { message cgroup_dir_entry {
required string path = 1; required string dir_name = 1;
repeated cgroup_dir_entry children = 2; repeated cgroup_dir_entry children = 2;
repeated cgroup_prop_entry properties = 3; repeated cgroup_prop_entry properties = 3;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment