mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
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: Andrey Vagin <avagin@openvz.org> Signed-off-by: Andrew Vagin <avagin@virtuozzo.com> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
98cc46fc13
commit
4864996ed8
3 changed files with 40 additions and 35 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
61
image.c
61
image.c
|
|
@ -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,38 +87,42 @@ 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();
|
||||
|
||||
crt.i.state = TASK_ALIVE;
|
||||
crt.i.pid.real = getpid();
|
||||
if (get_task_ids(&crt.i)) {
|
||||
close_image(img);
|
||||
return -1;
|
||||
}
|
||||
|
||||
he.has_root_cg_set = true;
|
||||
if (dump_task_cgroup(NULL, &he.root_cg_set))
|
||||
if (pb_write_one(img, he, PB_INVENTORY) < 0)
|
||||
return -1;
|
||||
|
||||
he.root_ids = crt.i.ids;
|
||||
|
||||
if (pb_write_one(img, &he, PB_INVENTORY) < 0)
|
||||
return -1;
|
||||
|
||||
xfree(crt.i.ids);
|
||||
xfree(he->root_ids);
|
||||
close_image(img);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kill_inventory(void)
|
||||
int prepare_inventory(InventoryEntry *he)
|
||||
{
|
||||
unlinkat(get_service_fd(IMG_FD_OFF),
|
||||
imgset_template[CR_FD_INVENTORY].fmt, 0);
|
||||
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))
|
||||
return -1;
|
||||
|
||||
he->has_root_cg_set = true;
|
||||
if (dump_task_cgroup(NULL, &he->root_cg_set))
|
||||
return -1;
|
||||
|
||||
he->root_ids = crt.i.ids;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct cr_imgset *alloc_cr_imgset(int nr)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue