From fb90982db536e429bffd45d77d5bb6d33c4af9ac Mon Sep 17 00:00:00 2001 From: Mike Rapoport Date: Mon, 6 Feb 2017 13:44:11 +0200 Subject: [PATCH] page-read: introduce dup_page_read The dup_page_read performs a shallow copy of a page_read object. It is required for implementation of fork event in lazy-pages daemon. When a restored process fork()'s a child, the lazy-pages daemon will handle page faults of the child process, and it will use the parent process memory dump for that. travis-ci: success for lazy-pages: add non-#PF events handling (rev2) Signed-off-by: Mike Rapoport Signed-off-by: Pavel Emelyanov --- criu/include/pagemap.h | 7 +++++++ criu/pagemap.c | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/criu/include/pagemap.h b/criu/include/pagemap.h index db9fae53c..d0a28b9f1 100644 --- a/criu/include/pagemap.h +++ b/criu/include/pagemap.h @@ -112,6 +112,13 @@ int pagemap_enqueue_iovec(struct page_read *pr, void *buf, unsigned long len, struct list_head *to); int pagemap_render_iovec(struct list_head *from, struct task_restore_args *ta); +/* + * Create a shallow copy of page_read object. + * The new object shares the pagemap structures with the original, but + * maintains its own set of references to those structures. + */ +extern void dup_page_read(struct page_read *src, struct page_read *dst); + extern int dedup_one_iovec(struct page_read *pr, unsigned long base, unsigned long len); diff --git a/criu/pagemap.c b/criu/pagemap.c index cb83caa14..f4035042d 100644 --- a/criu/pagemap.c +++ b/criu/pagemap.c @@ -819,3 +819,16 @@ 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, pr_flags); } + + +#define DUP_IDS_BASE 1000 + +void dup_page_read(struct page_read *src, struct page_read *dst) +{ + static int dup_ids = 1; + + memcpy(dst, src, sizeof(*dst)); + INIT_LIST_HEAD(&dst->async); + dst->id = src->id + DUP_IDS_BASE * dup_ids++; + dst->reset(dst); +}