[CRIU] [PATCH 06/14] crtools: put kobj-ids into separate image file

Andrey Vagin avagin at openvz.org
Fri Jan 11 04:22:37 EST 2013


It is read together with pstree items for checking what kind of
resources should be shared. Core is too big for reading it in
this place.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-dump.c          | 71 +++++++++++++++++++++++++++++++++---------------------
 cr-restore.c       |  2 +-
 cr-show.c          |  5 ++++
 image.c            |  1 +
 include/crtools.h  |  2 ++
 include/image.h    |  1 +
 include/protobuf.h |  1 +
 include/pstree.h   |  2 ++
 protobuf.c         |  1 +
 pstree.c           | 14 ++++++++++-
 10 files changed, 71 insertions(+), 29 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 130f885..7d8e2d3 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -659,7 +659,7 @@ static DECLARE_KCMP_TREE(fs_tree, KCMP_FS);
 static DECLARE_KCMP_TREE(files_tree, KCMP_FILES);
 static DECLARE_KCMP_TREE(sighand_tree, KCMP_SIGHAND);
 
-static int dump_task_kobj_ids(pid_t pid, CoreEntry *core)
+static int dump_task_kobj_ids(pid_t pid, TaskKobjIdsEntry *ids)
 {
 	int new;
 	struct kid_elem elem;
@@ -669,29 +669,29 @@ static int dump_task_kobj_ids(pid_t pid, CoreEntry *core)
 	elem.genid = 0; /* FIXME optimize */
 
 	new = 0;
-	core->ids->vm_id = kid_generate_gen(&vm_tree, &elem, &new);
-	if (!core->ids->vm_id || !new) {
+	ids->vm_id = kid_generate_gen(&vm_tree, &elem, &new);
+	if (!ids->vm_id || !new) {
 		pr_err("Can't make VM id for %d\n", pid);
 		return -1;
 	}
 
 	new = 0;
-	core->ids->fs_id = kid_generate_gen(&fs_tree, &elem, &new);
-	if (!core->ids->fs_id || !new) {
+	ids->fs_id = kid_generate_gen(&fs_tree, &elem, &new);
+	if (!ids->fs_id || !new) {
 		pr_err("Can't make FS id for %d\n", pid);
 		return -1;
 	}
 
 	new = 0;
-	core->ids->files_id = kid_generate_gen(&files_tree, &elem, &new);
-	if (!core->ids->files_id || !new) {
+	ids->files_id = kid_generate_gen(&files_tree, &elem, &new);
+	if (!ids->files_id || !new) {
 		pr_err("Can't make FILES id for %d\n", pid);
 		return -1;
 	}
 
 	new = 0;
-	core->ids->sighand_id = kid_generate_gen(&sighand_tree, &elem, &new);
-	if (!core->ids->sighand_id || !new) {
+	ids->sighand_id = kid_generate_gen(&sighand_tree, &elem, &new);
+	if (!ids->sighand_id || !new) {
 		pr_err("Can't make IO id for %d\n", pid);
 		return -1;
 	}
@@ -700,12 +700,10 @@ static int dump_task_kobj_ids(pid_t pid, CoreEntry *core)
 }
 
 static CoreEntry *core_entry_alloc(int alloc_thread_info,
-				   int alloc_tc,
-				   int alloc_ids)
+				   int alloc_tc)
 {
 	CoreEntry *core;
 	TaskCoreEntry *tc;
-	TaskKobjIdsEntry *ids;
 
 	core = xmalloc(sizeof(*core));
 	if (!core)
@@ -728,20 +726,37 @@ static CoreEntry *core_entry_alloc(int alloc_thread_info,
 		core->tc = tc;
 	}
 
-	if (alloc_ids) {
-		ids = xmalloc(sizeof(*ids));
-		if (!ids)
-			goto err;
-		task_kobj_ids_entry__init(ids);
-		core->ids = ids;
-	}
-
 	return core;
 err:
 	core_entry_free(core);
 	return NULL;
 }
 
+static int dump_task_ids(pid_t pid, const struct cr_fdset *cr_fdset)
+{
+	int fd_ids = fdset_fd(cr_fdset, CR_FD_IDS);
+	TaskKobjIdsEntry *ids;
+	int ret;
+
+	ids = xmalloc(sizeof(*ids));
+	if (!ids)
+		return -1;
+	task_kobj_ids_entry__init(ids);
+
+	ret = dump_task_kobj_ids(pid, ids);
+	if (ret)
+		goto err_free;
+
+	ret = pb_write_one(fd_ids, ids, PB_IDS);
+	if (ret < 0)
+		goto err_free;
+
+err_free:
+	xfree(ids);
+
+	return ret;
+}
+
 static int dump_task_core_all(pid_t pid, const struct proc_pid_stat *stat,
 		const struct parasite_dump_misc *misc, const struct parasite_ctl *ctl,
 		const struct cr_fdset *cr_fdset,
@@ -751,7 +766,7 @@ static int dump_task_core_all(pid_t pid, const struct proc_pid_stat *stat,
 	CoreEntry *core;
 	int ret = -1;
 
-	core = core_entry_alloc(1, 1, 1);
+	core = core_entry_alloc(1, 1);
 	if (!core)
 		return -1;
 
@@ -759,10 +774,6 @@ static int dump_task_core_all(pid_t pid, const struct proc_pid_stat *stat,
 	pr_info("Dumping core (pid: %d)\n", pid);
 	pr_info("----------------------------------------\n");
 
-	ret = dump_task_kobj_ids(pid, core);
-	if (ret)
-		goto err_free;
-
 	ret = dump_task_mm(pid, stat, misc, cr_fdset);
 	if (ret)
 		goto err_free;
@@ -1165,7 +1176,7 @@ static int dump_task_thread(struct parasite_ctl *parasite_ctl, struct pid *tid)
 	pr_info("Dumping core for thread (pid: %d)\n", pid);
 	pr_info("----------------------------------------\n");
 
-	core = core_entry_alloc(1, 0, 0);
+	core = core_entry_alloc(1, 0);
 	if (!core)
 		goto err;
 
@@ -1209,7 +1220,7 @@ static int dump_one_zombie(const struct pstree_item *item,
 	CoreEntry *core;
 	int ret = -1, fd_core;
 
-	core = core_entry_alloc(0, 1, 0);
+	core = core_entry_alloc(0, 1);
 	if (core == NULL)
 		goto err;
 
@@ -1439,6 +1450,12 @@ static int dump_one_task(struct pstree_item *item)
 		goto err_cure;
 	}
 
+	ret = dump_task_ids(pid, cr_fdset);
+	if (ret) {
+		pr_err("Dump ids (pid: %d) failed with %d\n", pid, ret);
+		goto err_cure;
+	}
+
 	ret = dump_task_threads(parasite_ctl, item);
 	if (ret) {
 		pr_err("Can't dump threads\n");
diff --git a/cr-restore.c b/cr-restore.c
index 417d36f..fd2fe0d 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -716,7 +716,7 @@ static int check_core(CoreEntry *core)
 	}
 
 	if (core->tc->task_state != TASK_DEAD) {
-		if (!core->ids) {
+		if (!current->ids) {
 			pr_err("Core IDS data missed for non-zombie\n");
 			goto out;
 		}
diff --git a/cr-show.c b/cr-show.c
index 61373be..b9654d0 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -351,6 +351,11 @@ void show_core(int fd_core, struct cr_options *o)
 	pb_show_vertical(fd_core, PB_CORE);
 }
 
+void show_ids(int fd_ids, struct cr_options *o)
+{
+	pb_show_vertical(fd_ids, PB_IDS);
+}
+
 void show_mm(int fd_mm, struct cr_options *o)
 {
 	pb_show_vertical(fd_mm, PB_MM);
diff --git a/image.c b/image.c
index cded9f6..d94c3de 100644
--- a/image.c
+++ b/image.c
@@ -100,6 +100,7 @@ struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = {
 	FD_ENTRY(INOTIFY,	"inotify",	 show_inotify),
 	FD_ENTRY(INOTIFY_WD,	"inotify-wd",	 show_inotify_wd),
 	FD_ENTRY(CORE,		"core-%d",	 show_core),
+	FD_ENTRY(IDS,		"ids-%d",	 show_ids),
 	FD_ENTRY(MM,		"mm-%d",	 show_mm),
 	FD_ENTRY(VMAS,		"vmas-%d",	 show_vmas),
 	FD_ENTRY(PIPES,		"pipes",	 show_pipes),
diff --git a/include/crtools.h b/include/crtools.h
index 01b58d3..a51998d 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -26,6 +26,7 @@ enum {
 	CR_FD_FDINFO,
 	CR_FD_PAGES,
 	CR_FD_CORE,
+	CR_FD_IDS,
 	CR_FD_MM,
 	CR_FD_VMAS,
 	CR_FD_SIGACT,
@@ -140,6 +141,7 @@ void show_files(int fd_files, struct cr_options *o);
 void show_pages(int fd_pages, struct cr_options *o);
 void show_reg_files(int fd_reg_files, struct cr_options *o);
 void show_core(int fd_core, struct cr_options *o);
+void show_ids(int fd_ids, struct cr_options *o);
 void show_mm(int fd_mm, struct cr_options *o);
 void show_vmas(int fd_vma, struct cr_options *o);
 void show_pipes(int fd_pipes, struct cr_options *o);
diff --git a/include/image.h b/include/image.h
index cdf362d..ee75a5d 100644
--- a/include/image.h
+++ b/include/image.h
@@ -28,6 +28,7 @@
 #define PAGES_MAGIC		0x56084025 /* Vladimir */
 #define SHMEM_PAGES_MAGIC	PAGES_MAGIC
 #define CORE_MAGIC		0x55053847 /* Kolomna */
+#define IDS_MAGIC		0x54432030 /* Konigsberg */
 #define VMAS_MAGIC		0x54123737 /* Tula */
 #define PIPES_MAGIC		0x56513555 /* Tver */
 #define PIPES_DATA_MAGIC	0x56453709 /* Dubna */
diff --git a/include/protobuf.h b/include/protobuf.h
index 4bed9f9..86d6101 100644
--- a/include/protobuf.h
+++ b/include/protobuf.h
@@ -43,6 +43,7 @@ enum {
 	PB_INOTIFY_WD,
 	PB_TTY,
 	PB_TTY_INFO,
+	PB_IDS,
 
 	PB_MAX
 };
diff --git a/include/pstree.h b/include/pstree.h
index d13dacf..7e1a40c 100644
--- a/include/pstree.h
+++ b/include/pstree.h
@@ -3,6 +3,7 @@
 
 #include "list.h"
 #include "crtools.h"
+#include "../protobuf/core.pb-c.h"
 
 /*
  * That's the init process which usually inherit
@@ -40,6 +41,7 @@ struct pstree_item {
 
 	int			nr_threads;	/* number of threads */
 	struct pid		*threads;	/* array of threads */
+	TaskKobjIdsEntry	*ids;
 
 	struct rst_info		rst[0];
 };
diff --git a/protobuf.c b/protobuf.c
index 5213d48..2598037 100644
--- a/protobuf.c
+++ b/protobuf.c
@@ -97,6 +97,7 @@ void cr_pb_init(void)
 	CR_PB_DESC(INOTIFY,		InotifyFile,	inotify_file);
 	CR_PB_DESC(INOTIFY_WD,		InotifyWd,	inotify_wd);
 	CR_PB_DESC(CORE,		Core,		core);
+	CR_PB_DESC(IDS,			TaskKobjIds,	task_kobj_ids);
 	CR_PB_DESC(MM,			Mm,		mm);
 	CR_PB_DESC(VMAS,		Vma,		vma);
 	CR_PB_DESC(PIPES,		Pipe,		pipe);
diff --git a/pstree.c b/pstree.c
index 3ba645e..2e2171b 100644
--- a/pstree.c
+++ b/pstree.c
@@ -177,7 +177,7 @@ static int prepare_pstree_for_shell_job(void)
 
 static int read_pstree_image(void)
 {
-	int ret = 0, i, ps_fd;
+	int ret = 0, i, ps_fd, fd;
 	struct pstree_item *pi, *parent = NULL;
 
 	pr_info("Reading image tree\n");
@@ -260,6 +260,18 @@ static int read_pstree_image(void)
 		task_entries->nr_tasks++;
 
 		pstree_entry__free_unpacked(e, NULL);
+
+		fd = open_image_ro(CR_FD_IDS, pi->pid.virt);
+		if (fd < 0) {
+			if (errno == ENOENT)
+				continue;
+			return -1;
+		}
+		ret = pb_read_one(fd, &pi->ids, PB_IDS);
+		close(fd);
+		if (ret != 1)
+			goto err;
+
 	}
 err:
 	close(ps_fd);
-- 
1.7.11.7



More information about the CRIU mailing list