[CRIU] [PATCH RFC 02/30] files: Create per-process transport sock and bind it
Andrei Vagin
avagin at virtuozzo.com
Tue Nov 1 22:28:10 PDT 2016
I think it would be better to explain why we need a per-process socket.
On Tue, Nov 01, 2016 at 05:30:36PM +0300, Kirill Tkhai wrote:
> Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
> ---
> criu/cr-restore.c | 6 ------
> criu/files.c | 18 ++++++++++++++++--
> criu/include/files.h | 2 --
> 3 files changed, 16 insertions(+), 10 deletions(-)
>
> diff --git a/criu/cr-restore.c b/criu/cr-restore.c
> index 3abdea8..1b88dce 100644
> --- a/criu/cr-restore.c
> +++ b/criu/cr-restore.c
> @@ -270,10 +270,6 @@ static int root_prepare_shared(void)
> if (ret)
> goto err;
>
> - ret = open_transport_socket();
> - if (ret)
> - goto err;
> -
> show_saved_files();
> err:
> return ret;
> @@ -714,8 +710,6 @@ static int restore_one_alive_task(int pid, CoreEntry *core)
> if (prepare_vmas(current, ta))
> return -1;
>
> - close_service_fd(TRANSPORT_FD_OFF);
> -
> if (setup_uffd(pid, ta))
> return -1;
>
> diff --git a/criu/files.c b/criu/files.c
> index 21af891..e869614 100644
> --- a/criu/files.c
> +++ b/criu/files.c
> @@ -1149,6 +1149,8 @@ int close_old_fds(void)
> return 0;
> }
>
> +static int open_transport_socket(pid_t pid);
> +
> int prepare_fds(struct pstree_item *me)
> {
> u32 ret = 0;
> @@ -1183,6 +1185,9 @@ int prepare_fds(struct pstree_item *me)
> }
> }
>
> + if (open_transport_socket(me->pid.virt))
> + return -1;
> +
> for (state = 0; state < ARRAY_SIZE(states); state++) {
> if (!states[state].required) {
> pr_debug("Skipping %s fd stage\n", states[state].name);
> @@ -1231,6 +1236,7 @@ int prepare_fds(struct pstree_item *me)
> out_w:
> if (rsti(me)->fdt)
> futex_inc_and_wake(&rsti(me)->fdt->fdt_lock);
> + close_service_fd(TRANSPORT_FD_OFF);
> out:
> close_service_fd(CR_PROC_FD_OFF);
> tty_fini_fds();
> @@ -1663,15 +1669,23 @@ int inherit_fd_fini()
> return 0;
> }
>
> -int open_transport_socket()
> +static int open_transport_socket(pid_t pid)
> {
> - int sock;
> + struct sockaddr_un saddr;
> + int sock, slen;
>
> sock = socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
> if (sock < 0) {
> pr_perror("Can't create socket");
> return -1;
> }
> +
> + transport_name_gen(&saddr, &slen, pid, -1);
> + if (bind(sock, (struct sockaddr *)&saddr, slen) < 0) {
> + pr_perror("Can't bind transport socket %s", saddr.sun_path + 1);
> + return -1;
> + }
> +
> if (install_service_fd(TRANSPORT_FD_OFF, sock) < 0) {
> close(sock);
> return -1;
> diff --git a/criu/include/files.h b/criu/include/files.h
> index 153e7b3..2cd1a67 100644
> --- a/criu/include/files.h
> +++ b/criu/include/files.h
> @@ -189,6 +189,4 @@ extern FdinfoEntry *dup_fdinfo(FdinfoEntry *old, int fd, unsigned flags);
> int dup_fle(struct pstree_item *task, struct fdinfo_list_entry *ple,
> int fd, unsigned flags);
>
> -extern int open_transport_socket(void);
> -
> #endif /* __CR_FILES_H__ */
>
More information about the CRIU
mailing list