From fe6fa3bec3249393c9cd2ead0d095e2bb9d92dad Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Fri, 30 Jun 2017 13:57:22 +0300 Subject: [PATCH] image: Introduce files.img and file_entry 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. Reviewed-by: Kirill Tkhai Signed-off-by: Pavel Emelyanov Signed-off-by: Andrei Vagin --- 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(-) diff --git a/criu/cr-restore.c b/criu/cr-restore.c index e62443ba5..e48088be6 100644 --- a/criu/cr-restore.c +++ b/criu/cr-restore.c @@ -278,6 +278,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 */ @@ -320,6 +323,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 41a8e0913..388bd281c 100644 --- a/criu/files.c +++ b/criu/files.c @@ -1664,8 +1664,30 @@ int open_transport_socket(void) return 0; } +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 5e5224b13..7fedf1a09 100644 --- a/criu/image-desc.c +++ b/criu/image-desc.c @@ -99,6 +99,7 @@ struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = { FD_ENTRY(USERNS, "userns-%d"), FD_ENTRY(NETNF_CT, "netns-ct-%d"), FD_ENTRY(NETNF_EXP, "netns-exp-%d"), + FD_ENTRY(FILES, "files"), [CR_FD_STATS] = { .fmt = "stats-%s", diff --git a/criu/include/files.h b/criu/include/files.h index ee9b2569f..9f65fa634 100644 --- a/criu/include/files.h +++ b/criu/include/files.h @@ -162,6 +162,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 eba5d00a1..8a857cd94 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 a0071eec4..05101f436 100644 --- a/criu/include/magic.h +++ b/criu/include/magic.h @@ -93,6 +93,7 @@ #define SECCOMP_MAGIC 0x64413049 /* Kostomuksha */ #define BINFMT_MISC_MAGIC 0x67343323 /* Apatity */ #define AUTOFS_MAGIC 0x49353943 /* Sochi */ +#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 023047de5..31f5b9a79 100644 --- a/criu/include/protobuf-desc.h +++ b/criu/include/protobuf-desc.h @@ -60,6 +60,7 @@ enum { PB_TTY_DATA, PB_AUTOFS, PB_GHOST_CHUNK, + PB_FILE, /* PB_AUTOGEN_STOP */ diff --git a/images/fdinfo.proto b/images/fdinfo.proto index 56506690c..86e39c19e 100644 --- a/images/fdinfo.proto +++ b/images/fdinfo.proto @@ -27,3 +27,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 894e1c2c0..bb2f3834e 100644 --- a/lib/py/images/images.py +++ b/lib/py/images/images.py @@ -506,6 +506,7 @@ handlers = { 'USERNS' : entry_handler(userns_entry), 'SECCOMP' : entry_handler(seccomp_entry), 'AUTOFS' : entry_handler(autofs_entry), + 'FILES' : entry_handler(file_entry), } def __rhandler(f):