[CRIU] [PATCH 09/10] pagemap-cache: Use greedy mode if pagemap inaccessible
Cyrill Gorcunov
gorcunov at openvz.org
Mon Sep 28 12:01:41 PDT 2015
If criu is running in unprivileged mode and we can't
access dumpee's pagemap file -- simply switch to
greedy mode where all pages are gonna be dumped
regardless of their presence in memory.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
pagemap-cache.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/pagemap-cache.c b/pagemap-cache.c
index 9ce7b911e440..2abe7bbf23b1 100644
--- a/pagemap-cache.c
+++ b/pagemap-cache.c
@@ -45,9 +45,13 @@ int pmc_init(pmc_t *pmc, pid_t pid, struct list_head *vma_head, size_t size)
pmc->vma_head = vma_head;
if (!pmc->map || pmc->fd < 0) {
- pr_err("Failed to init pagemap for %d\n", pid);
- pmc_fini(pmc);
- return -1;
+ if (!pmc->map || errno != EPERM) {
+ pr_err("Failed to init pagemap for %d\n", pid);
+ pmc_fini(pmc);
+ return -1;
+ } else
+ pr_warn("No pagemap for %d available, "
+ "switching to greedy mode\n", pid);
}
pr_debug("created for pid %d (takes %zu bytes)\n", pid, pmc->map_len);
@@ -120,10 +124,19 @@ static int pmc_fill_cache(pmc_t *pmc, struct vma_area *vma)
size_map = PAGEMAP_LEN(pmc->end - pmc->start);
BUG_ON(pmc->map_len < size_map);
- if (pread(pmc->fd, pmc->map, size_map, PAGEMAP_PFN_OFF(pmc->start)) != size_map) {
- pmc_zap(pmc);
- pr_perror("Can't read %d's pagemap file", pmc->pid);
- return -1;
+ if (unlikely(pmc->fd < 0)) {
+ /*
+ * We don't have access to the dumpee pagemap so fill
+ * everything as present. It's better than refuse
+ * to dump because it simply disables optimisation.
+ */
+ memset(pmc->map, 1, size_map);
+ } else {
+ if (pread(pmc->fd, pmc->map, size_map, PAGEMAP_PFN_OFF(pmc->start)) != size_map) {
+ pmc_zap(pmc);
+ pr_perror("Can't read %d's pagemap file", pmc->pid);
+ return -1;
+ }
}
return 0;
--
2.4.3
More information about the CRIU
mailing list