[CRIU] [PATCH] page-read: Introduce custom flags for opening

Pavel Emelyanov xemul at parallels.com
Fri Feb 27 07:29:45 PST 2015


Instead of open flags and boolean is_shmem argument.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 cr-dedup.c          |  2 +-
 cr-restore.c        |  3 +--
 include/page-read.h | 10 ++++++++--
 page-read.c         | 39 +++++++++++++++++++++++++++++++--------
 page-xfer.c         |  2 +-
 shmem.c             |  2 +-
 6 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/cr-dedup.c b/cr-dedup.c
index b619137..d0c1fc4 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, false);
+	ret = open_page_read(pid, &pr, PR_TASK | PR_MOD);
 	if (ret) {
 		ret = -1;
 		goto exit;
diff --git a/cr-restore.c b/cr-restore.c
index 2afdb45..e30d5a6 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -352,8 +352,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, false);
+	ret = open_page_read(pid, &pr, PR_TASK);
 	if (ret)
 		return -1;
 
diff --git a/include/page-read.h b/include/page-read.h
index df967bd..0ac316e 100644
--- a/include/page-read.h
+++ b/include/page-read.h
@@ -68,8 +68,14 @@ struct page_read {
 	unsigned id; /* for logging */
 };
 
-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);
+#define PR_SHMEM	0x1
+#define PR_TASK		0x2
+
+#define PR_TYPE_MASK	0x3
+#define PR_MOD		0x4	/* Will need to modify */
+
+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 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 f67bdfe..1126ad8 100644
--- a/page-read.c
+++ b/page-read.c
@@ -190,7 +190,7 @@ static void close_page_read(struct page_read *pr)
 		close_image(pr->pi);
 }
 
-static int try_open_parent(int dfd, int pid, struct page_read *pr, int flags)
+static int try_open_parent(int dfd, int pid, struct page_read *pr, int pr_flags)
 {
 	int pfd;
 	struct page_read *parent = NULL;
@@ -203,7 +203,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, false)) {
+	if (open_page_read_at(pfd, pid, parent, pr_flags)) {
 		if (errno != ENOENT)
 			goto err_free;
 		xfree(parent);
@@ -222,16 +222,39 @@ err_cl:
 	return -1;
 }
 
-int open_page_read_at(int dfd, int pid, struct page_read *pr, int flags, bool shmem)
+int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)
 {
+	int flags, i_typ, i_typ_o;
+
+	if (opts.auto_dedup)
+		pr_flags |= PR_MOD;
+	if (pr_flags & PR_MOD)
+		flags = O_RDWR;
+	else
+		flags = O_RSTR;
+
+	switch (pr_flags & PR_TYPE_MASK) {
+	case PR_TASK:
+		i_typ = CR_FD_PAGEMAP;
+		i_typ_o = CR_FD_PAGES_OLD;
+		break;
+	case PR_SHMEM:
+		i_typ = CR_FD_SHMEM_PAGEMAP;
+		i_typ_o = CR_FD_SHM_PAGES_OLD;
+		break;
+	default:
+		BUG();
+		return -1;
+	}
+
 	pr->pe = NULL;
 	pr->parent = NULL;
 	pr->bunch.iov_len = 0;
 	pr->bunch.iov_base = NULL;
 
-	pr->pmi = open_image_at(dfd, shmem ? CR_FD_SHMEM_PAGEMAP : CR_FD_PAGEMAP, O_RSTR, (long)pid);
+	pr->pmi = open_image_at(dfd, i_typ, O_RSTR, (long)pid);
 	if (!pr->pmi) {
-		pr->pmi = open_image_at(dfd, shmem ? CR_FD_SHM_PAGES_OLD : CR_FD_PAGES_OLD, flags, pid);
+		pr->pmi = open_image_at(dfd, i_typ_o, flags, pid);
 		if (!pr->pmi)
 			return -1;
 
@@ -242,7 +265,7 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int flags, bool sh
 	} else {
 		static unsigned ids = 1;
 
-		if (!shmem && try_open_parent(dfd, pid, pr, flags)) {
+		if ((i_typ != CR_FD_SHMEM_PAGEMAP) && try_open_parent(dfd, pid, pr, pr_flags)) {
 			close_image(pr->pmi);
 			return -1;
 		}
@@ -267,7 +290,7 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int flags, bool sh
 	return 0;
 }
 
-int open_page_read(int pid, struct page_read *pr, int flags, bool shmem)
+int open_page_read(int pid, struct page_read *pr, int pr_flags)
 {
-	return open_page_read_at(get_service_fd(IMG_FD_OFF), pid, pr, flags, shmem);
+	return open_page_read_at(get_service_fd(IMG_FD_OFF), pid, pr, pr_flags);
 }
diff --git a/page-xfer.c b/page-xfer.c
index 57dd794..43345d5 100644
--- a/page-xfer.c
+++ b/page-xfer.c
@@ -740,7 +740,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, false);
+		ret = open_page_read_at(pfd, id, xfer->parent, PR_TASK);
 		if (ret) {
 			pr_perror("No parent image found, though parent directory is set");
 			xfree(xfer->parent);
diff --git a/shmem.c b/shmem.c
index ce3916b..c66b2b4 100644
--- a/shmem.c
+++ b/shmem.c
@@ -151,7 +151,7 @@ static int restore_shmem_content(void *addr, struct shmem_info *si)
 	struct page_read pr;
 	unsigned long off_real;
 
-	ret = open_page_read(si->shmid, &pr, opts.auto_dedup ? O_RDWR : O_RSTR, true);
+	ret = open_page_read(si->shmid, &pr, PR_SHMEM);
 	if (ret)
 		return -1;
 
-- 
1.8.4.2



More information about the CRIU mailing list