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 <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Pavel Emelyanov 2017-06-30 13:57:22 +03:00
parent 904e7b383b
commit fe6fa3bec3
9 changed files with 43 additions and 1 deletions

View file

@ -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;

View file

@ -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);
}

View file

@ -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",

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -60,6 +60,7 @@ enum {
PB_TTY_DATA,
PB_AUTOFS,
PB_GHOST_CHUNK,
PB_FILE,
/* PB_AUTOGEN_STOP */

View file

@ -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;
}

View file

@ -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):