[13/13] image-desc: Encode pagemap in unsigned long format

Submitted by Cyrill Gorcunov on Oct. 19, 2017, 9:59 p.m.

Details

Message ID 1508450384-29215-14-git-send-email-gorcunov@openvz.org
State New
Series "Clean up image format and fix anon shmem bits strip"
Headers show

Commit Message

Cyrill Gorcunov Oct. 19, 2017, 9:59 p.m.
The anonymous shared memory are using shmid for image
name encoding which is unsigned long and we already
met scenario where high bits get strippped off thus
the restore failed.

Lets use unsigned long here, and because pagemap code
is shared between plain memory and anon shared memory
use unsigned long every where.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
---
 criu/cr-dedup.c          | 20 ++++++++++----------
 criu/image-desc.c        |  4 ++--
 criu/include/page-xfer.h |  8 ++++----
 criu/include/pagemap.h   |  6 +++---
 criu/page-xfer.c         | 44 ++++++++++++++++++++++----------------------
 criu/pagemap.c           | 38 +++++++++++++++++++-------------------
 6 files changed, 60 insertions(+), 60 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-dedup.c b/criu/cr-dedup.c
index e84303f2c7f5..71b7a9cc340b 100644
--- a/criu/cr-dedup.c
+++ b/criu/cr-dedup.c
@@ -8,12 +8,12 @@ 
 #include "pagemap.h"
 #include "restorer.h"
 
-static int cr_dedup_one_pagemap(int id, int flags);
+static int cr_dedup_one_pagemap(unsigned long img_id, int flags);
 
 int cr_dedup(void)
 {
 	int close_ret, ret = 0;
-	int id;
+	unsigned long img_id;
 	DIR * dirp;
 	struct dirent *ent;
 
@@ -36,18 +36,18 @@  int cr_dedup(void)
 			break;
 		}
 
-		ret = sscanf(ent->d_name, "pagemap-%d.img", &id);
+		ret = sscanf(ent->d_name, "pagemap-%lu.img", &img_id);
 		if (ret == 1) {
-			pr_info("pid=%d\n", id);
-			ret = cr_dedup_one_pagemap(id, PR_TASK);
+			pr_info("pid=%lu\n", img_id);
+			ret = cr_dedup_one_pagemap(img_id, PR_TASK);
 			if (ret < 0)
 				break;
 		}
 
-		ret = sscanf(ent->d_name, "pagemap-shmem-%d.img", &id);
+		ret = sscanf(ent->d_name, "pagemap-shmem-%lu.img", &img_id);
 		if (ret == 1) {
-			pr_info("shmid=%d\n", id);
-			ret = cr_dedup_one_pagemap(id, PR_SHMEM);
+			pr_info("shmid=%lu\n", img_id);
+			ret = cr_dedup_one_pagemap(img_id, PR_SHMEM);
 			if (ret < 0)
 				break;
 		}
@@ -67,14 +67,14 @@  int cr_dedup(void)
 	return 0;
 }
 
