[CRIU] [PATCH 2/2] cg: Don't copy path when restoring properties

Pavel Emelyanov xemul at parallels.com
Tue Aug 12 07:18:04 PDT 2014


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 cgroup.c | 51 ++++++++-------------------------------------------
 1 file changed, 8 insertions(+), 43 deletions(-)

diff --git a/cgroup.c b/cgroup.c
index a5433cd..0a4fd21 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -933,9 +933,8 @@ void fini_cgroup(void)
 }
 
 static int restore_cgroup_prop(const CgroupPropEntry * cg_prop_entry_p,
-			       const char *cname, const char *dir)
+			       char *path, int off, const char *dir)
 {
-	char path[PATH_MAX];
 	FILE *f;
 	int cg;
 
@@ -944,7 +943,7 @@ static int restore_cgroup_prop(const CgroupPropEntry * cg_prop_entry_p,
 		return -1;
 	}
 
-	if (snprintf(path, PATH_MAX, "%s/%s/%s", cname, dir, cg_prop_entry_p->name) >= PATH_MAX) {
+	if (snprintf(path + off, PATH_MAX - off, "/%s/%s", dir, cg_prop_entry_p->name) >= PATH_MAX) {
 		pr_err("snprintf output was truncated for %s\n", cg_prop_entry_p->name);
 		return -1;
 	}
@@ -971,7 +970,7 @@ static int restore_cgroup_prop(const CgroupPropEntry * cg_prop_entry_p,
 	return 0;
 }
 
-static int prepare_cgroup_dir_properties(char *controller, CgroupDirEntry **ents,
+static int prepare_cgroup_dir_properties(char *path, int off, CgroupDirEntry **ents,
 					 unsigned int n_ents)
 {
 	unsigned int i, j;
@@ -986,54 +985,22 @@ static int prepare_cgroup_dir_properties(char *controller, CgroupDirEntry **ents
 		 */
 		if (e->properties) {
 			for (j = 0; j < e->n_properties; ++j) {
-				if (restore_cgroup_prop(e->properties[j], controller, e->path) < 0)
+				if (restore_cgroup_prop(e->properties[j], path, off, e->path) < 0)
 					return -1;
 			}
 		}
 
-		if (prepare_cgroup_dir_properties(controller, e->children, e->n_children) < 0)
+		if (prepare_cgroup_dir_properties(path, off, e->children, e->n_children) < 0)
 			return -1;
 	}
 
 	return 0;
 }
 
-static int get_controller_path(char *cname_path, int size, CgControllerEntry *c)
-{
-	int i;
-	int cnt = 0;
-	int n = strlen(c->cnames[0]);
-
-	if (n >= size - cnt) {
-		pr_err("Ran out of room for cname_path\n");
-		return -1;
-	}
-	strcpy(&cname_path[cnt], c->cnames[0]);
-	cnt += n;
-
-	/*
-	 * Co-Mounted Case
-	 * adds on other controllers for full path, ie. "cpu,cpuacct"
-	 */
-	for (i = 1; i < c->n_cnames; ++i) {
-		n = strlen(c->cnames[i]);
-		/* +1 for comma */
-		if (n + 1 >= size - cnt) {
-			pr_err("Ran out of room for cname_path\n");
-			return -1;
-		}
-		cname_path[cnt++] = ',';
-		strcpy(&cname_path[cnt], c->cnames[i]);
-		cnt += n;
-	}
-
-	return 0;
-}
-
 int prepare_cgroup_properties(void)
 {
 	char cname_path[PATH_MAX];
-	unsigned int i;
+	unsigned int i, off;
 
 	for (i = 0; i < n_controllers; i++) {
 		CgControllerEntry *c = controllers[i];
@@ -1043,10 +1010,8 @@ int prepare_cgroup_properties(void)
 			return -1;
 		}
 
-		if (get_controller_path(cname_path, PATH_MAX, c) < 0)
-			return -1;
-
-		if (prepare_cgroup_dir_properties(cname_path, c->dirs, c->n_dirs) < 0)
+		off = ctrl_dir_and_opt(c, cname_path, sizeof(cname_path), NULL, 0);
+		if (prepare_cgroup_dir_properties(cname_path, off, c->dirs, c->n_dirs) < 0)
 			return -1;
 	}
 
-- 
1.8.4.2




More information about the CRIU mailing list