Commit c3051512 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

crtools: delete CORE_OUT

It's a rudiment from old times, when restore worked via ececve.
Now we modify the core file in place to fixup vma-s.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 650be3d2
......@@ -608,38 +608,6 @@ static int fixup_vma_fds(int pid, int fd)
return 0;
}
/*
* FIXME avoid this pages copying
*/
static int fixup_pages_data(int pid, int fd)
{
int pgfd, ret = -1;
u64 va;
pr_info("%d: Reading shmem pages img\n", pid);
pgfd = open_image_ro(CR_FD_PAGES, pid);
if (pgfd < 0)
return -1;
while (1) {
if (read_img(pgfd, &va) < 0)
goto out;
if (final_page_va(va))
break;
write(fd, &va, sizeof(va));
sendfile(fd, pgfd, NULL, PAGE_SIZE);
}
ret = 0;
out:
close_safe(&pgfd);
return ret;
}
static int prepare_image_maps(int fd, int pid)
{
pr_info("%d: Fixing maps\n", pid);
......@@ -647,9 +615,6 @@ static int prepare_image_maps(int fd, int pid)
if (fixup_vma_fds(pid, fd))
return -1;
if (fixup_pages_data(pid, fd))
return -1;
pr_info("%d: Fixing maps\n", pid);
return 0;
......@@ -658,46 +623,19 @@ static int prepare_image_maps(int fd, int pid)
static int prepare_and_sigreturn(int pid)
{
char path[PATH_MAX];
int fd = -1, fd_new = -1, err = -1;
int fd = -1, err = -1;
struct stat buf;
fd = open_image_ro_nocheck(FMT_FNAME_CORE, pid);
fd = open_image(CR_FD_CORE, O_RDWR, pid);
if (fd < 0)
return -1;
if (fstat(fd, &buf)) {
pr_perror("%d: Can't stat", pid);
goto out;
}
sprintf(path, FMT_FNAME_CORE_OUT, pid);
fd_new = openat(image_dir_fd, path,
O_RDWR | O_CREAT | O_TRUNC, CR_FD_PERM);
if (fd_new < 0) {
pr_perror("%d: Can't open new image", pid);
goto out;
}
pr_info("%d: Preparing restore image %s (%li bytes)\n", pid, path, buf.st_size);
if (sendfile(fd_new, fd, NULL, buf.st_size) != buf.st_size) {
pr_perror("%d: sendfile failed", pid);
goto out;
}
if (fstat(fd_new, &buf)) {
pr_perror("%d: Can't stat", pid);
goto out;
}
pr_info("fd_new: %li bytes\n", buf.st_size);
if (prepare_image_maps(fd_new, pid))
if (prepare_image_maps(fd, pid))
goto out;
err = 0;
out:
close_safe(&fd);
close_safe(&fd_new);
if (err)
return err;
sigreturn_restore(pid);
......@@ -1594,6 +1532,7 @@ static void sigreturn_restore(pid_t pid)
struct vma_area *vma_area;
int fd_fdinfo = -1;
int fd_core = -1;
int fd_pages = -1;
int i;
int *fd_core_threads;
......@@ -1618,7 +1557,7 @@ static void sigreturn_restore(pid_t pid)
BUILD_BUG_ON(SHMEMS_SIZE % PAGE_SIZE);
BUILD_BUG_ON(TASK_ENTRIES_SIZE % PAGE_SIZE);
fd_core = open_image_ro_nocheck(FMT_FNAME_CORE_OUT, pid);
fd_core = open_image_ro(CR_FD_CORE, pid);
if (fd_core < 0) {
pr_perror("Can't open core-out-%d", pid);
goto err;
......@@ -1630,6 +1569,11 @@ static void sigreturn_restore(pid_t pid)
goto err;
}
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);
......@@ -1751,6 +1695,7 @@ static void sigreturn_restore(pid_t pid)
task_args->logfd = log_get_fd();
task_args->sigchld_act = sigchld_act;
task_args->fd_fdinfo = fd_fdinfo;
task_args->fd_pages = fd_pages;
ret = prepare_itimers(pid, task_args);
if (ret < 0)
......
......@@ -77,7 +77,6 @@ extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
#define FMT_FNAME_PAGES "pages-%d.img"
#define FMT_FNAME_SHMEM_PAGES "pages-shmem-%ld.img"
#define FMT_FNAME_CORE "core-%d.img"
#define FMT_FNAME_CORE_OUT "core-%d.img.out"
#define FMT_FNAME_PIPES "pipes-%d.img"
#define FMT_FNAME_PSTREE "pstree-%d.img"
#define FMT_FNAME_SIGACTS "sigacts-%d.img"
......
......@@ -66,6 +66,7 @@ struct task_restore_core_args {
int pid; /* task pid */
int fd_core; /* opened core file */
int fd_fdinfo; /* opened files dump file */
int fd_pages; /* opened pages dump file */
int logfd;
bool restore_threads; /* if to restore threads */
u32 rst_lock;
......
......@@ -434,7 +434,7 @@ long restore_task(struct task_restore_core_args *args)
* Read page contents.
*/
while (1) {
ret = sys_read(args->fd_core, &va, sizeof(va));
ret = sys_read(args->fd_pages, &va, sizeof(va));
if (!ret)
break;
if (ret != sizeof(va)) {
......@@ -445,7 +445,7 @@ long restore_task(struct task_restore_core_args *args)
if (final_page_va(va))
break;
ret = sys_read(args->fd_core, (void *)va, PAGE_SIZE);
ret = sys_read(args->fd_pages, (void *)va, PAGE_SIZE);
if (ret != PAGE_SIZE) {
write_num_n(__LINE__);
write_num_n(ret);
......@@ -453,6 +453,8 @@ long restore_task(struct task_restore_core_args *args)
}
}
sys_close(args->fd_pages);
/*
* Walk though all VMAs again to drop PROT_WRITE
* if it was not there.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment