[CRIU] [PATCH 10/14] restore: read core.img before forking to know a child state
Andrey Vagin
avagin at openvz.org
Mon Mar 25 10:37:53 EDT 2013
It's necessary to get a number of zombies.
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
cr-restore.c | 38 +++++++++++++++++++++++---------------
include/crtools.h | 3 ++-
2 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/cr-restore.c b/cr-restore.c
index bdba840..7454f59 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -752,20 +752,9 @@ out:
return ret < 0 ? ret : 0;
}
-static int restore_one_task(int pid)
+static int restore_one_task(int pid, CoreEntry *core)
{
- int fd, ret;
- CoreEntry *core;
-
- fd = open_image_ro(CR_FD_CORE, pid);
- if (fd < 0)
- return -1;
-
- ret = pb_read_one(fd, &core, PB_CORE);
- close(fd);
-
- if (ret < 0)
- return -1;
+ int ret;
if (check_core(core)) {
ret = -1;
@@ -797,6 +786,8 @@ struct cr_clone_arg {
struct pstree_item *item;
unsigned long clone_flags;
int fd;
+
+ CoreEntry *core;
};
static void write_pidfile(char *pfname, int pid)
@@ -816,10 +807,25 @@ static void write_pidfile(char *pfname, int pid)
static inline int fork_with_pid(struct pstree_item *item)
{
- int ret = -1;
+ int ret = -1, fd;
struct cr_clone_arg ca;
pid_t pid = item->pid.virt;
+ if (item->state != TASK_HELPER) {
+ fd = open_image_ro(CR_FD_CORE, pid);
+ if (fd < 0)
+ return -1;
+
+ ret = pb_read_one(fd, &ca.core, PB_CORE);
+ close(fd);
+
+ if (ret < 0)
+ return -1;
+
+ if (ca.core->tc->task_state == TASK_DEAD)
+ item->parent->rst->nr_zombies++;
+ } else
+ ca.core = NULL;
ca.item = item;
ca.clone_flags = item->rst->clone_flags;
@@ -878,6 +884,8 @@ err_unlock:
close(ca.fd);
}
err:
+ if (ca.core)
+ core_entry__free_unpacked(ca.core, NULL);
return ret;
}
@@ -1111,7 +1119,7 @@ static int restore_task_with_children(void *_arg)
return restore_one_fake();
restore_finish_stage(CR_STATE_RESTORE_PGID);
- return restore_one_task(current->pid.virt);
+ return restore_one_task(current->pid.virt, ca->core);
}
static inline int stage_participants(int next_stage)
diff --git a/include/crtools.h b/include/crtools.h
index 158872f..4778910 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -273,9 +273,10 @@ struct rst_info {
unsigned long premmapped_len;
unsigned long clone_flags;
+ int nr_zombies;
+
int service_fd_id;
struct fdt *fdt;
-
};
static inline int in_vma_area(struct vma_area *vma, unsigned long addr)
--
1.7.11.7
More information about the CRIU
mailing list