From b43f7aa6159708874cacac77c20f22bf23047b86 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 11 May 2017 12:11:19 +0300 Subject: [PATCH] page_read: Make it possible to get pages.img ID from page_read The pages.img will need to get opened one more time w/o the pagemap.img. Signed-off-by: Pavel Emelyanov Signed-off-by: Andrei Vagin --- criu/image.c | 14 ++++++-------- criu/include/image.h | 4 ++-- criu/include/pagemap.h | 1 + criu/page-xfer.c | 4 +++- criu/pagemap.c | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/criu/image.c b/criu/image.c index 9715d1602..84e6c8af5 100644 --- a/criu/image.c +++ b/criu/image.c @@ -461,29 +461,27 @@ void up_page_ids_base(void) page_ids += 0x10000; } -struct cr_img *open_pages_image_at(int dfd, unsigned long flags, struct cr_img *pmi) +struct cr_img *open_pages_image_at(int dfd, unsigned long flags, struct cr_img *pmi, u32 *id) { - unsigned id; - if (flags == O_RDONLY || flags == O_RDWR) { PagemapHead *h; if (pb_read_one(pmi, &h, PB_PAGEMAP_HEAD) < 0) return NULL; - id = h->pages_id; + *id = h->pages_id; pagemap_head__free_unpacked(h, NULL); } else { PagemapHead h = PAGEMAP_HEAD__INIT; - id = h.pages_id = page_ids++; + *id = h.pages_id = page_ids++; if (pb_write_one(pmi, &h, PB_PAGEMAP_HEAD) < 0) return NULL; } - return open_image_at(dfd, CR_FD_PAGES, flags, id); + return open_image_at(dfd, CR_FD_PAGES, flags, *id); } -struct cr_img *open_pages_image(unsigned long flags, struct cr_img *pmi) +struct cr_img *open_pages_image(unsigned long flags, struct cr_img *pmi, u32 *id) { - return open_pages_image_at(get_service_fd(IMG_FD_OFF), flags, pmi); + return open_pages_image_at(get_service_fd(IMG_FD_OFF), flags, pmi, id); } /* diff --git a/criu/include/image.h b/criu/include/image.h index 1c22a4f66..22f34afff 100644 --- a/criu/include/image.h +++ b/criu/include/image.h @@ -150,8 +150,8 @@ extern void close_image_dir(void); extern struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...); #define open_image(typ, flags, ...) open_image_at(-1, typ, flags, ##__VA_ARGS__) extern int open_image_lazy(struct cr_img *img); -extern struct cr_img *open_pages_image(unsigned long flags, struct cr_img *pmi); -extern struct cr_img *open_pages_image_at(int dfd, unsigned long flags, struct cr_img *pmi); +extern struct cr_img *open_pages_image(unsigned long flags, struct cr_img *pmi, u32 *pages_id); +extern struct cr_img *open_pages_image_at(int dfd, unsigned long flags, struct cr_img *pmi, u32 *pages_id); extern void up_page_ids_base(void); extern struct cr_img *img_from_fd(int fd); /* for cr-show mostly */ diff --git a/criu/include/pagemap.h b/criu/include/pagemap.h index e87e9f1a7..6633eec20 100644 --- a/criu/include/pagemap.h +++ b/criu/include/pagemap.h @@ -55,6 +55,7 @@ struct page_read { /* Private data of reader */ struct cr_img *pmi; struct cr_img *pi; + u32 pages_img_id; PagemapEntry *pe; /* current pagemap we are on */ struct page_read *parent; /* parent pagemap (if ->in_parent diff --git a/criu/page-xfer.c b/criu/page-xfer.c index 71aee0d6b..436c41c2c 100644 --- a/criu/page-xfer.c +++ b/criu/page-xfer.c @@ -267,11 +267,13 @@ static void close_page_xfer(struct page_xfer *xfer) static int open_page_local_xfer(struct page_xfer *xfer, int fd_type, long id) { + u32 pages_id; + xfer->pmi = open_image(fd_type, O_DUMP, id); if (!xfer->pmi) return -1; - xfer->pi = open_pages_image(O_DUMP, xfer->pmi); + xfer->pi = open_pages_image(O_DUMP, xfer->pmi, &pages_id); if (!xfer->pi) { close_image(xfer->pmi); return -1; diff --git a/criu/pagemap.c b/criu/pagemap.c index 991d92e81..9c11c261a 100644 --- a/criu/pagemap.c +++ b/criu/pagemap.c @@ -655,7 +655,7 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags) return -1; } - pr->pi = open_pages_image_at(dfd, flags, pr->pmi); + pr->pi = open_pages_image_at(dfd, flags, pr->pmi, &pr->pages_img_id); if (!pr->pi) { close_page_read(pr); return -1;