Skip to content

Commit ad58f51

Browse files
committed
restore: split finalize_restore into two stages
First stage of finalize_restore unmaps the restorer blob, second stage detaches from processes. After first stage process tree is completely restored and processes are ready to continue run through sigreturn. This splitting allows us to execute something between these stages (e.g. restore freezer cgroup state). Signed-off-by: Evgeniy Akimov <[email protected]> Signed-off-by: Eugene Batalov <[email protected]>
1 parent a18dd12 commit ad58f51

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

cr-restore.c

+21-12
Original file line numberDiff line numberDiff line change
@@ -1705,33 +1705,42 @@ static int clear_breakpoints()
17051705
return ret;
17061706
}
17071707

1708-
static void finalize_restore(int status)
1708+
static void finalize_restore(void)
17091709
{
17101710
struct pstree_item *item;
17111711

17121712
for_each_pstree_item(item) {
17131713
pid_t pid = item->pid.real;
17141714
struct parasite_ctl *ctl;
1715-
int i;
17161715

17171716
if (!task_alive(item))
17181717
continue;
17191718

1720-
if (status < 0)
1721-
goto detach;
1722-
17231719
/* Unmap the restorer blob */
17241720
ctl = parasite_prep_ctl(pid, NULL);
17251721
if (ctl == NULL)
1726-
goto detach;
1722+
continue;
17271723

17281724
parasite_unmap(ctl, (unsigned long)rsti(item)->munmap_restorer);
17291725

17301726
xfree(ctl);
17311727

17321728
if (item->state == TASK_STOPPED)
17331729
kill(item->pid.real, SIGSTOP);
1734-
detach:
1730+
}
1731+
}
1732+
1733+
static void finalize_restore_detach(int status)
1734+
{
1735+
struct pstree_item *item;
1736+
1737+
for_each_pstree_item(item) {
1738+
pid_t pid;
1739+
int i;
1740+
1741+
if (!task_alive(item))
1742+
continue;
1743+
17351744
for (i = 0; i < item->nr_threads; i++) {
17361745
pid = item->threads[i].real;
17371746
if (pid < 0) {
@@ -1936,11 +1945,11 @@ static int restore_root_task(struct pstree_item *init)
19361945
if (clear_breakpoints())
19371946
pr_err("Unable to flush breakpoints\n");
19381947

1939-
/*
1940-
* finalize_restore() always detaches from processes and
1941-
* they continue run through sigreturn.
1942-
*/
1943-
finalize_restore(ret);
1948+
if (ret == 0)
1949+
finalize_restore();
1950+
1951+
/* Detaches from processes and they continue run through sigreturn. */
1952+
finalize_restore_detach(ret);
19441953

19451954
write_stats(RESTORE_STATS);
19461955

0 commit comments

Comments
 (0)