Commit fe6fa3be authored by Pavel Emelyanov's avatar Pavel Emelyanov

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: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 904e7b38
...@@ -278,6 +278,9 @@ static struct collect_image_info *cinfos[] = { ...@@ -278,6 +278,9 @@ static struct collect_image_info *cinfos[] = {
&sk_queues_cinfo, &sk_queues_cinfo,
}; };
static struct collect_image_info *cinfos_files[] = {
};
/* These images are requered to restore namespaces */ /* These images are requered to restore namespaces */
static struct collect_image_info *before_ns_cinfos[] = { static struct collect_image_info *before_ns_cinfos[] = {
&tty_info_cinfo, /* Restore devpts content */ &tty_info_cinfo, /* Restore devpts content */
...@@ -320,6 +323,10 @@ static int root_prepare_shared(void) ...@@ -320,6 +323,10 @@ static int root_prepare_shared(void)
if (collect_images(cinfos, ARRAY_SIZE(cinfos))) if (collect_images(cinfos, ARRAY_SIZE(cinfos)))
return -1; return -1;
if (!files_collected() &&
collect_images(cinfos_files, ARRAY_SIZE(cinfos_files)))
return -1;
for_each_pstree_item(pi) { for_each_pstree_item(pi) {
if (pi->pid->state == TASK_HELPER) if (pi->pid->state == TASK_HELPER)
continue; continue;
......
...@@ -1664,8 +1664,30 @@ int open_transport_socket(void) ...@@ -1664,8 +1664,30 @@ int open_transport_socket(void)
return 0; 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) int prepare_files(void)
{ {
init_fdesc_hash(); init_fdesc_hash();
return 0; return collect_image(&files_cinfo);
} }
...@@ -99,6 +99,7 @@ struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = { ...@@ -99,6 +99,7 @@ struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = {
FD_ENTRY(USERNS, "userns-%d"), FD_ENTRY(USERNS, "userns-%d"),
FD_ENTRY(NETNF_CT, "netns-ct-%d"), FD_ENTRY(NETNF_CT, "netns-ct-%d"),
FD_ENTRY(NETNF_EXP, "netns-exp-%d"), FD_ENTRY(NETNF_EXP, "netns-exp-%d"),
FD_ENTRY(FILES, "files"),
[CR_FD_STATS] = { [CR_FD_STATS] = {
.fmt = "stats-%s", .fmt = "stats-%s",
......
...@@ -162,6 +162,9 @@ extern int restore_fs(struct pstree_item *); ...@@ -162,6 +162,9 @@ extern int restore_fs(struct pstree_item *);
extern int prepare_fs_pid(struct pstree_item *); extern int prepare_fs_pid(struct pstree_item *);
extern int set_fd_flags(int fd, int flags); 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); extern int close_old_fds(void);
#ifndef AT_EMPTY_PATH #ifndef AT_EMPTY_PATH
#define AT_EMPTY_PATH 0x1000 #define AT_EMPTY_PATH 0x1000
......
...@@ -54,6 +54,7 @@ enum { ...@@ -54,6 +54,7 @@ enum {
CR_FD_FDINFO, CR_FD_FDINFO,
_CR_FD_GLOB_FROM, _CR_FD_GLOB_FROM,
CR_FD_FILES,
CR_FD_SK_QUEUES, CR_FD_SK_QUEUES,
CR_FD_REG_FILES, CR_FD_REG_FILES,
CR_FD_EXT_FILES, CR_FD_EXT_FILES,
......
...@@ -93,6 +93,7 @@ ...@@ -93,6 +93,7 @@
#define SECCOMP_MAGIC 0x64413049 /* Kostomuksha */ #define SECCOMP_MAGIC 0x64413049 /* Kostomuksha */
#define BINFMT_MISC_MAGIC 0x67343323 /* Apatity */ #define BINFMT_MISC_MAGIC 0x67343323 /* Apatity */
#define AUTOFS_MAGIC 0x49353943 /* Sochi */ #define AUTOFS_MAGIC 0x49353943 /* Sochi */
#define FILES_MAGIC 0x56303138 /* Toropets */
#define IFADDR_MAGIC RAW_IMAGE_MAGIC #define IFADDR_MAGIC RAW_IMAGE_MAGIC
#define ROUTE_MAGIC RAW_IMAGE_MAGIC #define ROUTE_MAGIC RAW_IMAGE_MAGIC
......
...@@ -60,6 +60,7 @@ enum { ...@@ -60,6 +60,7 @@ enum {
PB_TTY_DATA, PB_TTY_DATA,
PB_AUTOFS, PB_AUTOFS,
PB_GHOST_CHUNK, PB_GHOST_CHUNK,
PB_FILE,
/* PB_AUTOGEN_STOP */ /* PB_AUTOGEN_STOP */
......
...@@ -27,3 +27,8 @@ message fdinfo_entry { ...@@ -27,3 +27,8 @@ message fdinfo_entry {
required fd_types type = 3; required fd_types type = 3;
required uint32 fd = 4; required uint32 fd = 4;
} }
message file_entry {
required fd_types type = 1;
required uint32 id = 2;
}
...@@ -506,6 +506,7 @@ handlers = { ...@@ -506,6 +506,7 @@ handlers = {
'USERNS' : entry_handler(userns_entry), 'USERNS' : entry_handler(userns_entry),
'SECCOMP' : entry_handler(seccomp_entry), 'SECCOMP' : entry_handler(seccomp_entry),
'AUTOFS' : entry_handler(autofs_entry), 'AUTOFS' : entry_handler(autofs_entry),
'FILES' : entry_handler(file_entry),
} }
def __rhandler(f): def __rhandler(f):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment