[CRIU] Re: [PATCH cr 09/12] pipes: add functions to restore pipes
Pavel Emelyanov
xemul at parallels.com
Thu Apr 5 08:07:10 EDT 2012
On 04/05/2012 03:47 PM, Andrey Vagin wrote:
>
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
> files.c | 5 ++
> include/files.h | 4 ++
> pipes.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 133 insertions(+), 0 deletions(-)
>
> +int open_pipe(struct list_head *l)
> +{
> + unsigned long time = 1000;
> + struct pipe_info *pi, *pc, *p;
> + int ret, tmp;
> + int pfd[2];
> + int sock;
> + int create;
> +
> + pi = container_of(l, struct pipe_info, fd_head);
> +
> + pr_info("\tCreating pipe pipe_id=%x id=%x\n", pi->pe.pipe_id, pi->pe.id);
> +
> + if (!pi->create)
> + return recv_pipe_fd(pi);
> +
> + if (pipe(pfd) < 0) {
> + pr_perror("Can't create pipe");
> + return -1;
> + }
> +
> + sock = socket(PF_UNIX, SOCK_DGRAM, 0);
> + if (sock < 0) {
> + pr_perror("Can't create socket");
> + return -1;
> + }
> +
> + list_for_each_entry(p, &pi->pipe_list, pipe_list) {
> + int len, fd;
> + struct sockaddr_un saddr;
> + struct fdinfo_list_entry *fle;
> +
> + BUG_ON(list_empty(&p->fd_head));
> + fle = list_first_entry(&p->fd_head,
> + struct fdinfo_list_entry, list);
> +
> + pr_info("\t\tWait fdinfo pid=%d fd=%d\n", fle->pid, fle->fd);
> + futex_wait_while(&fle->real_pid, 0);
> +
> + transport_name_gen(&saddr, &len,
> + futex_get(&fle->real_pid), fle->fd);
> +
> + fd = pfd[p->pe.flags & O_WRONLY];
> +
> + pr_info("\t\tSend fd %d to %s\n", fd, saddr.sun_path + 1);
> +
> + if (send_fd(sock, &saddr, len, fd) < 0) {
This looks strange. You send an fd to other task to make it re-open it in
his /proc/pid/fd. Why not just make it open ours /proc/pid/fd ?
> + pr_perror("Can't send file descriptor");
> + return -1;
> + }
> + }
> +
> + close(sock);
> +
> +out:
> + close(pfd[!(pi->pe.flags & O_WRONLY)]);
> + tmp = pfd[pi->pe.flags & O_WRONLY];
> + ret = set_fd_flags(tmp, pi->pe.flags);
> + if (ret < 0)
> + return -1;
> +
> + return tmp;
> +}
More information about the CRIU
mailing list