[CRIU] Re: [PATCH 06/12] parasite: Add interface for file descriptors draining

Pavel Emelyanov xemul at parallels.com
Tue Mar 27 08:50:12 EDT 2012


> @@ -605,6 +605,57 @@ out:
>  	return ret;
>  }
>  
> +int parasite_drain_fds_seized(struct parasite_ctl *ctl, int *fds, int *lfds, int nr_fds)
> +{
> +	struct parasite_drain_fd args	= { };

I wouldn't allocate that much stack.

> +	parasite_status_t *st		= &args.status;
> +	int ret = -1;
> +	int sock, i;
> +
> +	args.sun_len = gen_parasite_saddr(&args.saddr, (int)-2u);
> +	args.nr_fds = nr_fds;
> +
> +	sock = socket(PF_UNIX, SOCK_DGRAM, 0);
> +	if (sock < 0) {
> +		pr_perror("Can't create socket");
> +		return -1;
> +	}
> +
> +	ret = bind(sock, (struct sockaddr *)&args.saddr, args.sun_len);
> +	if (ret < 0) {
> +		pr_perror("Can't bind socket");
> +		goto err;
> +	}
> +
> +	memcpy(&args.fds, fds, sizeof(int) * nr_fds);
> +
> +	ret = parasite_execute(PARASITE_CMD_DRAIN_FDS, ctl, st, sizeof(args));
> +	if (ret) {
> +		pr_err("Parasite failed to drain descriptors\n");
> +		goto err;
> +	}
> +
> +	ret = recv_fds(sock, lfds, nr_fds);
> +	if (ret) {
> +		pr_err("Can't retrieve FDs from socket\n");
> +		goto err;
> +	}
> +
> +	/* Verify the descriptors do match */
> +	for (i = 0; i < nr_fds; i++) {
> +		pid_t me = getpid();
> +		if (sys_kcmp(me, ctl->pid, KCMP_FILE, fds[i], lfds[i])) {

I.e. me's fds[i] should be equal to other's lfds[i], meanwhile the fds array
contains other's descriptors and the lfds one -- locally received ones.

How does it work?

> +			pr_err("File descriptors mismatch: (%d) %d (%d) %d\n",
> +				me, ctl->pid, fds[i], lfds[i]);
> +		}
> +	}
> +
> +	ret = 0;
> +err:
> +	close(sock);
> +	return ret;
> +}


More information about the CRIU mailing list