[CRIU] [PATCH 1/3] criu: pagemap: track current offset into pages*img
Mike Rapoport
rppt at linux.vnet.ibm.com
Sun Jun 26 21:53:20 PDT 2016
instead if doing lseek
Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
criu/include/pagemap.h | 1 +
criu/pagemap.c | 12 +++++++-----
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/criu/include/pagemap.h b/criu/include/pagemap.h
index 0c731ce..5e6c4b2 100644
--- a/criu/include/pagemap.h
+++ b/criu/include/pagemap.h
@@ -64,6 +64,7 @@ struct page_read {
go to this guy for page, see
read_pagemap_page */
unsigned long cvaddr; /* vaddr we are on */
+ off_t pi_off; /* current offset in pages file */
struct iovec bunch; /* record consequent neighbour
iovecs to punch together */
diff --git a/criu/pagemap.c b/criu/pagemap.c
index 08e3945..7babca3 100644
--- a/criu/pagemap.c
+++ b/criu/pagemap.c
@@ -68,7 +68,6 @@ static int punch_hole(struct page_read *pr, unsigned long off,
int dedup_one_iovec(struct page_read *pr, struct iovec *iov)
{
unsigned long off;
- unsigned long off_real;
unsigned long iov_end;
iov_end = (unsigned long)iov->iov_base + iov->iov_len;
@@ -95,9 +94,8 @@ int dedup_one_iovec(struct page_read *pr, struct iovec *iov)
return -1;
pagemap2iovec(pr->pe, &piov);
piov_end = (unsigned long)piov.iov_base + piov.iov_len;
- off_real = lseek(img_raw_fd(pr->pi), 0, SEEK_CUR);
if (!pr->pe->in_parent) {
- ret = punch_hole(pr, off_real, min(piov_end, iov_end) - off, false);
+ ret = punch_hole(pr, pr->pi_off, min(piov_end, iov_end) - off, false);
if (ret == -1)
return ret;
}
@@ -156,7 +154,7 @@ static void skip_pagemap_pages(struct page_read *pr, unsigned long len)
pr_debug("\tpr%u Skip %lu bytes from page-dump\n", pr->id, len);
if (!pr->pe->in_parent)
- lseek(img_raw_fd(pr->pi), len, SEEK_CUR);
+ pr->pi_off += len;
pr->cvaddr += len;
}
@@ -259,7 +257,7 @@ static int read_pagemap_page(struct page_read *pr, unsigned long vaddr, int nr,
} while (nr);
} else {
int fd = img_raw_fd(pr->pi);
- off_t current_vaddr = lseek(fd, 0, SEEK_CUR);
+ off_t current_vaddr = lseek(fd, pr->pi_off, SEEK_SET);
pr_debug("\tpr%u Read page from self %lx/%"PRIx64"\n", pr->id, pr->cvaddr, current_vaddr);
ret = read(fd, buf, len);
@@ -268,6 +266,8 @@ static int read_pagemap_page(struct page_read *pr, unsigned long vaddr, int nr,
return -1;
}
+ pr->pi_off += len;
+
if (opts.auto_dedup) {
ret = punch_hole(pr, current_vaddr, len, false);
if (ret == -1) {
@@ -431,6 +431,8 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)
pr->pe = NULL;
pr->parent = NULL;
+ pr->cvaddr = 0;
+ pr->pi_off = 0;
pr->bunch.iov_len = 0;
pr->bunch.iov_base = NULL;
--
1.9.1
More information about the CRIU
mailing list