Commit 4864996e authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

dump: write an inventory image after dumping all processes

Currently if criu segfaulted, the inventory image isn't removed and
we can't detect that images are incomplete.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 98cc46fc
......@@ -1575,7 +1575,6 @@ static int cr_dump_finish(int ret)
close_service_fd(CR_PROC_FD_OFF);
if (ret) {
kill_inventory();
pr_err("Dumping FAILED.\n");
} else {
write_stats(DUMP_STATS);
......@@ -1593,6 +1592,7 @@ void dump_alarm_handler(int signum)
int cr_dump_tasks(pid_t pid)
{
InventoryEntry he = INVENTORY_ENTRY__INIT;
struct pstree_item *item;
int pre_dump_ret = 0;
int ret = -1;
......@@ -1627,7 +1627,7 @@ int cr_dump_tasks(pid_t pid)
if (parse_cg_info())
goto err;
if (write_img_inventory())
if (prepare_inventory(&he))
goto err;
if (opts.cpu_cap & (CPU_CAP_CPU | CPU_CAP_INS)) {
......@@ -1710,6 +1710,9 @@ int cr_dump_tasks(pid_t pid)
if (ret)
goto err;
ret = write_img_inventory(&he);
if (ret)
goto err;
err:
return cr_dump_finish(ret);
}
......@@ -77,14 +77,9 @@ out_close:
return ret;
}
int write_img_inventory(void)
int write_img_inventory(InventoryEntry *he)
{
struct cr_img *img;
InventoryEntry he = INVENTORY_ENTRY__INIT;
struct {
struct pstree_item i;
struct dmp_info d;
} crt = { };
pr_info("Writing image inventory (version %u)\n", CRTOOLS_IMAGES_V1);
......@@ -92,40 +87,44 @@ int write_img_inventory(void)
if (!img)
return -1;
he.img_version = CRTOOLS_IMAGES_V1_1;
he.fdinfo_per_id = true;
he.has_fdinfo_per_id = true;
he.ns_per_id = true;
he.has_ns_per_id = true;
he.lsmtype = host_lsm_type();
if (pb_write_one(img, he, PB_INVENTORY) < 0)
return -1;
xfree(he->root_ids);
close_image(img);
return 0;
}
int prepare_inventory(InventoryEntry *he)
{
struct {
struct pstree_item i;
struct dmp_info d;
} crt = { };
pr_info("Perparing image inventory (version %u)\n", CRTOOLS_IMAGES_V1);
he->img_version = CRTOOLS_IMAGES_V1_1;
he->fdinfo_per_id = true;
he->has_fdinfo_per_id = true;
he->ns_per_id = true;
he->has_ns_per_id = true;
he->lsmtype = host_lsm_type();
crt.i.state = TASK_ALIVE;
crt.i.pid.real = getpid();
if (get_task_ids(&crt.i)) {
close_image(img);
if (get_task_ids(&crt.i))
return -1;
}
he.has_root_cg_set = true;
if (dump_task_cgroup(NULL, &he.root_cg_set))
he->has_root_cg_set = true;
if (dump_task_cgroup(NULL, &he->root_cg_set))
return -1;
he.root_ids = crt.i.ids;
he->root_ids = crt.i.ids;
if (pb_write_one(img, &he, PB_INVENTORY) < 0)
return -1;
xfree(crt.i.ids);
close_image(img);
return 0;
}
void kill_inventory(void)
{
unlinkat(get_service_fd(IMG_FD_OFF),
imgset_template[CR_FD_INVENTORY].fmt, 0);
}
static struct cr_imgset *alloc_cr_imgset(int nr)
{
struct cr_imgset *cr_imgset;
......
......@@ -7,11 +7,14 @@
#include "asm/types.h"
#include "servicefd.h"
#include "protobuf.h"
#include "protobuf/inventory.pb-c.h"
#define CR_FD_PERM (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
extern int check_img_inventory(void);
extern int write_img_inventory(void);
extern void kill_inventory(void);
extern int write_img_inventory(InventoryEntry *he);
extern int prepare_inventory(InventoryEntry *he);
#define LAST_PID_PATH "sys/kernel/ns_last_pid"
......
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