Commit 9dc332a5 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

parasite-syscall: Add parasite_[init|fini]_threads_seized helpers

We will use them from crtools code to save and restore blocked
signals mask of threads.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 98544842
......@@ -54,4 +54,8 @@ extern struct parasite_ctl *parasite_infect_seized(pid_t pid,
extern struct parasite_tty_args *parasite_dump_tty(struct parasite_ctl *ctl, int fd);
struct pstree_item;
extern int parasite_init_threads_seized(struct parasite_ctl *ctl, struct pstree_item *item);
extern int parasite_fini_threads_seized(struct parasite_ctl *ctl, struct pstree_item *item);
#endif /* PARASITE_SYSCALL_H_ */
......@@ -674,6 +674,58 @@ int parasite_get_proc_fd_seized(struct parasite_ctl *ctl)
return fd;
}
int parasite_init_threads_seized(struct parasite_ctl *ctl, struct pstree_item *item)
{
int ret = 0, i;
for (i = 0; i < item->nr_threads; i++) {
if (item->pid.real == item->threads[i].real)
continue;
ret = parasite_execute_by_pid(PARASITE_CMD_INIT_THREAD, ctl,
item->threads[i].real);
if (ret) {
pr_err("Can't init thread in parasite %d\n",
item->threads[i].real);
break;
}
}
return ret;
}
int parasite_fini_threads_seized(struct parasite_ctl *ctl, struct pstree_item *item)
{
int ret = 0, i;
for (i = 0; i < item->nr_threads; i++) {
if (item->pid.real == item->threads[i].real)
continue;
ret = parasite_execute_by_pid(PARASITE_CMD_FINI_THREAD, ctl,
item->threads[i].real);
/*
* Note the thread's fini() can be called even when not
* all threads were init()'ed, say we're rolling back from
* error happened while we were init()'ing some thread, thus
* -ENOENT will be returned but we should continie for the
* rest of threads set.
*
* Strictly speaking we always init() threads in sequence thus
* we could simply break the loop once first -ENOENT returned
* but I prefer to be on a safe side even if some future changes
* would change the code logic.
*/
if (ret && ret != -ENOENT) {
pr_err("Can't fini thread in parasite %d\n",
item->threads[i].real);
break;
}
}
return ret;
}
int parasite_cure_seized(struct parasite_ctl *ctl)
{
int ret = 0;
......
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