[CRIU] [PATCH 2/3] inventory: save dump_uptime for criu dump if track_mem is set

Andrei Vagin avagin at virtuozzo.com
Sat Apr 28 09:02:30 MSK 2018


A set of images from criu dump can be used as a previous point, when we
are doing snapshots. In this case, each point contains a full set of
images.

https://github.com/checkpoint-restore/criu/issues/479

Cc: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/cr-dump.c         |  7 ++++++-
 criu/image.c           | 16 +++++++++++-----
 criu/include/crtools.h |  2 +-
 criu/mem.c             | 12 ++++++------
 4 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 00b84feed..e75783f2f 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -1577,7 +1577,9 @@ static int cr_pre_dump_finish(int ret)
 	if (arch_set_thread_regs(root_item, false) < 0)
 		goto err;
 
-	prepare_inventory_pre_dump(&he);
+	if (invertory_save_uptime(&he))
+		goto err;
+
 	pstree_switch_state(root_item, TASK_ALIVE);
 
 	timing_stop(TIME_FROZEN);
@@ -2008,6 +2010,9 @@ int cr_dump_tasks(pid_t pid)
 	if (ret)
 		goto err;
 
+	if (invertory_save_uptime(&he))
+		goto err;
+
 	ret = write_img_inventory(&he);
 	if (ret)
 		goto err;
diff --git a/criu/image.c b/criu/image.c
index fcdc081c1..108471b36 100644
--- a/criu/image.c
+++ b/criu/image.c
@@ -113,14 +113,20 @@ int write_img_inventory(InventoryEntry *he)
 	return 0;
 }
 
-void prepare_inventory_pre_dump(InventoryEntry *he)
+int invertory_save_uptime(InventoryEntry *he)
 {
-	pr_info("Perparing image inventory for pre-dump (version %u)\n", CRTOOLS_IMAGES_V1);
+	if (!opts.track_mem)
+		return 0;
 
-	he->img_version = CRTOOLS_IMAGES_V1_1;
+	/*
+	 * dump_uptime is used to detect whether a process was handled
+	 * before or it is a new process with the same pid.
+	 */
+	if (parse_uptime(&he->dump_uptime))
+		return -1;
 
-	if (!parse_uptime(&he->dump_uptime))
-		he->has_dump_uptime = true;
+	he->has_dump_uptime = true;
+	return 0;
 }
 
 InventoryEntry *get_parent_inventory(void)
diff --git a/criu/include/crtools.h b/criu/include/crtools.h
index 2c21e822a..7b2dc4523 100644
--- a/criu/include/crtools.h
+++ b/criu/include/crtools.h
@@ -12,7 +12,7 @@
 
 extern int check_img_inventory(void);
 extern int write_img_inventory(InventoryEntry *he);
-extern void prepare_inventory_pre_dump(InventoryEntry *he);
+extern int invertory_save_uptime(InventoryEntry *he);
 extern InventoryEntry *get_parent_inventory(void);
 extern int prepare_inventory(InventoryEntry *he);
 struct pprep_head {
diff --git a/criu/mem.c b/criu/mem.c
index dc67fc50d..289f36297 100644
--- a/criu/mem.c
+++ b/criu/mem.c
@@ -299,6 +299,12 @@ static int detect_pid_reuse(struct pstree_item *item,
 	unsigned long long tps; /* ticks per second */
 	int ret;
 
+	if (!parent_ie) {
+		pr_err("Pid-reuse detection failed: no parent inventory, " \
+		       "check warnings in get_parent_stats\n");
+		return -1;
+	}
+
 	tps = sysconf(_SC_CLK_TCK);
 	if (tps == -1) {
 		pr_perror("Failed to get clock ticks via sysconf");
@@ -312,12 +318,6 @@ static int detect_pid_reuse(struct pstree_item *item,
 			return -1;
 	}
 
-	if (!parent_ie) {
-		pr_err("Pid-reuse detection failed: no parent inventory, " \
-		       "check warnings in get_parent_stats\n");
-		return -1;
-	}
-
 	dump_ticks = parent_ie->dump_uptime/(USEC_PER_SEC/tps);
 
 	if (pps->start_time >= dump_ticks) {
-- 
2.14.3



More information about the CRIU mailing list