Commit 9725b7be authored by Pavel Tikhomirov's avatar Pavel Tikhomirov Committed by Pavel Emelyanov

inventory: add a helper to get entry of parent pre-dump

will be used in the next patch

https://jira.sw.ru/browse/PSBM-67502

note: actually we need only one value from inventory entry but I still
prefer general helper as we still need to read and allocate memory
for the whole structure

v2: fix get_parent_stats to have static typing
v3: simplify get_parent_stats to return a StatsEntry pointer instead of
doing it through arguments
v8: replace errors with warnings, we should whatch on them only if we
have corresponding error in detect_pid_reuse else they are fine
v9: change stats to inventory image
Signed-off-by: 's avatarPavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 5451fc23
......@@ -116,6 +116,43 @@ void prepare_inventory_pre_dump(InventoryEntry *he)
he->has_dump_uptime = true;
}
__maybe_unused InventoryEntry *get_parent_inventory(void)
{
struct cr_img *img;
InventoryEntry *ie;
int dir;
dir = openat(get_service_fd(IMG_FD_OFF), CR_PARENT_LINK, O_RDONLY);
if (dir == -1) {
pr_warn("Failed to open parent directory");
return NULL;
}
img = open_image_at(dir, CR_FD_INVENTORY, O_RSTR);
if (!img) {
pr_warn("Failed to open parent pre-dump inventory image");
close(dir);
return NULL;
}
if (pb_read_one(img, &ie, PB_INVENTORY) < 0) {
pr_warn("Failed to read parent pre-dump inventory entry");
close_image(img);
close(dir);
return NULL;
}
if (!ie->has_dump_uptime) {
pr_warn("Parent pre-dump inventory has no uptime");
inventory_entry__free_unpacked(ie, NULL);
ie = NULL;
}
close_image(img);
close(dir);
return ie;
}
int prepare_inventory(InventoryEntry *he)
{
struct pid pid;
......
......@@ -13,6 +13,7 @@
extern int check_img_inventory(void);
extern int write_img_inventory(InventoryEntry *he);
extern void prepare_inventory_pre_dump(InventoryEntry *he);
extern InventoryEntry *get_parent_inventory(void);
extern int prepare_inventory(InventoryEntry *he);
struct pprep_head {
int (*actor)(struct pprep_head *);
......
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