mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-22 09:58:09 +00:00
protobuf: Convert pstree_entry to PB engine
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
b02158c14c
commit
ccb254c1f0
32
cr-show.c
32
cr-show.c
@ -32,6 +32,7 @@
|
|||||||
#include "protobuf/remap-file-path.pb-c.h"
|
#include "protobuf/remap-file-path.pb-c.h"
|
||||||
#include "protobuf/fown.pb-c.h"
|
#include "protobuf/fown.pb-c.h"
|
||||||
#include "protobuf/fs.pb-c.h"
|
#include "protobuf/fs.pb-c.h"
|
||||||
|
#include "protobuf/pstree.pb-c.h"
|
||||||
|
|
||||||
#define DEF_PAGES_PER_LINE 6
|
#define DEF_PAGES_PER_LINE 6
|
||||||
|
|
||||||
@ -433,29 +434,30 @@ out:
|
|||||||
|
|
||||||
static int show_collect_pstree(int fd_pstree, struct list_head *collect)
|
static int show_collect_pstree(int fd_pstree, struct list_head *collect)
|
||||||
{
|
{
|
||||||
struct pstree_entry e;
|
PstreeEntry *e;
|
||||||
|
|
||||||
pr_img_head(CR_FD_PSTREE);
|
pr_img_head(CR_FD_PSTREE);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
u32 pid;
|
|
||||||
int ret;
|
int ret;
|
||||||
struct pstree_item *item = NULL;
|
struct pstree_item *item = NULL;
|
||||||
|
|
||||||
ret = read_img_eof(fd_pstree, &e);
|
e = NULL;
|
||||||
|
ret = pb_read_eof(fd_pstree, &e, pstree_entry);
|
||||||
if (ret <= 0)
|
if (ret <= 0)
|
||||||
goto out;
|
goto out;
|
||||||
pr_msg("pid: %8d ppid %8d pgid: %8d sid %8d nr_threads: %8d\n",
|
pr_msg("pid: %8d ppid %8d pgid: %8d sid %8d n_threads: %8d\n",
|
||||||
e.pid, e.ppid, e.pgid, e.sid, e.nr_threads);
|
(int)e->pid, (int)e->ppid, (int)e->pgid,
|
||||||
|
(int)e->sid, (int)e->n_threads);
|
||||||
|
|
||||||
if (collect) {
|
if (collect) {
|
||||||
item = xzalloc(sizeof(struct pstree_item));
|
item = xzalloc(sizeof(struct pstree_item));
|
||||||
if (!item)
|
if (!item)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
item->pid.virt = e.pid;
|
item->pid.virt = e->pid;
|
||||||
item->nr_threads = e.nr_threads;
|
item->nr_threads = e->n_threads;
|
||||||
item->threads = xzalloc(sizeof(u32) * e.nr_threads);
|
item->threads = xzalloc(sizeof(u32) * e->n_threads);
|
||||||
if (!item->threads) {
|
if (!item->threads) {
|
||||||
xfree(item);
|
xfree(item);
|
||||||
return -1;
|
return -1;
|
||||||
@ -464,23 +466,23 @@ static int show_collect_pstree(int fd_pstree, struct list_head *collect)
|
|||||||
list_add_tail(&item->list, collect);
|
list_add_tail(&item->list, collect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.nr_threads) {
|
if (e->n_threads) {
|
||||||
pr_msg(" \\\n");
|
pr_msg(" \\\n");
|
||||||
pr_msg(" --- threads: ");
|
pr_msg(" --- threads: ");
|
||||||
while (e.nr_threads--) {
|
while (e->n_threads--) {
|
||||||
ret = read_img(fd_pstree, &pid);
|
pr_msg(" %6d", (int)e->threads[e->n_threads]);
|
||||||
if (ret < 0)
|
|
||||||
goto out;
|
|
||||||
pr_msg(" %6d", pid);
|
|
||||||
if (item)
|
if (item)
|
||||||
item->threads[e.nr_threads].virt = pid;
|
item->threads[e->n_threads].virt = e->threads[e->n_threads];
|
||||||
}
|
}
|
||||||
pr_msg("\n");
|
pr_msg("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pstree_entry__free_unpacked(e, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
if (e)
|
||||||
|
pstree_entry__free_unpacked(e, NULL);
|
||||||
pr_img_tail(CR_FD_PSTREE);
|
pr_img_tail(CR_FD_PSTREE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -75,14 +75,6 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
#define REMAP_GHOST (1 << 31)
|
#define REMAP_GHOST (1 << 31)
|
||||||
|
|
||||||
struct pstree_entry {
|
|
||||||
u32 pid;
|
|
||||||
u32 ppid;
|
|
||||||
u32 pgid;
|
|
||||||
u32 sid;
|
|
||||||
u32 nr_threads;
|
|
||||||
} __packed;
|
|
||||||
|
|
||||||
struct pipe_entry {
|
struct pipe_entry {
|
||||||
u32 id;
|
u32 id;
|
||||||
u32 pipe_id;
|
u32 pipe_id;
|
||||||
|
@ -30,6 +30,7 @@ PROTO_FILES += eventpoll.proto
|
|||||||
PROTO_FILES += fh.proto
|
PROTO_FILES += fh.proto
|
||||||
PROTO_FILES += inotify.proto
|
PROTO_FILES += inotify.proto
|
||||||
PROTO_FILES += fs.proto
|
PROTO_FILES += fs.proto
|
||||||
|
PROTO_FILES += pstree.proto
|
||||||
|
|
||||||
HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
|
HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
|
||||||
SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
|
SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
|
||||||
|
7
protobuf/pstree.proto
Normal file
7
protobuf/pstree.proto
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
message pstree_entry {
|
||||||
|
required uint32 pid = 1;
|
||||||
|
required uint32 ppid = 2;
|
||||||
|
required uint32 pgid = 3;
|
||||||
|
required uint32 sid = 4;
|
||||||
|
repeated uint32 threads = 5;
|
||||||
|
}
|
68
pstree.c
68
pstree.c
@ -6,6 +6,9 @@
|
|||||||
#include "restorer.h"
|
#include "restorer.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
#include "protobuf.h"
|
||||||
|
#include "protobuf/pstree.pb-c.h"
|
||||||
|
|
||||||
struct pstree_item *root_item;
|
struct pstree_item *root_item;
|
||||||
|
|
||||||
void free_pstree(struct pstree_item *root_item)
|
void free_pstree(struct pstree_item *root_item)
|
||||||
@ -71,7 +74,7 @@ struct pstree_item *pstree_item_next(struct pstree_item *item)
|
|||||||
int dump_pstree(struct pstree_item *root_item)
|
int dump_pstree(struct pstree_item *root_item)
|
||||||
{
|
{
|
||||||
struct pstree_item *item = root_item;
|
struct pstree_item *item = root_item;
|
||||||
struct pstree_entry e;
|
PstreeEntry e = PSTREE_ENTRY__INIT;
|
||||||
int ret = -1, i;
|
int ret = -1, i;
|
||||||
int pstree_fd;
|
int pstree_fd;
|
||||||
|
|
||||||
@ -90,16 +93,20 @@ int dump_pstree(struct pstree_item *root_item)
|
|||||||
e.ppid = item->parent ? item->parent->pid.virt : 0;
|
e.ppid = item->parent ? item->parent->pid.virt : 0;
|
||||||
e.pgid = item->pgid;
|
e.pgid = item->pgid;
|
||||||
e.sid = item->sid;
|
e.sid = item->sid;
|
||||||
e.nr_threads = item->nr_threads;
|
e.n_threads = item->nr_threads;
|
||||||
|
|
||||||
if (write_img(pstree_fd, &e))
|
e.threads = xmalloc(sizeof(e.threads[0]) * e.n_threads);
|
||||||
|
if (!e.threads)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
for (i = 0; i < item->nr_threads; i++) {
|
for (i = 0; i < item->nr_threads; i++)
|
||||||
if (write_img_buf(pstree_fd,
|
e.threads[i] = item->threads[i].virt;
|
||||||
&item->threads[i].virt, sizeof(u32)))
|
|
||||||
goto err;
|
ret = pb_write(pstree_fd, &e, pstree_entry);
|
||||||
}
|
xfree(e.threads);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
@ -122,9 +129,9 @@ int prepare_pstree(void)
|
|||||||
return ps_fd;
|
return ps_fd;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
struct pstree_entry e;
|
PstreeEntry *e;
|
||||||
|
|
||||||
ret = read_img_eof(ps_fd, &e);
|
ret = pb_read_eof(ps_fd, &e, pstree_entry);
|
||||||
if (ret <= 0)
|
if (ret <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -133,19 +140,19 @@ int prepare_pstree(void)
|
|||||||
if (pi == NULL)
|
if (pi == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
pi->pid.virt = e.pid;
|
pi->pid.virt = e->pid;
|
||||||
if (e.pid > max_pid)
|
if (e->pid > max_pid)
|
||||||
max_pid = e.pid;
|
max_pid = e->pid;
|
||||||
|
|
||||||
pi->pgid = e.pgid;
|
pi->pgid = e->pgid;
|
||||||
if (e.pgid > max_pid)
|
if (e->pgid > max_pid)
|
||||||
max_pid = e.pgid;
|
max_pid = e->pgid;
|
||||||
|
|
||||||
pi->sid = e.sid;
|
pi->sid = e->sid;
|
||||||
if (e.sid > max_pid)
|
if (e->sid > max_pid)
|
||||||
max_pid = e.sid;
|
max_pid = e->sid;
|
||||||
|
|
||||||
if (e.ppid == 0) {
|
if (e->ppid == 0) {
|
||||||
BUG_ON(root_item);
|
BUG_ON(root_item);
|
||||||
root_item = pi;
|
root_item = pi;
|
||||||
pi->parent = NULL;
|
pi->parent = NULL;
|
||||||
@ -157,14 +164,14 @@ int prepare_pstree(void)
|
|||||||
* and sit among the last item's ancestors.
|
* and sit among the last item's ancestors.
|
||||||
*/
|
*/
|
||||||
while (parent) {
|
while (parent) {
|
||||||
if (parent->pid.virt == e.ppid)
|
if (parent->pid.virt == e->ppid)
|
||||||
break;
|
break;
|
||||||
parent = parent->parent;
|
parent = parent->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent == NULL)
|
if (parent == NULL)
|
||||||
for_each_pstree_item(parent)
|
for_each_pstree_item(parent)
|
||||||
if (parent->pid.virt == e.ppid)
|
if (parent->pid.virt == e->ppid)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (parent == NULL) {
|
if (parent == NULL) {
|
||||||
@ -179,22 +186,19 @@ int prepare_pstree(void)
|
|||||||
|
|
||||||
parent = pi;
|
parent = pi;
|
||||||
|
|
||||||
pi->nr_threads = e.nr_threads;
|
pi->nr_threads = e->n_threads;
|
||||||
pi->threads = xmalloc(e.nr_threads * sizeof(struct pid));
|
pi->threads = xmalloc(e->n_threads * sizeof(struct pid));
|
||||||
if (!pi->threads)
|
if (!pi->threads)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
for (i = 0; i < e.nr_threads; i++) {
|
for (i = 0; i < e->n_threads; i++)
|
||||||
ret = read_img_buf(ps_fd, &pi->threads[i].virt, sizeof(u32));
|
pi->threads[i].virt = e->threads[i];
|
||||||
if (ret < 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (ret < 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
task_entries->nr += e.nr_threads;
|
task_entries->nr += e->n_threads;
|
||||||
task_entries->nr_tasks++;
|
task_entries->nr_tasks++;
|
||||||
|
|
||||||
|
pstree_entry__free_unpacked(e, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(ps_fd);
|
close(ps_fd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user