[CRIU] [PATCH] cg: Use relative paths in cgroup dirs image

Pavel Emelyanov xemul at parallels.com
Wed Aug 13 02:34:22 PDT 2014


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 at parallels.com>
---
 cgroup.c              | 19 +++++++++----------
 protobuf/cgroup.proto |  2 +-
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/cgroup.c b/cgroup.c
index 8308413..1f38c4d 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -641,7 +641,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;
@@ -657,12 +657,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;
 			}
@@ -704,7 +702,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;
 			}
@@ -930,7 +928,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;
@@ -940,7 +938,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;
 	}
@@ -975,6 +973,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
@@ -982,7 +981,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;
 			}
 		}
@@ -1023,7 +1022,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
diff --git a/protobuf/cgroup.proto b/protobuf/cgroup.proto
index fcd5834..2084388 100644
--- a/protobuf/cgroup.proto
+++ b/protobuf/cgroup.proto
@@ -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;
 }
-- 
1.8.4.2



More information about the CRIU mailing list