[CRIU] [PATCH] Attempt to restore cgroups

Cyrill Gorcunov gorcunov at gmail.com
Tue Jul 1 09:30:13 PDT 2014


On Tue, Jul 01, 2014 at 01:36:04PM +0000, Tycho Andersen wrote:
> 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>

Hi Tycho, well done! A few comments below

...

> +int parse_cgroups()
> +{
> +	FILE *f = fopen("/proc/cgroups", "r");
> +	char buf[1024], name[1024];
> +	uint32_t heirarchy;
> +	struct cg_controller *cur = NULL;
> +
> +	if (!f) {
> +		pr_perror("failed opening /proc/cgroups");
> +		return -1;
> +	}
> +
> +	/* throw away the header */
> +	if (!fgets(buf, 1024, f))
> +		return 0;
> +
> +	while(fgets(buf, 1024, f))
> +	{

Lets follow kernel style and place '{' on while() line (same for if() statement)

> +
> +int mkdirp(const char* path)
> +{
> +	char* tok;
> +	char made_path[PATH_MAX] = "", tok_path[PATH_MAX];
> +
> +	if (strlen(path) >= PATH_MAX)
> +	{
> +		pr_err("path %s is longer than PATH_MAX", path);
> +		return -1;
> +	}
> +
> +	strncpy(tok_path, path, PATH_MAX);
> +
> +	for(tok = strtok(tok_path, "/"); tok; tok = strtok(NULL, "/")) {
> +		strcat(made_path, tok);
> +		strcat(made_path, "/");

strcat really a longtime operation which tossing memory around, maybe
we can use strchr helper instead, like

	for (i = 0; i < strlen(path); i++) {
		char *pos = strchr(&path[i], '/');
		if (!pos)
			break;
		*pos = '\0';
		mkdir(made_path, 0755) < 0 && errno != EEXIST
		i = pos - path + 1;
	}

? OTOH I can live with strtok as well :)


More information about the CRIU mailing list