[02/11] page_read: Make it possible to get pages.img ID from page_read

Submitted by Pavel Emelianov on May 5, 2017, 4:02 p.m.

Details

Message ID 38e40371-292c-f9ec-77ba-0613051ceaf8@virtuozzo.com
State New
Series "Do not remap vmas when not needed"
Headers show

Commit Message

Pavel Emelianov May 5, 2017, 4:02 p.m.
The pages.img will need to get opened one more time w/o the pagemap.img.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 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(-)

Patch hide | download patch | download mbox

diff --git a/criu/image.c b/criu/image.c
index ab12c88..62e8e71 100644
--- a/criu/image.c
+++ b/criu/image.c
@@ -521,29 +521,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 c2b612e..0fa9510 100644
--- a/criu/include/image.h
+++ b/criu/include/image.h
@@ -151,8 +151,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 e629f3c..b23ec3a 100644
--- a/criu/include/pagemap.h
+++ b/criu/include/pagemap.h
@@ -61,6 +61,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 89ea94f..fa3aacc 100644
--- a/criu/page-xfer.c
+++ b/criu/page-xfer.c
@@ -281,11 +281,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 353c469..2cf91e3 100644
--- a/criu/pagemap.c
+++ b/criu/pagemap.c
@@ -809,7 +809,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;