[CRIU] Re: [PATCH 4/4] cr-restore: read pages to temporary file if
migrating
Pavel Emelyanov
xemul at parallels.com
Wed Aug 15 06:54:12 EDT 2012
On 08/15/2012 01:54 PM, Adrian Reber wrote:
> This is a hack until it is possible to read the pages-*.img directly
> from restorer.c over a network socket. This workaround opens
> a temporary file on /dev/shm which is then used by restorer.c to
> read pages-*.img.
I don't see any code, that closes one and then removes.
> Signed-off-by: Adrian Reber <adrian at lisas.de>
> ---
> cr-restore.c | 51 +++++++++++++++++++++++++++++++++++++++++++--------
> 1 files changed, 43 insertions(+), 8 deletions(-)
>
> diff --git a/cr-restore.c b/cr-restore.c
> index fe07599..f9b8c88 100644
> --- a/cr-restore.c
> +++ b/cr-restore.c
> @@ -1171,7 +1171,6 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core, struct list_head *tgt_v
> struct thread_restore_args *thread_args;
>
> LIST_HEAD(self_vma_list);
> - int fd_pages = -1;
> int i;
>
> pr_info("Restore via sigreturn\n");
> @@ -1195,12 +1194,6 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core, struct list_head *tgt_v
> BUILD_BUG_ON(SHMEMS_SIZE % PAGE_SIZE);
> BUILD_BUG_ON(TASK_ENTRIES_SIZE % PAGE_SIZE);
>
> - fd_pages = open_image_ro(CR_FD_PAGES, pid);
> - if (fd_pages < 0) {
> - pr_perror("Can't open pages-%d", pid);
> - goto err;
> - }
> -
> restore_code_len = sizeof(restorer_blob);
> restore_code_len = round_up(restore_code_len, 16);
>
> @@ -1315,7 +1308,6 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core, struct list_head *tgt_v
> task_args->pid = pid;
> task_args->logfd = log_get_fd();
> task_args->sigchld_act = sigchld_act;
> - task_args->fd_pages = fd_pages;
>
> strncpy(task_args->comm, core->tc->comm, sizeof(task_args->comm));
>
> @@ -1339,6 +1331,49 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core, struct list_head *tgt_v
> if (ret < 0)
> goto err;
>
> + task_args->fd_pages = open_image_ro(CR_FD_PAGES, pid);
> + if (task_args->fd_pages < 0) {
> + pr_perror("Can't open pages-%d", pid);
> + goto err;
> + }
> +
> + /* check if we are running in network migration mode */
> + if (open_listen_socket(NULL, 0) >= 0) {
> + /* yes we are. save the pages to temporary file
> + * until there is a better way to directly read
> + * the network socket from restorer.c */
> +
> + int tmp_fd;
> + char buffer[PATH_MAX];
> + char tmp[PAGE_SIZE];
> + int n;
> +
> + i = 0;
> + strcpy(buffer, "/dev/shm/pages-XXXXXX");
> + tmp_fd = mkstemp(buffer);
> + while (1) {
> + n = read(task_args->fd_pages, tmp, PAGE_SIZE);
> +
> + if (n == 0)
> + break;
> +
> + if (n == -1) {
> + pr_perror("Pages read failed");
> + goto err;
> + }
> +
> + i = write(tmp_fd, tmp, n);
> + if (i!=n) {
> + pr_perror("Oops, writing failed");
> + goto err;
> + }
> +
> + }
> + lseek(tmp_fd, 0, SEEK_SET);
> + close(task_args->fd_pages);
> + task_args->fd_pages = tmp_fd;
> + }
> +
> mutex_init(&task_args->rst_lock);
>
> /*
More information about the CRIU
mailing list