2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00

pages: Accept pages images from versions v0.4 and below

After reworkring the way pagemap is stored the backward compatibility
was not preserved for patches simplicity. Time to return it back.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Pavel Emelyanov
2013-03-27 13:12:02 +04:00
parent 18242f8319
commit 421d46f79e
5 changed files with 76 additions and 31 deletions

View File

@@ -277,29 +277,47 @@ static int restore_priv_vma_content(pid_t pid)
vma = list_first_entry(&rst_vmas.h, struct vma_area, list);
fd = open_image_ro(CR_FD_PAGEMAP, (long)pid);
if (fd < 0)
return -1;
fd_pg = open_pages_image(O_RSTR, fd);
if (fd_pg < 0) {
close(fd);
return -1;
if (fd < 0) {
fd_pg = open_image_ro(CR_FD_PAGES_OLD, pid);
if (fd_pg < 0)
return -1;
} else {
fd_pg = open_pages_image(O_RSTR, fd);
if (fd_pg < 0) {
close(fd);
return -1;
}
}
/*
* Read page contents.
*/
while (1) {
PagemapEntry *pe;
unsigned long off, i;
unsigned long off, i, nr_pages;;
ret = pb_read_one_eof(fd, &pe, PB_PAGEMAP);
if (ret <= 0)
break;
if (fd >= 0) {
PagemapEntry *pe;
va = (unsigned long)decode_pointer(pe->vaddr);
ret = pb_read_one_eof(fd, &pe, PB_PAGEMAP);
if (ret <= 0)
break;
for (i = 0; i < pe->nr_pages; i++) {
va = (unsigned long)decode_pointer(pe->vaddr);
nr_pages = pe->nr_pages;
pagemap_entry__free_unpacked(pe, NULL);
} else {
__u64 img_va;
ret = read_img_eof(fd_pg, &img_va);
if (ret <= 0)
break;
va = (unsigned long)decode_pointer(img_va);
nr_pages = 1;
}
for (i = 0; i < nr_pages; i++) {
unsigned char buf[PAGE_SIZE];
void *p;
@@ -350,8 +368,6 @@ static int restore_priv_vma_content(pid_t pid)
memcpy(p, buf, PAGE_SIZE);
nr_restored++;
}
pagemap_entry__free_unpacked(pe, NULL);
}
close(fd_pg);
close(fd);

View File

@@ -157,6 +157,8 @@ struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = {
FD_ENTRY(FILE_LOCKS, "filelocks-%d", show_file_locks),
FD_ENTRY(RLIMIT, "rlimit", show_rlimit),
FD_ENTRY(PAGES, "pages-%u", NULL),
FD_ENTRY(PAGES_OLD, "pages-%d", NULL),
FD_ENTRY(SHM_PAGES_OLD, "pages-shmem-%ld", NULL),
FD_ENTRY(SIGNAL, "signal-s-%d", show_siginfo), /* shared signals */
FD_ENTRY(PSIGNAL, "signal-p-%d", show_siginfo), /* private signals */
};

View File

@@ -86,6 +86,9 @@ enum {
CR_FD_PAGES,
CR_FD_PSIGNAL,
CR_FD_PAGES_OLD,
CR_FD_SHM_PAGES_OLD,
CR_FD_MAX
};

View File

@@ -72,4 +72,7 @@
#define ROUTE_MAGIC RAW_IMAGE_MAGIC
#define TMPFS_MAGIC RAW_IMAGE_MAGIC
#define PAGES_OLD_MAGIC PAGEMAP_MAGIC
#define SHM_PAGES_OLD_MAGIC PAGEMAP_MAGIC
#endif /* __CR_MAGIC_H__ */

51
shmem.c
View File

@@ -139,30 +139,51 @@ static int restore_shmem_content(void *addr, struct shmem_info *si)
int fd, fd_pg, ret = 0;
fd = open_image_ro(CR_FD_SHMEM_PAGEMAP, si->shmid);
if (fd < 0)
goto err_unmap;
fd_pg = open_pages_image(O_RSTR, fd);
if (fd_pg < 0)
goto out_close;
if (fd < 0) {
fd_pg = open_image_ro(CR_FD_SHM_PAGES_OLD, si->shmid);
if (fd_pg < 0)
goto err_unmap;
} else {
fd_pg = open_pages_image(O_RSTR, fd);
if (fd_pg < 0)
goto out_close;
}
while (1) {
PagemapEntry *pe;
unsigned long vaddr;
unsigned nr_pages;
ret = pb_read_one_eof(fd, &pe, PB_PAGEMAP);
if (ret <= 0)
if (fd >= 0) {
PagemapEntry *pe;
ret = pb_read_one_eof(fd, &pe, PB_PAGEMAP);
if (ret <= 0)
break;
vaddr = (unsigned long)decode_pointer(pe->vaddr);
nr_pages = pe->nr_pages;
pagemap_entry__free_unpacked(pe, NULL);
} else {
__u64 img_vaddr;
ret = read_img_eof(fd_pg, &img_vaddr);
if (ret <= 0)
break;
vaddr = (unsigned long)decode_pointer(img_vaddr);
nr_pages = 1;
}
if (vaddr + nr_pages * PAGE_SIZE > si->size)
break;
if (pe->vaddr + pe->nr_pages * PAGE_SIZE > si->size)
break;
ret = read(fd_pg, addr + pe->vaddr, pe->nr_pages * PAGE_SIZE);
if (ret != pe->nr_pages * PAGE_SIZE) {
ret = read(fd_pg, addr + vaddr, nr_pages * PAGE_SIZE);
if (ret != nr_pages * PAGE_SIZE) {
ret = -1;
break;
}
pagemap_entry__free_unpacked(pe, NULL);
}
close(fd_pg);