[CRIU] [PATCH] dump: write an inventory image after dumping all processes

Andrey Vagin avagin at openvz.org
Fri Dec 25 09:20:31 PST 2015


Currently if criu segfaulted, the inventory image isn't removed and
we can't detect that images are incomplete.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 cr-dump.c         |  7 +++++--
 image.c           | 57 +++++++++++++++++++++++++++----------------------------
 include/crtools.h |  7 +++++--
 3 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index af398b6..2fa6ade 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1569,7 +1569,6 @@ static int cr_dump_finish(int ret)
 	close_service_fd(CR_PROC_FD_OFF);
 
 	if (ret) {
-		kill_inventory();
 		pr_err("Dumping FAILED.\n");
 	} else {
 		write_stats(DUMP_STATS);
@@ -1587,6 +1586,7 @@ void dump_alarm_handler(int signum)
 
 int cr_dump_tasks(pid_t pid)
 {
+	InventoryEntry he = INVENTORY_ENTRY__INIT;
 	struct pstree_item *item;
 	int pre_dump_ret = 0;
 	int ret = -1;
@@ -1621,7 +1621,7 @@ int cr_dump_tasks(pid_t pid)
 	if (parse_cg_info())
 		goto err;
 
-	if (write_img_inventory())
+	if (prepare_inventory(&he))
 		goto err;
 
 	if (opts.cpu_cap & (CPU_CAP_CPU | CPU_CAP_INS)) {
@@ -1704,6 +1704,9 @@ int cr_dump_tasks(pid_t pid)
 	if (ret)
 		goto err;
 
+	ret = write_img_inventory(&he);
+	if (ret)
+		goto err;
 err:
 	return cr_dump_finish(ret);
 }
diff --git a/image.c b/image.c
index dc9d6a1..a164722 100644
--- a/image.c
+++ b/image.c
@@ -77,14 +77,9 @@ out_close:
 	return ret;
 }
 
-int write_img_inventory(void)
+int write_img_inventory(InventoryEntry *he)
 {
 	struct cr_img *img;
-	InventoryEntry he = INVENTORY_ENTRY__INIT;
-	struct {
-		struct pstree_item i;
-		struct dmp_info d;
-	} crt = { };
 
 	pr_info("Writing image inventory (version %u)\n", CRTOOLS_IMAGES_V1);
 
@@ -92,40 +87,44 @@ int write_img_inventory(void)
 	if (!img)
 		return -1;
 
-	he.img_version = CRTOOLS_IMAGES_V1_1;
-	he.fdinfo_per_id = true;
-	he.has_fdinfo_per_id = true;
-	he.ns_per_id = true;
-	he.has_ns_per_id = true;
-	he.lsmtype = host_lsm_type();
+	if (pb_write_one(img, he, PB_INVENTORY) < 0)
+		return -1;
+
+	xfree(he->root_ids);
+	close_image(img);
+	return 0;
+}
+
+int prepare_inventory(InventoryEntry *he)
+{
+	struct {
+		struct pstree_item i;
+		struct dmp_info d;
+	} crt = { };
+
+	pr_info("Perparing image inventory (version %u)\n", CRTOOLS_IMAGES_V1);
+
+	he->img_version = CRTOOLS_IMAGES_V1_1;
+	he->fdinfo_per_id = true;
+	he->has_fdinfo_per_id = true;
+	he->ns_per_id = true;
+	he->has_ns_per_id = true;
+	he->lsmtype = host_lsm_type();
 
 	crt.i.state = TASK_ALIVE;
 	crt.i.pid.real = getpid();
-	if (get_task_ids(&crt.i)) {
-		close_image(img);
+	if (get_task_ids(&crt.i))
 		return -1;
-	}
 
-	he.has_root_cg_set = true;
-	if (dump_task_cgroup(NULL, &he.root_cg_set))
+	he->has_root_cg_set = true;
+	if (dump_task_cgroup(NULL, &he->root_cg_set))
 		return -1;
 
-	he.root_ids = crt.i.ids;
+	he->root_ids = crt.i.ids;
 
-	if (pb_write_one(img, &he, PB_INVENTORY) < 0)
-		return -1;
-
-	xfree(crt.i.ids);
-	close_image(img);
 	return 0;
 }
 
-void kill_inventory(void)
-{
-	unlinkat(get_service_fd(IMG_FD_OFF),
-			imgset_template[CR_FD_INVENTORY].fmt, 0);
-}
-
 static struct cr_imgset *alloc_cr_imgset(int nr)
 {
 	struct cr_imgset *cr_imgset;
diff --git a/include/crtools.h b/include/crtools.h
index bbed0ef..eaa70dc 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -7,11 +7,14 @@
 #include "asm/types.h"
 #include "servicefd.h"
 
+#include "protobuf.h"
+#include "protobuf/inventory.pb-c.h"
+
 #define CR_FD_PERM		(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
 
 extern int check_img_inventory(void);
-extern int write_img_inventory(void);
-extern void kill_inventory(void);
+extern int write_img_inventory(InventoryEntry *he);
+extern int prepare_inventory(InventoryEntry *he);
 
 #define LAST_PID_PATH		"sys/kernel/ns_last_pid"
 
-- 
2.4.3



More information about the CRIU mailing list