[06/22] image: Introduce files.img and file_entry

Submitted by Pavel Emelianov on June 30, 2017, 10:57 a.m.

Details

Message ID 5e42b627-600c-b90b-ef61-a90aff91126d@virtuozzo.com
State Accepted
Series "Merge images with different files into one"
Headers show

Commit Message

Pavel Emelianov June 30, 2017, 10:57 a.m.
There are two goals of this merge. First is to reduce the amount
of image files we generate and scan on restore. The latter is
more importaint, as even if we have no weird stuff like signalfd,
we still try to open this file. So after the merge we try to
open ~15 image files (out of ~30) less %) which is nice.

The 2nd goal is to simplify the C/R support for SCM messages.
This becomes possible with the fact, that all files we have can
be distinguished by their ID only, w/o type. This, in turn,
makes image layout for SCMs much simpler.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/cr-restore.c            |  7 +++++++
 criu/files.c                 | 24 +++++++++++++++++++++++-
 criu/image-desc.c            |  1 +
 criu/include/files.h         |  3 +++
 criu/include/image-desc.h    |  1 +
 criu/include/magic.h         |  1 +
 criu/include/protobuf-desc.h |  1 +
 images/fdinfo.proto          |  5 +++++
 lib/py/images/images.py      |  1 +
 9 files changed, 43 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index e6c1cac..8b81de9 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -284,6 +284,9 @@  static struct collect_image_info *cinfos[] = {
 	&sk_queues_cinfo,
 };
 
+static struct collect_image_info *cinfos_files[] = {
+};
+
 /* These images are requered to restore namespaces */
 static struct collect_image_info *before_ns_cinfos[] = {
 	&tty_info_cinfo, /* Restore devpts content */
@@ -326,6 +329,10 @@  static int root_prepare_shared(void)
 	if (collect_images(cinfos, ARRAY_SIZE(cinfos)))
 		return -1;
 
+	if (!files_collected() &&
+			collect_images(cinfos_files, ARRAY_SIZE(cinfos_files)))
+		return -1;
+
 	for_each_pstree_item(pi) {
 		if (pi->pid->state == TASK_HELPER)
 			continue;
diff --git a/criu/files.c b/criu/files.c
index b83901f..c371f8c 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -1780,8 +1780,30 @@  err:
 	return -1;
 }
 
+static int collect_one_file(void *o, ProtobufCMessage *base, struct cr_img *i)
+{
+	int ret = 0;
+	FileEntry *fe;
+
+	fe = pb_msg(base, FileEntry);
+	switch (fe->type) {
+	default:
+		pr_err("Unknown file type %d\n", fe->type);
+		return -1;
+	}
+
+	return ret;
+}
+
+struct collect_image_info files_cinfo = {
+	.fd_type = CR_FD_FILES,
+	.pb_type = PB_FILE,
+	.priv_size = 0,
+	.collect = collect_one_file,
+};
+
 int prepare_files(void)
 {
 	init_fdesc_hash();
-	return 0;
+	return collect_image(&files_cinfo);
 }
diff --git a/criu/image-desc.c b/criu/image-desc.c
index 3394300..f17d67d 100644
--- a/criu/image-desc.c
+++ b/criu/image-desc.c
@@ -100,6 +100,7 @@  struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = {
 	FD_ENTRY(NETNF_CT,	"netns-ct-%d"),
 	FD_ENTRY(NETNF_EXP,	"netns-exp-%d"),
 	FD_ENTRY(NS,		"ns"),
+	FD_ENTRY(FILES,		"files"),
 
 	[CR_FD_STATS] = {
 		.fmt	= "stats-%s",
diff --git a/criu/include/files.h b/criu/include/files.h
index c19f10d..22d5bc8 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -160,6 +160,9 @@  extern int restore_fs(struct pstree_item *);
 extern int prepare_fs_pid(struct pstree_item *);
 extern int set_fd_flags(int fd, int flags);
 
+extern struct collect_image_info files_cinfo;
+#define files_collected() (files_cinfo.flags & COLLECT_HAPPENED)
+
 extern int close_old_fds(void);
 #ifndef AT_EMPTY_PATH
 #define AT_EMPTY_PATH 0x1000
diff --git a/criu/include/image-desc.h b/criu/include/image-desc.h
index fda5cac..41fed0d 100644
--- a/criu/include/image-desc.h
+++ b/criu/include/image-desc.h
@@ -54,6 +54,7 @@  enum {
 	CR_FD_FDINFO,
 
 	_CR_FD_GLOB_FROM,
+	CR_FD_FILES,
 	CR_FD_SK_QUEUES,
 	CR_FD_REG_FILES,
 	CR_FD_EXT_FILES,
diff --git a/criu/include/magic.h b/criu/include/magic.h
index 6fb241a..604506e 100644
--- a/criu/include/magic.h
+++ b/criu/include/magic.h
@@ -94,6 +94,7 @@ 
 #define BINFMT_MISC_MAGIC	0x67343323 /* Apatity */
 #define AUTOFS_MAGIC		0x49353943 /* Sochi */
 #define NS_MAGIC		0x44293409 /* Yalta */
+#define FILES_MAGIC		0x56303138 /* Toropets */
 
 #define IFADDR_MAGIC		RAW_IMAGE_MAGIC
 #define ROUTE_MAGIC		RAW_IMAGE_MAGIC
diff --git a/criu/include/protobuf-desc.h b/criu/include/protobuf-desc.h
index 66460cf..7c6f435 100644
--- a/criu/include/protobuf-desc.h
+++ b/criu/include/protobuf-desc.h
@@ -64,6 +64,7 @@  enum {
 	PB_LOCAL_IMAGE_REPLY,	/* Header for reading/writing images reply. */
 	PB_SNAPSHOT_ID,         /* Contains a single id. Used for reading/writing ids from proxy or cache. */
 	PB_GHOST_CHUNK,
+	PB_FILE,
 
 	/* PB_AUTOGEN_STOP */
 
diff --git a/images/fdinfo.proto b/images/fdinfo.proto
index d511dff..9c67bab 100644
--- a/images/fdinfo.proto
+++ b/images/fdinfo.proto
@@ -30,3 +30,8 @@  message fdinfo_entry {
 	required fd_types	type	= 3;
 	required uint32		fd	= 4;
 }
+
+message file_entry {
+	required fd_types		type	= 1;
+	required uint32			id	= 2;
+}
diff --git a/lib/py/images/images.py b/lib/py/images/images.py
index 80ed4b7..cba882a 100644
--- a/lib/py/images/images.py
+++ b/lib/py/images/images.py
@@ -507,6 +507,7 @@  handlers = {
 	'SECCOMP'		: entry_handler(seccomp_entry),
 	'AUTOFS'		: entry_handler(autofs_entry),
 	'NS'                    : entry_handler(ns_entry),
+	'FILES'                 : entry_handler(file_entry),
 	}
 
 def __rhandler(f):