[CRIU] [PATCH v3 06/12] page-read/xfer: add ability to open image hierarchy for shmem
Eugene Batalov
eabatalov89 at gmail.com
Sun Aug 7 06:11:10 PDT 2016
From: Fyodor Bocharov <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>
---
criu/include/pagemap.h | 5 +++--
criu/page-xfer.c | 5 +++--
criu/pagemap.c | 10 +++++-----
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/criu/include/pagemap.h b/criu/include/pagemap.h
index b973caf..e5debbf 100644
--- a/criu/include/pagemap.h
+++ b/criu/include/pagemap.h
@@ -87,8 +87,9 @@ 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);
diff --git a/criu/page-xfer.c b/criu/page-xfer.c
index 0da20e2..7677184 100644
--- a/criu/page-xfer.c
+++ b/criu/page-xfer.c
@@ -300,9 +300,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)
@@ -314,7 +315,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);
diff --git a/criu/pagemap.c b/criu/pagemap.c
index 227d561..86591e4 100644
--- a/criu/pagemap.c
+++ b/criu/pagemap.c
@@ -428,7 +428,7 @@ free_pagemaps:
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;
static unsigned ids = 1;
@@ -460,7 +460,7 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)
pr->bunch.iov_base = NULL;
pr->pmes = 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;
@@ -469,7 +469,7 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)
return 0;
}
- 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;
}
@@ -500,7 +500,7 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)
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);
}
--
1.9.1
More information about the CRIU
mailing list