Commit fad59b7b authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Andrei Vagin

restore: Normalize first and last staging switches

Don't set futexes by hands, use the restore_switch_stage
helpers explicitly (for code readability).
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 6b44cd8e
...@@ -1592,10 +1592,18 @@ static int restore_wait_inprogress_tasks() ...@@ -1592,10 +1592,18 @@ static int restore_wait_inprogress_tasks()
return 0; return 0;
} }
static void __restore_switch_stage(int next_stage) static inline void __restore_switch_stage_nw(int next_stage)
{ {
futex_set(&task_entries->nr_in_progress, futex_set(&task_entries->nr_in_progress,
stage_participants(next_stage)); stage_participants(next_stage));
futex_set(&task_entries->start, next_stage);
}
static inline void __restore_switch_stage(int next_stage)
{
if (next_stage != CR_STATE_COMPLETE)
futex_set(&task_entries->nr_in_progress,
stage_participants(next_stage));
futex_set_and_wake(&task_entries->start, next_stage); futex_set_and_wake(&task_entries->start, next_stage);
} }
...@@ -1893,8 +1901,7 @@ static int restore_root_task(struct pstree_item *init) ...@@ -1893,8 +1901,7 @@ static int restore_root_task(struct pstree_item *init)
if (prepare_namespace_before_tasks()) if (prepare_namespace_before_tasks())
return -1; return -1;
futex_set(&task_entries->nr_in_progress, __restore_switch_stage_nw(CR_STATE_RESTORE_NS);
stage_participants(CR_STATE_RESTORE_NS));
ret = fork_with_pid(init); ret = fork_with_pid(init);
if (ret < 0) if (ret < 0)
...@@ -2051,7 +2058,7 @@ static int restore_root_task(struct pstree_item *init) ...@@ -2051,7 +2058,7 @@ static int restore_root_task(struct pstree_item *init)
ret = catch_tasks(root_seized, &flag); ret = catch_tasks(root_seized, &flag);
pr_info("Restore finished successfully. Resuming tasks.\n"); pr_info("Restore finished successfully. Resuming tasks.\n");
futex_set_and_wake(&task_entries->start, CR_STATE_COMPLETE); __restore_switch_stage(CR_STATE_COMPLETE);
if (ret == 0) if (ret == 0)
ret = compel_stop_on_syscall(task_entries->nr_threads, ret = compel_stop_on_syscall(task_entries->nr_threads,
...@@ -2130,7 +2137,7 @@ static int prepare_task_entries(void) ...@@ -2130,7 +2137,7 @@ static int prepare_task_entries(void)
task_entries->nr_threads = 0; task_entries->nr_threads = 0;
task_entries->nr_tasks = 0; task_entries->nr_tasks = 0;
task_entries->nr_helpers = 0; task_entries->nr_helpers = 0;
futex_set(&task_entries->start, CR_STATE_RESTORE_NS); futex_set(&task_entries->start, CR_STATE_FAIL);
mutex_init(&task_entries->userns_sync_lock); mutex_init(&task_entries->userns_sync_lock);
return 0; return 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