Commit 9f2168a4 authored by Pavel Emelyanov's avatar Pavel Emelyanov

images: Introduce the top-level file -- inventory

Currently we store the images version in the core file. This is
bad, since core file describes a single process (or thread) and
says nothing about the images set as a whole (let alone the fact
that it's being parsed too late).

Thus introduce the inventory image file which describes the image
set the way we need (want). For now the only entry in it is the
images version. In the future it can be extended.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 76e7f12c
...@@ -675,7 +675,6 @@ static int dump_task_core(struct core_entry *core, int fd_core) ...@@ -675,7 +675,6 @@ static int dump_task_core(struct core_entry *core, int fd_core)
{ {
pr_info("Dumping header ... "); pr_info("Dumping header ... ");
core->header.version = HEADER_VERSION;
core->header.arch = HEADER_ARCH_X86_64; core->header.arch = HEADER_ARCH_X86_64;
core->header.flags = 0; core->header.flags = 0;
...@@ -1377,6 +1376,9 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts) ...@@ -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("Dumping process %s(pid: %d)\n", !opts->leader_only ? "group " : "", pid);
pr_info("========================================\n"); pr_info("========================================\n");
if (write_img_inventory())
goto err;
if (collect_pstree(pid, opts)) if (collect_pstree(pid, opts))
goto err; goto err;
......
...@@ -403,11 +403,6 @@ static int check_core_header(int pid, struct task_core_entry *tc) ...@@ -403,11 +403,6 @@ static int check_core_header(int pid, struct task_core_entry *tc)
if (read_img(fd, &hdr) < 0) if (read_img(fd, &hdr) < 0)
goto out; 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) { if (hdr.arch != HEADER_ARCH_X86_64) {
pr_err("Core arch mismatch %d\n", (int)hdr.arch); pr_err("Core arch mismatch %d\n", (int)hdr.arch);
goto out; goto out;
...@@ -866,6 +861,9 @@ static int prepare_task_entries() ...@@ -866,6 +861,9 @@ static int prepare_task_entries()
static int restore_all_tasks(pid_t pid, struct cr_options *opts) static int restore_all_tasks(pid_t pid, struct cr_options *opts)
{ {
if (check_img_inventory() < 0)
return -1;
if (prepare_task_entries() < 0) if (prepare_task_entries() < 0)
return -1; return -1;
......
...@@ -9,6 +9,64 @@ ...@@ -9,6 +9,64 @@
#include "ipc_ns.h" #include "ipc_ns.h"
#include "sk-inet.h" #include "sk-inet.h"
#include "mount.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 * The cr fd set is the set of files where the information
...@@ -25,6 +83,7 @@ ...@@ -25,6 +83,7 @@
} }
struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = { 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(FDINFO, "fdinfo-%d", show_files),
FD_ENTRY(PAGES, "pages-%d", show_pages), FD_ENTRY(PAGES, "pages-%d", show_pages),
FD_ENTRY(SHMEM_PAGES, "pages-shmem-%ld", show_pages), FD_ENTRY(SHMEM_PAGES, "pages-shmem-%ld", show_pages),
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#define CRIU_VERSION_MINOR 0 #define CRIU_VERSION_MINOR 0
enum { enum {
CR_FD_INVENTORY,
/* /*
* Task entries * Task entries
*/ */
...@@ -123,6 +124,9 @@ void show_ghost_file(int fd, struct cr_options *o); ...@@ -123,6 +124,9 @@ void show_ghost_file(int fd, struct cr_options *o);
void show_fown_cont(void *p); void show_fown_cont(void *p);
void show_eventfds(int fd, struct cr_options *o); 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 void print_data(unsigned long addr, unsigned char *data, size_t size);
extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX]; extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
......
...@@ -4,11 +4,18 @@ ...@@ -4,11 +4,18 @@
#include "types.h" #include "types.h"
#include "compiler.h" #include "compiler.h"
/*
* Basic multi-file images
*/
#define CRTOOLS_IMAGES_V1 1
/* /*
* The magic-s below correspond to coordinates * The magic-s below correspond to coordinates
* of various Russian towns in the NNNNEEEE form. * of various Russian towns in the NNNNEEEE form.
*/ */
#define INVENTORY_MAGIC 0x58313116 /* Veliky Novgorod */
#define PSTREE_MAGIC 0x50273030 /* Kyiv */ #define PSTREE_MAGIC 0x50273030 /* Kyiv */
#define FDINFO_MAGIC 0x56213732 /* Dmitrov */ #define FDINFO_MAGIC 0x56213732 /* Dmitrov */
#define PAGES_MAGIC 0x56084025 /* Vladimir */ #define PAGES_MAGIC 0x56084025 /* Vladimir */
...@@ -80,12 +87,10 @@ struct page_entry { ...@@ -80,12 +87,10 @@ struct page_entry {
#define CR_CAP_SIZE 2 #define CR_CAP_SIZE 2
#define HEADER_VERSION 1
#define HEADER_ARCH_X86_64 1 #define HEADER_ARCH_X86_64 1
struct image_header { struct image_header {
u16 version; u32 arch;
u16 arch;
u32 flags; u32 flags;
} __packed; } __packed;
......
...@@ -19,6 +19,7 @@ CFLAGS += $(WARNINGS) $(DEFINES) ...@@ -19,6 +19,7 @@ CFLAGS += $(WARNINGS) $(DEFINES)
LIBRARY := protobuf-lib.o LIBRARY := protobuf-lib.o
PROTO_FILES += inventory.proto
PROTO_FILES += fdinfo.proto PROTO_FILES += fdinfo.proto
PROTO_FILES += fown.proto PROTO_FILES += fown.proto
PROTO_FILES += regfile.proto PROTO_FILES += regfile.proto
......
message inventory_entry {
required uint32 img_version = 1;
}
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