[CRIU] [PATCH v9 07/10] inventory: add a helper to get entry of parent pre-dump

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


will be used in the next patch

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

note: actually we need only one value from inventory entry but I still
prefer general helper as we still need to read and allocate memory
for the whole structure

v2: fix get_parent_stats to have static typing
v3: simplify get_parent_stats to return a StatsEntry pointer instead of
doing it through arguments
v8: replace errors with warnings, we should whatch on them only if we
have corresponding error in detect_pid_reuse else they are fine
v9: change stats to inventory image

Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 criu/image.c           | 37 +++++++++++++++++++++++++++++++++++++
 criu/include/crtools.h |  1 +
 2 files changed, 38 insertions(+)

diff --git a/criu/image.c b/criu/image.c
index 2667863db..6dbeebe8d 100644
--- a/criu/image.c
+++ b/criu/image.c
@@ -123,6 +123,43 @@ void prepare_inventory_pre_dump(InventoryEntry *he)
 		he->has_dump_uptime = true;
 }
 
+__maybe_unused InventoryEntry *get_parent_inventory(void)
+{
+	struct cr_img *img;
+	InventoryEntry *ie;
+	int dir;
+
+	dir = openat(get_service_fd(IMG_FD_OFF), CR_PARENT_LINK, O_RDONLY);
+	if (dir == -1) {
+		pr_warn("Failed to open parent directory");
+		return NULL;
+	}
+
+	img = open_image_at(dir, CR_FD_INVENTORY, O_RSTR);
+	if (!img) {
+		pr_warn("Failed to open parent pre-dump inventory image");
+		close(dir);
+		return NULL;
+	}
+
+	if (pb_read_one(img, &ie, PB_INVENTORY) < 0) {
+		pr_warn("Failed to read parent pre-dump inventory entry");
+		close_image(img);
+		close(dir);
+		return NULL;
+	}
+
+	if (!ie->has_dump_uptime) {
+		pr_warn("Parent pre-dump inventory has no uptime");
+		inventory_entry__free_unpacked(ie, NULL);
+		ie = NULL;
+	}
+
+	close_image(img);
+	close(dir);
+	return ie;
+}
+
 int prepare_inventory(InventoryEntry *he)
 {
 	struct pid pid;
diff --git a/criu/include/crtools.h b/criu/include/crtools.h
index 88d2220a4..2c21e822a 100644
--- a/criu/include/crtools.h
+++ b/criu/include/crtools.h
@@ -13,6 +13,7 @@
 extern int check_img_inventory(void);
 extern int write_img_inventory(InventoryEntry *he);
 extern void prepare_inventory_pre_dump(InventoryEntry *he);
+extern InventoryEntry *get_parent_inventory(void);
 extern int prepare_inventory(InventoryEntry *he);
 struct pprep_head {
 	int (*actor)(struct pprep_head *);
-- 
2.14.3



More information about the CRIU mailing list