Commit 66f55b5e authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Andrei Vagin

restore: Do not iterate over parent's files to find leftovers

This patch speeds up creation of child process by disabling
iteration over open files for the most cases. Really, we don't
need that now, as previous patches make parent files do not leak:

mnt namespace fds are stored in fdstore, pid proc files
are closed directly.

So, now we can skip closing old files for the most cases,
except some CLONE_FILES cases: we need that only if parent
have CLONE_FILES in its flags (and for root_item).
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent f11a0ce0
......@@ -1002,6 +1002,30 @@ static int restore_one_zombie(CoreEntry *core)
return -1;
}
static int setup_newborn_fds(struct pstree_item *me)
{
if (clone_service_fd(rsti(me)->service_fd_id))
return -1;
if (!me->parent ||
(rsti(me->parent)->fdt && !(rsti(me)->clone_flags & CLONE_FILES))) {
/*
* When our parent has shared fd table, some of the table owners
* may be already created. Files, they open, will be inherited
* by current process, and here we close them. Also, service fds
* of parent are closed here. And root_item closes the files,
* that were inherited from criu process.
*/
if (close_old_fds())
return -1;
}
if (log_init_by_pid(vpid(me)))
return -1;
return 0;
}
static int check_core(CoreEntry *core, struct pstree_item *me)
{
int ret = -1;
......@@ -1546,12 +1570,7 @@ static int restore_task_with_children(void *_arg)
if ( !(ca->clone_flags & CLONE_FILES))
close_safe(&ca->fd);
ret = clone_service_fd(rsti(current)->service_fd_id);
if (ret)
goto err;
ret = log_init_by_pid(vpid(current));
if (ret < 0)
if (setup_newborn_fds(current))
goto err;
pid = getpid();
......@@ -1561,12 +1580,6 @@ static int restore_task_with_children(void *_arg)
goto err;
}
if (!(ca->clone_flags & CLONE_FILES)) {
ret = close_old_fds();
if (ret)
goto err;
}
if (current->parent == NULL) {
/*
* The root task has to be in its namespaces before executing
......
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