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); +}