mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-29 21:38:16 +00:00
restore: Tune up fixup_pages_data
Use pr_panic if ending-zero page is missed (also a few style tuneups). Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
parent
1293fb0f8e
commit
11cf71c542
43
cr-restore.c
43
cr-restore.c
@ -653,7 +653,6 @@ static int fixup_vma_fds(int pid, int fd)
|
|||||||
{
|
{
|
||||||
int offset = GET_FILE_OFF_AFTER(struct core_entry);
|
int offset = GET_FILE_OFF_AFTER(struct core_entry);
|
||||||
|
|
||||||
pr_info("Seek for: %d bytes\n", offset);
|
|
||||||
lseek(fd, offset, SEEK_SET);
|
lseek(fd, offset, SEEK_SET);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -708,8 +707,8 @@ static int fixup_pages_data(int pid, int fd)
|
|||||||
{
|
{
|
||||||
char path[128];
|
char path[128];
|
||||||
int shfd;
|
int shfd;
|
||||||
u32 mag;
|
u32 magic;
|
||||||
u64 vaddr;
|
u64 va;
|
||||||
|
|
||||||
sprintf(path, "pages-shmem-%d.img", pid);
|
sprintf(path, "pages-shmem-%d.img", pid);
|
||||||
shfd = open(path, O_RDONLY);
|
shfd = open(path, O_RDONLY);
|
||||||
@ -718,48 +717,58 @@ static int fixup_pages_data(int pid, int fd)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
read(shfd, &mag, sizeof(mag));
|
read(shfd, &magic, sizeof(magic));
|
||||||
if (mag != PAGES_MAGIC) {
|
if (magic != PAGES_MAGIC) {
|
||||||
fprintf(stderr, "Bad shmem image\n");
|
fprintf(stderr, "Bad shmem image\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find out the last page, which is zero one */
|
/*
|
||||||
|
* Find out the last page, which must be a zero page.
|
||||||
|
*/
|
||||||
lseek(fd, -sizeof(struct page_entry), SEEK_END);
|
lseek(fd, -sizeof(struct page_entry), SEEK_END);
|
||||||
read(fd, &vaddr, sizeof(vaddr));
|
read(fd, &va, sizeof(va));
|
||||||
if (vaddr != 0) {
|
if (va) {
|
||||||
pr_info("SHIT %lx\n", (unsigned long)vaddr);
|
pr_panic("Zero-page expected but got %lx\n", (unsigned long)va);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Since we're to update pages we suppress old zero-page
|
||||||
|
* and will write new one at the end.
|
||||||
|
*/
|
||||||
lseek(fd, -sizeof(struct page_entry), SEEK_END);
|
lseek(fd, -sizeof(struct page_entry), SEEK_END);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = read(shfd, &vaddr, sizeof(vaddr));
|
ret = read(shfd, &va, sizeof(va));
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (ret < 0 || ret != sizeof(vaddr)) {
|
if (ret < 0 || ret != sizeof(va)) {
|
||||||
perror("Can't read vaddr");
|
perror("Can't read virtual address");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vaddr == 0)
|
if (va == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!should_restore_page(pid, vaddr)) {
|
if (!should_restore_page(pid, va)) {
|
||||||
lseek(shfd, PAGE_SIZE, SEEK_CUR);
|
lseek(shfd, PAGE_SIZE, SEEK_CUR);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
write(fd, &vaddr, sizeof(vaddr));
|
pr_info("%d: Restoring shared page: %16lx\n",
|
||||||
|
pid, va);
|
||||||
|
|
||||||
|
write(fd, &va, sizeof(va));
|
||||||
sendfile(fd, shfd, NULL, PAGE_SIZE);
|
sendfile(fd, shfd, NULL, PAGE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(shfd);
|
close(shfd);
|
||||||
vaddr = 0;
|
va = 0;
|
||||||
write(fd, &vaddr, sizeof(vaddr));
|
write(fd, &va, sizeof(va));
|
||||||
write(fd, zpage, sizeof(zpage));
|
write(fd, zpage, sizeof(zpage));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user