Commit 20b5ed91 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

crtools: put kobj-ids into separate image file (v2)

It is read together with pstree items for checking what kind of
resources should be shared. Core is too big for reading it in
this place.

v2: fix check_core
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 4ea62143
......@@ -690,7 +690,7 @@ static DECLARE_KCMP_TREE(fs_tree, KCMP_FS);
static DECLARE_KCMP_TREE(files_tree, KCMP_FILES);
static DECLARE_KCMP_TREE(sighand_tree, KCMP_SIGHAND);
static int dump_task_kobj_ids(pid_t pid, CoreEntry *core)
static int dump_task_kobj_ids(pid_t pid, TaskKobjIdsEntry *ids)
{
int new;
struct kid_elem elem;
......@@ -700,29 +700,29 @@ static int dump_task_kobj_ids(pid_t pid, CoreEntry *core)
elem.genid = 0; /* FIXME optimize */
new = 0;
core->ids->vm_id = kid_generate_gen(&vm_tree, &elem, &new);
if (!core->ids->vm_id || !new) {
ids->vm_id = kid_generate_gen(&vm_tree, &elem, &new);
if (!ids->vm_id || !new) {
pr_err("Can't make VM id for %d\n", pid);
return -1;
}
new = 0;
core->ids->fs_id = kid_generate_gen(&fs_tree, &elem, &new);
if (!core->ids->fs_id || !new) {
ids->fs_id = kid_generate_gen(&fs_tree, &elem, &new);
if (!ids->fs_id || !new) {
pr_err("Can't make FS id for %d\n", pid);
return -1;
}
new = 0;
core->ids->files_id = kid_generate_gen(&files_tree, &elem, &new);
if (!core->ids->files_id || !new) {
ids->files_id = kid_generate_gen(&files_tree, &elem, &new);
if (!ids->files_id || !new) {
pr_err("Can't make FILES id for %d\n", pid);
return -1;
}
new = 0;
core->ids->sighand_id = kid_generate_gen(&sighand_tree, &elem, &new);
if (!core->ids->sighand_id || !new) {
ids->sighand_id = kid_generate_gen(&sighand_tree, &elem, &new);
if (!ids->sighand_id || !new) {
pr_err("Can't make IO id for %d\n", pid);
return -1;
}
......@@ -731,12 +731,10 @@ static int dump_task_kobj_ids(pid_t pid, CoreEntry *core)
}
static CoreEntry *core_entry_alloc(int alloc_thread_info,
int alloc_tc,
int alloc_ids)
int alloc_tc)
{
CoreEntry *core;
TaskCoreEntry *tc;
TaskKobjIdsEntry *ids;
core = xmalloc(sizeof(*core));
if (!core)
......@@ -759,20 +757,37 @@ static CoreEntry *core_entry_alloc(int alloc_thread_info,
core->tc = tc;
}
if (alloc_ids) {
ids = xmalloc(sizeof(*ids));
if (!ids)
goto err;
task_kobj_ids_entry__init(ids);
core->ids = ids;
}
return core;
err:
core_entry_free(core);
return NULL;
}
static int dump_task_ids(pid_t pid, const struct cr_fdset *cr_fdset)
{
int fd_ids = fdset_fd(cr_fdset, CR_FD_IDS);
TaskKobjIdsEntry *ids;
int ret;
ids = xmalloc(sizeof(*ids));
if (!ids)
return -1;
task_kobj_ids_entry__init(ids);
ret = dump_task_kobj_ids(pid, ids);
if (ret)
goto err_free;
ret = pb_write_one(fd_ids, ids, PB_IDS);
if (ret < 0)
goto err_free;
err_free:
xfree(ids);
return ret;
}
static int dump_task_core_all(pid_t pid, const struct proc_pid_stat *stat,
const struct parasite_dump_misc *misc, const struct parasite_ctl *ctl,
const struct cr_fdset *cr_fdset,
......@@ -782,7 +797,7 @@ static int dump_task_core_all(pid_t pid, const struct proc_pid_stat *stat,
CoreEntry *core;
int ret = -1;
core = core_entry_alloc(1, 1, 1);
core = core_entry_alloc(1, 1);
if (!core)
return -1;
......@@ -790,10 +805,6 @@ static int dump_task_core_all(pid_t pid, const struct proc_pid_stat *stat,
pr_info("Dumping core (pid: %d)\n", pid);
pr_info("----------------------------------------\n");
ret = dump_task_kobj_ids(pid, core);
if (ret)
goto err_free;
ret = dump_task_mm(pid, stat, misc, cr_fdset);
if (ret)
goto err_free;
......@@ -1196,7 +1207,7 @@ static int dump_task_thread(struct parasite_ctl *parasite_ctl, struct pid *tid)
pr_info("Dumping core for thread (pid: %d)\n", pid);
pr_info("----------------------------------------\n");
core = core_entry_alloc(1, 0, 0);
core = core_entry_alloc(1, 0);
if (!core)
goto err;
......@@ -1240,7 +1251,7 @@ static int dump_one_zombie(const struct pstree_item *item,
CoreEntry *core;
int ret = -1, fd_core;
core = core_entry_alloc(0, 1, 0);
core = core_entry_alloc(0, 1);
if (core == NULL)
goto err;
......@@ -1470,6 +1481,12 @@ static int dump_one_task(struct pstree_item *item)
goto err_cure;
}
ret = dump_task_ids(pid, cr_fdset);
if (ret) {
pr_err("Dump ids (pid: %d) failed with %d\n", pid, ret);
goto err_cure;
}
ret = dump_task_threads(parasite_ctl, item);
if (ret) {
pr_err("Can't dump threads\n");
......
......@@ -717,7 +717,7 @@ static int check_core(CoreEntry *core)
}
if (core->tc->task_state != TASK_DEAD) {
if (!core->ids) {
if (!core->ids && !current->ids) {
pr_err("Core IDS data missed for non-zombie\n");
goto out;
}
......
......@@ -356,6 +356,11 @@ void show_core(int fd_core, struct cr_options *o)
pb_show_vertical(fd_core, PB_CORE);
}
void show_ids(int fd_ids, struct cr_options *o)
{
pb_show_vertical(fd_ids, PB_IDS);
}
void show_mm(int fd_mm, struct cr_options *o)
{
pb_show_vertical(fd_mm, PB_MM);
......
......@@ -100,6 +100,7 @@ struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = {
FD_ENTRY(INOTIFY, "inotify", show_inotify),
FD_ENTRY(INOTIFY_WD, "inotify-wd", show_inotify_wd),
FD_ENTRY(CORE, "core-%d", show_core),
FD_ENTRY(IDS, "ids-%d", show_ids),
FD_ENTRY(MM, "mm-%d", show_mm),
FD_ENTRY(VMAS, "vmas-%d", show_vmas),
FD_ENTRY(PIPES, "pipes", show_pipes),
......
......@@ -26,6 +26,7 @@ enum {
CR_FD_FDINFO,
CR_FD_PAGES,
CR_FD_CORE,
CR_FD_IDS,
CR_FD_MM,
CR_FD_VMAS,
CR_FD_SIGACT,
......@@ -141,6 +142,7 @@ void show_files(int fd_files, struct cr_options *o);
void show_pages(int fd_pages, struct cr_options *o);
void show_reg_files(int fd_reg_files, struct cr_options *o);
void show_core(int fd_core, struct cr_options *o);
void show_ids(int fd_ids, struct cr_options *o);
void show_mm(int fd_mm, struct cr_options *o);
void show_vmas(int fd_vma, struct cr_options *o);
void show_pipes(int fd_pipes, struct cr_options *o);
......
......@@ -28,6 +28,7 @@
#define PAGES_MAGIC 0x56084025 /* Vladimir */
#define SHMEM_PAGES_MAGIC PAGES_MAGIC
#define CORE_MAGIC 0x55053847 /* Kolomna */
#define IDS_MAGIC 0x54432030 /* Konigsberg */
#define VMAS_MAGIC 0x54123737 /* Tula */
#define PIPES_MAGIC 0x56513555 /* Tver */
#define PIPES_DATA_MAGIC 0x56453709 /* Dubna */
......
......@@ -44,6 +44,7 @@ enum {
PB_TTY,
PB_TTY_INFO,
PB_RLIMIT,
PB_IDS,
PB_MAX
};
......
......@@ -3,6 +3,7 @@
#include "list.h"
#include "crtools.h"
#include "../protobuf/core.pb-c.h"
/*
* That's the init process which usually inherit
......@@ -40,6 +41,7 @@ struct pstree_item {
int nr_threads; /* number of threads */
struct pid *threads; /* array of threads */
TaskKobjIdsEntry *ids;
struct rst_info rst[0];
};
......
......@@ -98,6 +98,7 @@ void cr_pb_init(void)
CR_PB_DESC(INOTIFY, InotifyFile, inotify_file);
CR_PB_DESC(INOTIFY_WD, InotifyWd, inotify_wd);
CR_PB_DESC(CORE, Core, core);
CR_PB_DESC(IDS, TaskKobjIds, task_kobj_ids);
CR_PB_DESC(MM, Mm, mm);
CR_PB_DESC(VMAS, Vma, vma);
CR_PB_DESC(PIPES, Pipe, pipe);
......
......@@ -177,7 +177,7 @@ static int prepare_pstree_for_shell_job(void)
static int read_pstree_image(void)
{
int ret = 0, i, ps_fd;
int ret = 0, i, ps_fd, fd;
struct pstree_item *pi, *parent = NULL;
pr_info("Reading image tree\n");
......@@ -260,6 +260,18 @@ static int read_pstree_image(void)
task_entries->nr_tasks++;
pstree_entry__free_unpacked(e, NULL);
fd = open_image_ro(CR_FD_IDS, pi->pid.virt);
if (fd < 0) {
if (errno == ENOENT)
continue;
return -1;
}
ret = pb_read_one(fd, &pi->ids, PB_IDS);
close(fd);
if (ret != 1)
goto err;
}
err:
close(ps_fd);
......
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