[CRIU] [PATCH 1/3]v2 page-read: rework open_page_read to use in shmem restore

Tikhomirov Pavel snorcht at gmail.com
Thu Mar 13 23:16:54 PDT 2014


Signed-off-by: Tikhomirov Pavel <snorcht at gmail.com>
---
 cr-dedup.c          |  2 +-
 cr-restore.c        |  2 +-
 include/page-read.h |  4 ++--
 page-read.c         | 14 +++++++-------
 page-xfer.c         |  2 +-
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/cr-dedup.c b/cr-dedup.c
index 38f03a6..7758674 100644
--- a/cr-dedup.c
+++ b/cr-dedup.c
@@ -67,7 +67,7 @@ static int cr_dedup_one_pagemap(int pid)
 	struct page_read * prp;
 	struct iovec iov;
 
-	ret = open_page_read(pid, &pr, O_RDWR);
+	ret = open_page_read(pid, &pr, O_RDWR, false);
 	if (ret) {
 		ret = -1;
 		goto exit;
diff --git a/cr-restore.c b/cr-restore.c
index ab8fa77..406fdbb 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -340,7 +340,7 @@ static int restore_priv_vma_content(pid_t pid)
 	vma = list_first_entry(vmas, struct vma_area, list);
 
 	ret = open_page_read(pid, &pr,
-			opts.auto_dedup ? O_RDWR : O_RSTR);
+			opts.auto_dedup ? O_RDWR : O_RSTR, false);
 	if (ret)
 		return -1;
 
diff --git a/include/page-read.h b/include/page-read.h
index 9078eaa..7a063e9 100644
--- a/include/page-read.h
+++ b/include/page-read.h
@@ -68,8 +68,8 @@ struct page_read {
 	unsigned id; /* for logging */
 };
 
-extern int open_page_read(int pid, struct page_read *, int flags);
-extern int open_page_read_at(int dfd, int pid, struct page_read *pr, int flags);
+extern int open_page_read(int pid, struct page_read *, int flags, bool shmem);
+extern int open_page_read_at(int dfd, int pid, struct page_read *pr, int flags, bool shmem);
 extern void pagemap2iovec(PagemapEntry *pe, struct iovec *iov);
 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 fc51b6a..6ed1e6b 100644
--- a/page-read.c
+++ b/page-read.c
@@ -195,7 +195,7 @@ static int try_open_parent(int dfd, int pid, struct page_read *pr, int flags)
 	if (!parent)
 		goto err_cl;
 
-	if (open_page_read_at(pfd, pid, parent, flags)) {
+	if (open_page_read_at(pfd, pid, parent, flags, false)) {
 		if (errno != ENOENT)
 			goto err_free;
 		xfree(parent);
@@ -214,15 +214,15 @@ err_cl:
 	return -1;
 }
 
-int open_page_read_at(int dfd, int pid, struct page_read *pr, int flags)
+int open_page_read_at(int dfd, int pid, struct page_read *pr, int flags, bool shmem)
 {
 	pr->pe = NULL;
 	pr->bunch.iov_len = 0;
 	pr->bunch.iov_base = NULL;
 
-	pr->fd = open_image_at(dfd, CR_FD_PAGEMAP, O_RSTR, (long)pid);
+	pr->fd = open_image_at(dfd, shmem ? CR_FD_SHMEM_PAGEMAP : CR_FD_PAGEMAP, O_RSTR, (long)pid);
 	if (pr->fd < 0) {
-		pr->fd_pg = open_image_at(dfd, CR_FD_PAGES_OLD, flags, pid);
+		pr->fd_pg = open_image_at(dfd, shmem ? CR_FD_SHM_PAGES_OLD : CR_FD_PAGES_OLD, flags, pid);
 		if (pr->fd_pg < 0)
 			return -1;
 
@@ -233,7 +233,7 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int flags)
 	} else {
 		static unsigned ids = 1;
 
-		if (try_open_parent(dfd, pid, pr, flags)) {
+		if (!shmem && try_open_parent(dfd, pid, pr, flags)) {
 			close(pr->fd);
 			return -1;
 		}
@@ -258,7 +258,7 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int flags)
 	return 0;
 }
 
-int open_page_read(int pid, struct page_read *pr, int flags)
+int open_page_read(int pid, struct page_read *pr, int flags, bool shmem)
 {
-	return open_page_read_at(get_service_fd(IMG_FD_OFF), pid, pr, flags);
+	return open_page_read_at(get_service_fd(IMG_FD_OFF), pid, pr, flags, shmem);
 }
diff --git a/page-xfer.c b/page-xfer.c
index f9e1456..f26be35 100644
--- a/page-xfer.c
+++ b/page-xfer.c
@@ -656,7 +656,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, O_RDWR);
+		ret = open_page_read_at(pfd, id, xfer->parent, O_RDWR, false);
 		if (ret) {
 			pr_perror("Can't dedup old image format");
 			xfree(xfer->parent);
-- 
1.8.3.2



More information about the CRIU mailing list