[CRIU] [PATCH] Attempt to restore cgroups

Pavel Emelyanov xemul at parallels.com
Wed Jul 9 07:04:30 PDT 2014


On 07/09/2014 05:47 PM, Tycho Andersen wrote:

> +static int collect_cgroups(struct list_head *ctls)
> +{
> +	struct cg_ctl *cc;
> +	int ret = 0;
> +
> +	list_for_each_entry(cc, ctls, l) {
> +		char path[PATH_MAX];
> +		char *name, mount_point[PATH_MAX], prefix[] = ".criu.cgmounts.XXXXXX";
> +		bool temp_mount = false;
> +		struct cg_controller *cg;
> +		int i;
> +
> +		if (strstartswith(cc->name, "name="))
> +			name = cc->name + 5;
> +		else
> +			name = cc->name;
> +
> +		if (get_cgroup_mount_point(name, mount_point) < 0) {
> +			/* Someone is trying to dump a process that is in
> +			 * a controller that isn't mounted, so we mount it for
> +			 * them.
> +			 */
> +			char opts[1024];
> +			temp_mount = true;
> +
> +			if (mkdtemp(prefix) == NULL) {
> +				pr_perror("can't make dir for cg mounts\n");
> +				return -1;
> +			}
> +
> +			if (name == cc->name)
> +				sprintf(opts, "%s", name);
> +			else
> +				sprintf(opts, "none,%s", cc->name);
> +
> +			if (mount("none", prefix, "cgroup", 0, opts) < 0) {
> +				pr_perror("couldn't mount %s\n", opts);
> +				rmdir(prefix);
> +				return -1;
> +			}
> +
> +			strcpy(mount_point, prefix);
> +		}
> +
> +		snprintf(path, PATH_MAX, "%s/%s", mount_point, cc->path);
> +
> +		current_controller = NULL;
> +
> +		/* We should get all the "real" (i.e. not name=systemd type)
> +		 * controller from parse_cgroups(), so find that controller if
> +		 * it exists. */
> +		list_for_each_entry(cg, &cgroups, l) {
> +			for (i = 0; i < cg->n_controllers; i++) {
> +				if (strcmp(cg->controllers[i], cc->name) == 0) {
> +					current_controller = cg;
> +					break;
> +				}
> +			}
> +		}

Here we have some matching problem. I've applied the patch and run cgroup01 test.
The result is:

Error (cgroup.c:382): cg: controller cpu,cpuacct not found

My cgroups are

# cat /proc/self/cgroup 
...
3:cpu,cpuacct:/
...

# cat /proc/cgroups 
#subsys_name	hierarchy	num_cgroups	enabled
...
cpu	3	1	1
cpuacct	3	1	1
...

One of cg objects correctly has the cg->controllers[0] == "cpu" and
cg->controllers[1] == "cpuacct", but the cc->name is "cpu,cpuacct"
which doesn't match (with strcmp()) with them.




More information about the CRIU mailing list