[CRIU] [PATCHv0 6/8] page-read/xfer: add ability to open image hierarchy for shmem

Eugene Batalov eabatalov89 at gmail.com
Sun Dec 6 05:15:22 PST 2015


From: Fyodor <bocharovfedor at gmail.com>

In order to restore deduplicated anonymous shared memory we need to open
it's parent pagemap images. Code that opens parent pagemap images already
exists for anonymous private memory. All we need to do is to remove couple
of checks from existing code. Also we need to rename pid to id because now
we can pass either pid or shmid and the actual meaning depends on pr_flags.

Signed-off-by: Fyodor Bocharov <fbocharov at yandex.ru>
Signed-off-by: Eugene Batalov <eabatalov89 at gmail.com>
---
 include/page-read.h |  4 ++--
 page-read.c         | 12 ++++++------
 page-xfer.c         |  5 +++--
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/include/page-read.h b/include/page-read.h
index 827e4ac..9892b19 100644
--- a/include/page-read.h
+++ b/include/page-read.h
@@ -79,8 +79,8 @@ struct page_read {
  *  0 -- no images
  *  1 -- opened
  */
-extern int open_page_read(int pid, struct page_read *, int pr_flags);
-extern int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags);
+extern int open_page_read(int id, struct page_read *, int pr_flags);
+extern int open_page_read_at(int dfd, int id, struct page_read *pr, int pr_flags);
 extern void pagemap2iovec(PagemapEntry *pe, struct iovec *iov);
 extern void iovec2pagemap(struct iovec *iov, PagemapEntry *pe);
 extern int seek_pagemap_page(struct page_read *pr, unsigned long vaddr, bool warn);
diff --git a/page-read.c b/page-read.c
index 28ecd5b..58cd318 100644
--- a/page-read.c
+++ b/page-read.c
@@ -273,7 +273,7 @@ err_cl:
 	return -1;
 }
 
-int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)
+int open_page_read_at(int dfd, int id, struct page_read *pr, int pr_flags)
 {
 	int flags, i_typ, i_typ_o;
 	static unsigned ids = 1;
@@ -304,7 +304,7 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)
 	pr->bunch.iov_len = 0;
 	pr->bunch.iov_base = NULL;
 
-	pr->pmi = open_image_at(dfd, i_typ, O_RSTR, (long)pid);
+	pr->pmi = open_image_at(dfd, i_typ, O_RSTR, (long)id);
 	if (!pr->pmi)
 		return -1;
 
@@ -313,7 +313,7 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)
 		goto open_old;
 	}
 
-	if ((i_typ != CR_FD_SHMEM_PAGEMAP) && try_open_parent(dfd, pid, pr, pr_flags)) {
+	if (try_open_parent(dfd, id, pr, pr_flags)) {
 		close_image(pr->pmi);
 		return -1;
 	}
@@ -336,7 +336,7 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)
 	return 1;
 
 open_old:
-	pr->pmi = open_image_at(dfd, i_typ_o, flags, pid);
+	pr->pmi = open_image_at(dfd, i_typ_o, flags, id);
 	if (!pr->pmi)
 		return -1;
 
@@ -354,7 +354,7 @@ open_old:
 	return 1;
 }
 
-int open_page_read(int pid, struct page_read *pr, int pr_flags)
+int open_page_read(int id, struct page_read *pr, int pr_flags)
 {
-	return open_page_read_at(get_service_fd(IMG_FD_OFF), pid, pr, pr_flags);
+	return open_page_read_at(get_service_fd(IMG_FD_OFF), id, pr, pr_flags);
 }
diff --git a/page-xfer.c b/page-xfer.c
index cb6073a..1f57e2a 100644
--- a/page-xfer.c
+++ b/page-xfer.c
@@ -759,9 +759,10 @@ static int open_page_local_xfer(struct page_xfer *xfer, int fd_type, long id)
 	 *    to exist in parent (either pagemap or hole)
 	 */
 	xfer->parent = NULL;
-	if (fd_type == CR_FD_PAGEMAP) {
+	if (fd_type == CR_FD_PAGEMAP || fd_type == CR_FD_SHMEM_PAGEMAP) {
 		int ret;
 		int pfd;
+		int pr_flags = (fd_type == CR_FD_PAGEMAP) ? PR_TASK : PR_SHMEM;
 
 		pfd = openat(get_service_fd(IMG_FD_OFF), CR_PARENT_LINK, O_RDONLY);
 		if (pfd < 0 && errno == ENOENT)
@@ -773,7 +774,7 @@ static int open_page_local_xfer(struct page_xfer *xfer, int fd_type, long id)
 			return -1;
 		}
 
-		ret = open_page_read_at(pfd, id, xfer->parent, PR_TASK);
+		ret = open_page_read_at(pfd, id, xfer->parent, pr_flags);
 		if (ret <= 0) {
 			pr_perror("No parent image found, though parent directory is set");
 			xfree(xfer->parent);
-- 
1.9.1



More information about the CRIU mailing list