[CRIU] [PATCH v9 06/10] inventory: save uptime to know when dump had happened

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Tue Apr 3 12:34:22 MSK 2018


We want to use a simple fact: If we have an alive process in a pstree we
want to dump, and a starttime of that process is less than pre-dump's
timestamp (taken while all processes were freezed), then these exact
process existed (100% sure) at the time of these pre-dump and the
process' memory was dumped in images.

So save inventory image on pre-dump and put there an uptime.

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

v9: improve comment, put uptime to ivnentory image as 1) where is no
stats in parent images directory if --work-dir option is set to
something different then images directory, 2) stats-dump is not an image
and it is a bad practice to put there data required for restoring.

Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 criu/cr-dump.c         |  6 ++++++
 criu/image.c           | 11 +++++++++++
 criu/include/crtools.h |  1 +
 criu/proc_parse.c      |  2 +-
 images/inventory.proto |  1 +
 5 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 0f4f438b3..35c4d512f 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -1563,6 +1563,7 @@ static int setup_alarm_handler()
 
 static int cr_pre_dump_finish(int ret)
 {
+	InventoryEntry he = INVENTORY_ENTRY__INIT;
 	struct pstree_item *item;
 
 	/*
@@ -1571,6 +1572,8 @@ static int cr_pre_dump_finish(int ret)
 	 */
 	if (arch_set_thread_regs(root_item, false) < 0)
 		goto err;
+
+	prepare_inventory_pre_dump(&he);
 	pstree_switch_state(root_item, TASK_ALIVE);
 
 	timing_stop(TIME_FROZEN);
@@ -1621,6 +1624,9 @@ static int cr_pre_dump_finish(int ret)
 	if (bfd_flush_images())
 		ret = -1;
 
+	if (write_img_inventory(&he))
+		ret = -1;
+
 	if (ret)
 		pr_err("Pre-dumping FAILED.\n");
 	else {
diff --git a/criu/image.c b/criu/image.c
index 9201f6a30..2667863db 100644
--- a/criu/image.c
+++ b/criu/image.c
@@ -17,6 +17,7 @@
 #include "images/inventory.pb-c.h"
 #include "images/pagemap.pb-c.h"
 #include "img-remote.h"
+#include "proc_parse.h"
 
 bool ns_per_id = false;
 bool img_common_magic = true;
@@ -112,6 +113,16 @@ int write_img_inventory(InventoryEntry *he)
 	return 0;
 }
 
+void prepare_inventory_pre_dump(InventoryEntry *he)
+{
+	pr_info("Perparing image inventory for pre-dump (version %u)\n", CRTOOLS_IMAGES_V1);
+
+	he->img_version = CRTOOLS_IMAGES_V1_1;
+
+	if (!parse_uptime(&he->dump_uptime))
+		he->has_dump_uptime = true;
+}
+
 int prepare_inventory(InventoryEntry *he)
 {
 	struct pid pid;
diff --git a/criu/include/crtools.h b/criu/include/crtools.h
index a78a577cd..88d2220a4 100644
--- a/criu/include/crtools.h
+++ b/criu/include/crtools.h
@@ -12,6 +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 prepare_inventory(InventoryEntry *he);
 struct pprep_head {
 	int (*actor)(struct pprep_head *);
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 387a90323..5bd56b3bc 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -2715,7 +2715,7 @@ int parse_children(pid_t pid, pid_t **_c, int *_n)
 
 #define CSEC_PER_SEC 100
 
-__maybe_unused int parse_uptime(u_int64_t *upt)
+int parse_uptime(u_int64_t *upt)
 {
 	unsigned long sec, csec;
 	FILE *f;
diff --git a/images/inventory.proto b/images/inventory.proto
index 5bc3db240..3e64602c4 100644
--- a/images/inventory.proto
+++ b/images/inventory.proto
@@ -16,4 +16,5 @@ message inventory_entry {
 	optional uint32			root_cg_set	= 5;
 	optional lsmtype		lsmtype		= 6;
 	optional bool			check_only	= 7;
+	optional uint64			dump_uptime	= 8;
 }
-- 
2.14.3



More information about the CRIU mailing list