[1/2] vz7: image-desc -- Make pagemap and pagemap-shmem images to use lu

Submitted by Cyrill Gorcunov on Oct. 18, 2017, 10:01 a.m.

Details

Message ID 1508320902-26535-2-git-send-email-gorcunov@virtuozzo.com
State New
Series "vz7: Fix id trimming in pagemap- images"
Headers show

Commit Message

Cyrill Gorcunov Oct. 18, 2017, 10:01 a.m.
The @shmid is unsigned long and may overflow the integer so we loose
the bijective mapping between image names and their ids. Thus use
unsigned long here.

https://jira.sw.ru/browse/PSBM-75112

Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>
---
 criu/cr-dedup.c        | 12 ++++++------
 criu/image-desc.c      |  4 ++--
 criu/include/pagemap.h |  4 ++--
 criu/page-xfer.c       |  2 +-
 criu/pagemap.c         | 14 +++++++-------
 5 files changed, 18 insertions(+), 18 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-dedup.c b/criu/cr-dedup.c
index d103ddf..93af9be 100644
--- a/criu/cr-dedup.c
+++ b/criu/cr-dedup.c
@@ -8,7 +8,7 @@ 
 #include "pagemap.h"
 #include "restorer.h"
 
-static int cr_dedup_one_pagemap(int id, int flags);
+static int cr_dedup_one_pagemap(unsigned long id, int flags);
 
 int cr_dedup(void)
 {
@@ -36,17 +36,17 @@  int cr_dedup(void)
 			break;
 		}
 
-		ret = sscanf(ent->d_name, "pagemap-%d.img", &id);
+		ret = sscanf(ent->d_name, "pagemap-%lu.img", &id);
 		if (ret == 1) {
-			pr_info("pid=%d\n", id);
+			pr_info("pid=%lu\n", id);
 			ret = cr_dedup_one_pagemap(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", &id);
 		if (ret == 1) {
-			pr_info("shmid=%d\n", id);
+			pr_info("shmid=%lu\n", id);
 			ret = cr_dedup_one_pagemap(id, PR_SHMEM);
 			if (ret < 0)
 				break;
@@ -67,7 +67,7 @@  int cr_dedup(void)
 	return 0;
 }
 
-static int cr_dedup_one_pagemap(int id, int flags)
+static int cr_dedup_one_pagemap(unsigned long id, int flags)
 {
 	int ret;
 	struct page_read pr;
diff --git a/criu/image-desc.c b/criu/image-desc.c
index 7fedf1a..58e8bf7 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-%d"),
-	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/pagemap.h b/criu/include/pagemap.h
index b993c47..7ab19d6 100644
--- a/criu/include/pagemap.h
+++ b/criu/include/pagemap.h
@@ -96,8 +96,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 img_id, struct page_read *, int pr_flags);
+extern int open_page_read_at(int dfd, unsigned long img_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 f729334..14cfdbe 100644
--- a/criu/page-xfer.c
+++ b/criu/page-xfer.c
@@ -467,7 +467,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 id)
 {
 	char path[PATH_MAX];
 	struct stat st;
diff --git a/criu/pagemap.c b/criu/pagemap.c
index 0292576..6644849 100644
--- a/criu/pagemap.c
+++ b/criu/pagemap.c
@@ -560,7 +560,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 img_id, struct page_read *pr, int pr_flags)
 {
 	int pfd, ret;
 	struct page_read *parent = NULL;
@@ -573,7 +573,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, img_id, parent, pr_flags);
 	if (ret < 0)
 		goto err_free;
 
@@ -649,7 +649,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;
@@ -683,7 +683,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;
 
@@ -692,7 +692,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;
 	}
@@ -725,7 +725,7 @@  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);
 }