diff --git a/cr-dump.c b/cr-dump.c index 2ce3c762e..e7489601b 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -675,7 +675,6 @@ static int dump_task_core(struct core_entry *core, int fd_core) { pr_info("Dumping header ... "); - core->header.version = HEADER_VERSION; core->header.arch = HEADER_ARCH_X86_64; core->header.flags = 0; @@ -1377,6 +1376,9 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts) pr_info("Dumping process %s(pid: %d)\n", !opts->leader_only ? "group " : "", pid); pr_info("========================================\n"); + if (write_img_inventory()) + goto err; + if (collect_pstree(pid, opts)) goto err; diff --git a/cr-restore.c b/cr-restore.c index 2559b2139..9f0d1ef4c 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -403,11 +403,6 @@ static int check_core_header(int pid, struct task_core_entry *tc) if (read_img(fd, &hdr) < 0) goto out; - if (hdr.version != HEADER_VERSION) { - pr_err("Core version mismatch %d\n", (int)hdr.version); - goto out; - } - if (hdr.arch != HEADER_ARCH_X86_64) { pr_err("Core arch mismatch %d\n", (int)hdr.arch); goto out; @@ -866,6 +861,9 @@ static int prepare_task_entries() static int restore_all_tasks(pid_t pid, struct cr_options *opts) { + if (check_img_inventory() < 0) + return -1; + if (prepare_task_entries() < 0) return -1; diff --git a/image.c b/image.c index d241b3e2b..bc63427fa 100644 --- a/image.c +++ b/image.c @@ -9,6 +9,64 @@ #include "ipc_ns.h" #include "sk-inet.h" #include "mount.h" +#include "protobuf.h" +#include "protobuf/inventory.pb-c.h" + +int check_img_inventory(void) +{ + int fd, ret; + InventoryEntry *he; + + fd = open_image_ro(CR_FD_INVENTORY); + if (fd < 0) + return -1; + + ret = pb_read(fd, &he, inventory_entry); + close(fd); + if (ret < 0) + return ret; + + ret = he->img_version; + inventory_entry__free_unpacked(he, NULL); + + if (ret != CRTOOLS_IMAGES_V1) { + pr_err("Not supported images version %u\n", ret); + return -1; + } + + return 0; +} + +int write_img_inventory(void) +{ + int fd; + InventoryEntry he = INVENTORY_ENTRY__INIT; + + pr_info("Writing image inventory (version %u)\n", CRTOOLS_IMAGES_V1); + + fd = open_image(CR_FD_INVENTORY, O_DUMP); + if (fd < 0) + return -1; + + he.img_version = CRTOOLS_IMAGES_V1; + + if (pb_write(fd, &he, inventory_entry) < 0) + return -1; + + close(fd); + return 0; +} + +static void show_inventory(int fd, struct cr_options *o) +{ + InventoryEntry *he; + + if (pb_read(fd, &he, inventory_entry) < 0) + return; + + pr_msg("Version: %u\n", he->img_version); + inventory_entry__free_unpacked(he, NULL); +} /* * The cr fd set is the set of files where the information @@ -25,6 +83,7 @@ } struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = { + FD_ENTRY(INVENTORY, "inventory", show_inventory), FD_ENTRY(FDINFO, "fdinfo-%d", show_files), FD_ENTRY(PAGES, "pages-%d", show_pages), FD_ENTRY(SHMEM_PAGES, "pages-shmem-%ld", show_pages), diff --git a/include/crtools.h b/include/crtools.h index 329774102..9b7d6ddfa 100644 --- a/include/crtools.h +++ b/include/crtools.h @@ -18,6 +18,7 @@ #define CRIU_VERSION_MINOR 0 enum { + CR_FD_INVENTORY, /* * Task entries */ @@ -123,6 +124,9 @@ void show_ghost_file(int fd, struct cr_options *o); void show_fown_cont(void *p); void show_eventfds(int fd, struct cr_options *o); +int check_img_inventory(void); +int write_img_inventory(void); + extern void print_data(unsigned long addr, unsigned char *data, size_t size); extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX]; diff --git a/include/image.h b/include/image.h index d8d57e62c..637e59a62 100644 --- a/include/image.h +++ b/include/image.h @@ -4,11 +4,18 @@ #include "types.h" #include "compiler.h" +/* + * Basic multi-file images + */ + +#define CRTOOLS_IMAGES_V1 1 + /* * The magic-s below correspond to coordinates * of various Russian towns in the NNNNEEEE form. */ +#define INVENTORY_MAGIC 0x58313116 /* Veliky Novgorod */ #define PSTREE_MAGIC 0x50273030 /* Kyiv */ #define FDINFO_MAGIC 0x56213732 /* Dmitrov */ #define PAGES_MAGIC 0x56084025 /* Vladimir */ @@ -80,12 +87,10 @@ struct page_entry { #define CR_CAP_SIZE 2 -#define HEADER_VERSION 1 #define HEADER_ARCH_X86_64 1 struct image_header { - u16 version; - u16 arch; + u32 arch; u32 flags; } __packed; diff --git a/protobuf/Makefile b/protobuf/Makefile index db481706e..0b66c3bd3 100644 --- a/protobuf/Makefile +++ b/protobuf/Makefile @@ -19,6 +19,7 @@ CFLAGS += $(WARNINGS) $(DEFINES) LIBRARY := protobuf-lib.o +PROTO_FILES += inventory.proto PROTO_FILES += fdinfo.proto PROTO_FILES += fown.proto PROTO_FILES += regfile.proto diff --git a/protobuf/inventory.proto b/protobuf/inventory.proto new file mode 100644 index 000000000..e9a40eeaa --- /dev/null +++ b/protobuf/inventory.proto @@ -0,0 +1,3 @@ +message inventory_entry { + required uint32 img_version = 1; +}