-static int cr_dedup_one_pagemap(int id, int flags)
+static int cr_dedup_one_pagemap(unsigned long img_id, int flags)
 {
 	int ret;
 	struct page_read pr;
 	struct page_read * prp;
 
 	flags |= PR_MOD;
-	ret = open_page_read(id, &pr, flags);
+	ret = open_page_read(img_id, &pr, flags);
 	if (ret <= 0)
 		return -1;
 
diff --git a/criu/image-desc.c b/criu/image-desc.c
index 3ce8f854de27..c4ec97a3aa49 100644
--- a/criu/image-desc.c
+++ b/criu/image-desc.c
@@ -27,8 +27,8 @@ 
 struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = {
 	FD_ENTRY(INVENTORY,	"inventory"),
 	FD_ENTRY(FDINFO,	"fdinfo-%u"),
-	FD_ENTRY(PAGEMAP,	"pagemap-%ld"),
-	FD_ENTRY(SHMEM_PAGEMAP,	"pagemap-shmem-%ld"),
+	FD_ENTRY(PAGEMAP,	"pagemap-%lu"),
+	FD_ENTRY(SHMEM_PAGEMAP,	"pagemap-shmem-%lu"),
 	FD_ENTRY(REG_FILES,	"reg-files"),
 	FD_ENTRY(EXT_FILES,	"ext-files"),
 	FD_ENTRY(NS_FILES,	"ns-files"),
diff --git a/criu/include/page-xfer.h b/criu/include/page-xfer.h
index ffb6b08ac16f..ee90ae65acad 100644
--- a/criu/include/page-xfer.h
+++ b/criu/include/page-xfer.h
@@ -45,14 +45,14 @@  struct page_xfer {
 	struct page_read *parent;
 };
 
-extern int open_page_xfer(struct page_xfer *xfer, int fd_type, long id);
+extern int open_page_xfer(struct page_xfer *xfer, int fd_type, unsigned long id);
 struct page_pipe;
 extern int page_xfer_dump_pages(struct page_xfer *, struct page_pipe *);
 extern int connect_to_page_server_to_send(void);
 extern int connect_to_page_server_to_recv(int epfd);
 extern int disconnect_from_page_server(void);
 
-extern int check_parent_page_xfer(int fd_type, long id);
+extern int check_parent_page_xfer(int fd_type, unsigned long id);
 
 /*
  * The post-copy migration makes it necessary to receive pages from
@@ -65,9 +65,9 @@  extern int check_parent_page_xfer(int fd_type, long id);
  */
 
 /* async request/receive of remote pages */
-extern int request_remote_pages(int pid, unsigned long addr, int nr_pages);
+extern int request_remote_pages(unsigned long img_id, unsigned long addr, int nr_pages);
 
-typedef int (*ps_async_read_complete)(int pid, unsigned long vaddr, int nr_pages, void *);
+typedef int (*ps_async_read_complete)(unsigned long img_id, unsigned long vaddr, int nr_pages, void *);
 extern int page_server_start_read(void *buf, int nr_pages,
 		ps_async_read_complete complete, void *priv, unsigned flags);
 
diff --git a/criu/include/pagemap.h b/criu/include/pagemap.h
index 800768308067..45284b87df15 100644
--- a/criu/include/pagemap.h
+++ b/criu/include/pagemap.h
@@ -76,7 +76,7 @@  struct page_read {
 	struct iovec bunch;		/* record consequent neighbour
 					   iovecs to punch together */
 	unsigned id;			/* for logging */
-	int pid;			/* PID of the process */
+	unsigned long img_id;		/* pagemap image file ID */
 
 	PagemapEntry **pmes;
 	int nr_pmes;
@@ -102,8 +102,8 @@  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,
+extern int open_page_read(unsigned long id, struct page_read *, int pr_flags);
+extern int open_page_read_at(int dfd, unsigned long id, struct page_read *pr,
 		int pr_flags);
 
 struct task_restore_args;
diff --git a/criu/page-xfer.c b/criu/page-xfer.c
index 2c4c3bbfeb2a..814dc83674b2 100644
--- a/criu/page-xfer.c
+++ b/criu/page-xfer.c
@@ -61,7 +61,7 @@  static void psi2iovec(struct page_server_iov *ps, struct iovec *iov)
  * numbers that can be met from older CRIUs
  */
 
-static inline u64 encode_pm(int type, long id)
+static inline u64 encode_pm(int type, unsigned long id)
 {
 	if (type == CR_FD_PAGEMAP)
 		type = PS_TYPE_PID;
@@ -75,7 +75,7 @@  static inline u64 encode_pm(int type, long id)
 	return ((u64)id) << PS_TYPE_BITS | type;
 }
 
-static int decode_pm(u64 dst_id, long *id)
+static int decode_pm(u64 dst_id, unsigned long *id)
 {
 	int type;
 
@@ -174,7 +174,7 @@  static void close_server_xfer(struct page_xfer *xfer)
 	xfer->sk = -1;
 }
 
-static int open_page_server_xfer(struct page_xfer *xfer, int fd_type, long id)
+static int open_page_server_xfer(struct page_xfer *xfer, int fd_type, unsigned long img_id)
 {
 	char has_parent;
 	struct page_server_iov pi = {
@@ -185,7 +185,7 @@  static int open_page_server_xfer(struct page_xfer *xfer, int fd_type, long id)
 	xfer->write_pagemap = write_pagemap_to_server;
 	xfer->write_pages = write_pages_to_server;
 	xfer->close = close_server_xfer;
-	xfer->dst_id = encode_pm(fd_type, id);
+	xfer->dst_id = encode_pm(fd_type, img_id);
 	xfer->parent = NULL;
 
 	pi.dst_id = xfer->dst_id;
@@ -322,11 +322,11 @@  static void close_page_xfer(struct page_xfer *xfer)
 	close_image(xfer->pmi);
 }
 
-static int open_page_local_xfer(struct page_xfer *xfer, int fd_type, long id)
+static int open_page_local_xfer(struct page_xfer *xfer, int fd_type, unsigned long img_id)
 {
 	u32 pages_id;
 
-	xfer->pmi = open_image(fd_type, O_DUMP, id);
+	xfer->pmi = open_image(fd_type, O_DUMP, img_id);
 	if (!xfer->pmi)
 		return -1;
 
@@ -375,7 +375,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_flags);
+		ret = open_page_read_at(pfd, img_id, xfer->parent, pr_flags);
 		if (ret <= 0) {
 			pr_perror("No parent image found, though parent directory is set");
 			xfree(xfer->parent);
@@ -395,15 +395,15 @@  static int open_page_local_xfer(struct page_xfer *xfer, int fd_type, long id)
 	return 0;
 }
 
-int open_page_xfer(struct page_xfer *xfer, int fd_type, long id)
+int open_page_xfer(struct page_xfer *xfer, int fd_type, unsigned long img_id)
 {
 	xfer->offset = 0;
 	xfer->transfer_lazy = true;
 
 	if (opts.use_page_server)
-		return open_page_server_xfer(xfer, fd_type, id);
+		return open_page_server_xfer(xfer, fd_type, img_id);
 	else
-		return open_page_local_xfer(xfer, fd_type, id);
+		return open_page_local_xfer(xfer, fd_type, img_id);
 }
 
 static int page_xfer_dump_hole(struct page_xfer *xfer,
@@ -511,7 +511,7 @@  int page_xfer_dump_pages(struct page_xfer *xfer, struct page_pipe *pp)
  *	 0 - if a parent image doesn't exist
  *	-1 - in error cases
  */
-int check_parent_local_xfer(int fd_type, int id)
+int check_parent_local_xfer(int fd_type, unsigned long img_id)
 {
 	char path[PATH_MAX];
 	struct stat st;
@@ -524,7 +524,7 @@  int check_parent_local_xfer(int fd_type, int id)
 	if (pfd < 0 && errno == ENOENT)
 		return 0;
 
-	snprintf(path, sizeof(path), imgset_template[fd_type].fmt, id);
+	snprintf(path, sizeof(path), imgset_template[fd_type].fmt, img_id);
 	ret = fstatat(pfd, path, &st, 0);
 	if (ret == -1 && errno != ENOENT) {
 		pr_perror("Unable to stat %s", path);
@@ -540,7 +540,7 @@  int check_parent_local_xfer(int fd_type, int id)
 static int page_server_check_parent(int sk, struct page_server_iov *pi)
 {
 	int type, ret;
-	long id;
+	unsigned long id;
 
 	type = decode_pm(pi->dst_id, &id);
 	if (type == -1) {
@@ -560,13 +560,13 @@  static int page_server_check_parent(int sk, struct page_server_iov *pi)
 	return 0;
 }
 
-static int check_parent_server_xfer(int fd_type, long id)
+static int check_parent_server_xfer(int fd_type, unsigned long img_id)
 {
 	struct page_server_iov pi = {};
 	int has_parent;
 
 	pi.cmd = PS_IOV_PARENT;
-	pi.dst_id = encode_pm(fd_type, id);
+	pi.dst_id = encode_pm(fd_type, img_id);
 
 	if (send_psi(page_server_sk, &pi))
 		return -1;
@@ -581,12 +581,12 @@  static int check_parent_server_xfer(int fd_type, long id)
 	return has_parent;
 }
 
-int check_parent_page_xfer(int fd_type, long id)
+int check_parent_page_xfer(int fd_type, unsigned long img_id)
 {
 	if (opts.use_page_server)
-		return check_parent_server_xfer(fd_type, id);
+		return check_parent_server_xfer(fd_type, img_id);
 	else
-		return check_parent_local_xfer(fd_type, id);
+		return check_parent_local_xfer(fd_type, img_id);
 }
 
 struct page_xfer_job {
@@ -618,7 +618,7 @@  static void page_server_close(void)
 static int page_server_open(int sk, struct page_server_iov *pi)
 {
 	int type;
-	long id;
+	unsigned long id;
 
 	type = decode_pm(pi->dst_id, &id);
 	if (type == -1) {
@@ -626,7 +626,7 @@  static int page_server_open(int sk, struct page_server_iov *pi)
 		return -1;
 	}
 
-	pr_info("Opening %d/%ld\n", type, id);
+	pr_info("Opening %d/%lu\n", type, id);
 
 	page_server_close();
 
@@ -1212,13 +1212,13 @@  int connect_to_page_server_to_recv(int epfd)
 	return epoll_add_rfd(epfd, &ps_rfd);
 }
 
-int request_remote_pages(int pid, unsigned long addr, int nr_pages)
+int request_remote_pages(unsigned long img_id, unsigned long addr, int nr_pages)
 {
 	struct page_server_iov pi = {
 		.cmd		= PS_IOV_GET,
 		.nr_pages	= nr_pages,
 		.vaddr		= addr,
-		.dst_id		= pid,
+		.dst_id		= img_id,
 	};
 
 	/* XXX: why MSG_DONTWAIT here? */
diff --git a/criu/pagemap.c b/criu/pagemap.c
index f7e1173f9aab..a61a954507c0 100644
--- a/criu/pagemap.c
+++ b/criu/pagemap.c
@@ -55,7 +55,7 @@  static int punch_hole(struct page_read *pr, unsigned long off,
 	struct iovec * bunch = &pr->bunch;
 
 	if (!cleanup && can_extend_bunch(bunch, off, len)) {
-		pr_debug("pr%d-%d:Extend bunch len from %zu to %lu\n", pr->pid,
+		pr_debug("pr%lu-%u:Extend bunch len from %zu to %lu\n", pr->img_id,
 			 pr->id, bunch->iov_len, bunch->iov_len + len);
 		bunch->iov_len += len;
 	} else {
@@ -70,7 +70,7 @@  static int punch_hole(struct page_read *pr, unsigned long off,
 		}
 		bunch->iov_base = (void *)off;
 		bunch->iov_len = len;
-		pr_debug("pr%d-%d:New bunch/%p/%zu/\n", pr->pid, pr->id, bunch->iov_base, bunch->iov_len);
+		pr_debug("pr%lu-%u:New bunch/%p/%zu/\n", pr->img_id, pr->id, bunch->iov_base, bunch->iov_len);
 	}
 	return 0;
 }
@@ -206,7 +206,7 @@  static int read_parent_page(struct page_read *pr, unsigned long vaddr,
 	do {
 		int p_nr;
 
-		pr_debug("\tpr%d-%u Read from parent\n", pr->pid, pr->id);
+		pr_debug("\tpr%lu-%u Read from parent\n", pr->img_id, pr->id);
 		ret = ppr->seek_pagemap(ppr, vaddr);
 		if (ret <= 0) {
 			pr_err("Missing %lx in parent pagemap\n", vaddr);
@@ -253,7 +253,7 @@  static int read_local_page(struct page_read *pr, unsigned long vaddr,
 	if (pr->sync(pr))
 		return -1;
 
-	pr_debug("\tpr%d-%u Read page from self %lx/%"PRIx64"\n", pr->pid, pr->id, pr->cvaddr, pr->pi_off);
+	pr_debug("\tpr%lu-%u Read page from self %lx/%"PRIx64"\n", pr->img_id, pr->id, pr->cvaddr, pr->pi_off);
 	ret = pread(fd, buf, len, pr->pi_off);
 	if (ret != len) {
 		pr_perror("Can't read mapping page %d", ret);
@@ -409,7 +409,7 @@  static int maybe_read_page_img_cache(struct page_read *pr, unsigned long vaddr,
 	int ret;
 	size_t curr = 0;
 
-	pr_debug("\tpr%d-%u Read page from self %lx/%"PRIx64"\n", pr->pid, pr->id, pr->cvaddr, pr->pi_off);
+	pr_debug("\tpr%lu-%u Read page from self %lx/%"PRIx64"\n", pr->img_id, pr->id, pr->cvaddr, pr->pi_off);
 	while (1) {
 		ret = read(fd, buf + curr, len - curr);
 		if (ret < 0) {
@@ -432,14 +432,14 @@  static int maybe_read_page_img_cache(struct page_read *pr, unsigned long vaddr,
 	return ret;
 }
 
-static int read_page_complete(int pid, unsigned long vaddr, int nr_pages, void *priv)
+static int read_page_complete(unsigned long img_id, unsigned long vaddr, int nr_pages, void *priv)
 {
 	int ret = 0;
 	struct page_read *pr = priv;
 
-	if (pr->pid != pid) {
-		pr_err("Out of order read completed (want %d have %d)\n",
-				pr->pid, pid);
+	if (pr->img_id != img_id) {
+		pr_err("Out of order read completed (want %lu have %lu)\n",
+				pr->img_id, img_id);
 		return -1;
 	}
 
@@ -457,7 +457,7 @@  static int maybe_read_page_remote(struct page_read *pr, unsigned long vaddr,
 	int ret;
 
 	/* We always do PR_ASAP mode here (FIXME?) */
-	ret = request_remote_pages(pr->pid, vaddr, nr);
+	ret = request_remote_pages(pr->img_id, vaddr, nr);
 	if (!ret)
 		ret = page_server_start_read(buf, nr,
 				read_page_complete, pr, flags);
@@ -467,7 +467,7 @@  static int maybe_read_page_remote(struct page_read *pr, unsigned long vaddr,
 static int read_pagemap_page(struct page_read *pr, unsigned long vaddr, int nr,
 			     void *buf, unsigned flags)
 {
-	pr_info("pr%d-%u Read %lx %u pages\n", pr->pid, pr->id, vaddr, nr);
+	pr_info("pr%lu-%u Read %lx %u pages\n", pr->img_id, pr->id, vaddr, nr);
 	pagemap_bound_check(pr->pe, vaddr, nr);
 
 	if (pagemap_in_parent(pr->pe)) {
@@ -623,7 +623,7 @@  static void reset_pagemap(struct page_read *pr)
 		reset_pagemap(pr->parent);
 }
 
-static int try_open_parent(int dfd, int pid, struct page_read *pr, int pr_flags)
+static int try_open_parent(int dfd, unsigned long id, struct page_read *pr, int pr_flags)
 {
 	int pfd, ret;
 	struct page_read *parent = NULL;
@@ -651,7 +651,7 @@  static int try_open_parent(int dfd, int pid, struct page_read *pr, int pr_flags)
 	if (!parent)
 		goto err_cl;
 
-	ret = open_page_read_at(pfd, pid, parent, pr_flags);
+	ret = open_page_read_at(pfd, id, parent, pr_flags);
 	if (ret < 0)
 		goto err_free;
 
@@ -756,7 +756,7 @@  static int init_pagemaps(struct page_read *pr)
 	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, unsigned long img_id, struct page_read *pr, int pr_flags)
 {
 	int flags, i_typ;
 	static unsigned ids = 1;
@@ -796,7 +796,7 @@  int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)
 	pr->pmes = NULL;
 	pr->pieok = false;
 
-	pr->pmi = open_image_at(dfd, i_typ, O_RSTR, (long)pid);
+	pr->pmi = open_image_at(dfd, i_typ, O_RSTR, img_id);
 	if (!pr->pmi)
 		return -1;
 
@@ -805,7 +805,7 @@  int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)
 		return 0;
 	}
 
-	if (try_open_parent(dfd, pid, pr, pr_flags)) {
+	if (try_open_parent(dfd, img_id, pr, pr_flags)) {
 		close_image(pr->pmi);
 		return -1;
 	}
@@ -830,7 +830,7 @@  int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)
 	pr->reset = reset_pagemap;
 	pr->io_complete = NULL; /* set up by the client if needed */
 	pr->id = ids++;
-	pr->pid = pid;
+	pr->img_id = img_id;
 
 	if (opts.remote)
 		pr->maybe_read_page = maybe_read_page_img_cache;
@@ -849,9 +849,9 @@  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(unsigned long img_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), img_id, pr, pr_flags);
 }