[CRIU] [PATCH 2/3] Add restore for unnamed unix sockets

Pavel Emelyanov xemul at parallels.com
Wed Jul 29 01:58:21 PDT 2015


> 
> @@ -1404,6 +1404,19 @@ static int inherit_fd_lookup_id(char *id)
> 
>                return ret;
> 
> }
> 
>  
> 
> +bool inherit_fd_lookup_desc(struct file_desc *d)

Unused in this patch.

> 
> +{
> 
> +             char buf[32], *id_str;
> 
> +
> 
> +             if (!d->ops->name)
> 
> +                             return -1;
> 
> +
> 
> +             id_str = d->ops->name(d, buf, sizeof(buf));
> 
> +             int ret = inherit_fd_lookup_id(id_str);
> 
> +
> 
> +             return (ret < 0 ? false : true);
> 
> +}
> 
> +
> 
> bool inherited_fd(struct file_desc *d, int *fd_p)
> 
> {
> 
>                char buf[32], *id_str;
> 
> @@ -1421,12 +1434,10 @@ bool inherited_fd(struct file_desc *d, int *fd_p)
> 
>                                return true;
> 
>  
> 
>                *fd_p = dup(i_fd);
> 
> -              if (*fd_p < 0) {
> 
> +             if (*fd_p < 0)
> 
>                                pr_perror("Inherit fd DUP failed");
> 
> -                              return false;
> 
> -              }
> 
>                else
> 
> -                              pr_info("File %s will be restored from fd %d duped "
> 
> +                             pr_info("File %s will be restored from fd %d dumped "

Same as with patch #1 -- all enhancements in the inherited_fd() deserve separate patch.

> 
>                                                                "from inherit fd %d\n", id_str, *fd_p, i_fd);
> 
>                return true;
> 
> }
> 

> @@ -718,21 +717,23 @@ static int post_open_unix_sk(struct file_desc *d, int fd)
> 
>                if (ui->ue->uflags & USK_CALLBACK)
> 
>                                return 0;
> 
>  
> 
> -              pr_info("\tConnect %#x to %#x\n", ui->ue->ino, peer->ue->ino);
> 
> -
> 
>                /* Skip external sockets */
> 
>                if (!list_empty(&peer->d.fd_info_head))
> 
>                                futex_wait_while(&peer->prepared, 0);
> 
>  
> 
> -              memset(&addr, 0, sizeof(addr));
> 
> -              addr.sun_family = AF_UNIX;
> 
> -              memcpy(&addr.sun_path, peer->name, peer->ue->name.len);
> 
> +             if (!(ui->ue->uflags & USK_INHERIT)) {

I think we should avoid _any_ actions in post_open for inherited sockets, not
only connect().

> 
> +                             memset(&addr, 0, sizeof(addr));
> 
> +                             addr.sun_family = AF_UNIX;
> 
> +                             memcpy(&addr.sun_path, peer->name, peer->ue->name.len);
> 
>  
> 
> -              if (connect(fd, (struct sockaddr *)&addr,
> 
> -                                                              sizeof(addr.sun_family) +
> 
> -                                                              peer->ue->name.len) < 0) {
> 
> -                              pr_perror("Can't connect %#x socket", ui->ue->ino);
> 
> -                              return -1;
> 
> +                             pr_info("\tConnect %#x to %#x\n", ui->ue->ino, peer->ue->ino);
> 
> +
> 
> +                             if (connect(fd, (struct sockaddr *)&addr,
> 
> +                                                                             sizeof(addr.sun_family) +
> 
> +                                                                             peer->ue->name.len) < 0) {
> 
> +                                             pr_perror("Can't connect %#x socket", ui->ue->ino);
> 
> +                                             return -1;
> 
> +                             }
> 
>                }
> 
>  
> 
>                if (restore_sk_queue(fd, peer->ue->id))
> 



More information about the CRIU mailing list