Commit 99498681 authored by Andrey Vagin's avatar Andrey Vagin Committed by Cyrill Gorcunov

restore: new mechanism to sync tasks

Now we have only one mutex nr_in_progress, it says how many
tasks are not restored yet. A negative value signs that someone
failed.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Acked-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 4798771c
...@@ -395,7 +395,7 @@ static int prepare_shared(int ps_fd) ...@@ -395,7 +395,7 @@ static int prepare_shared(int ps_fd)
return -1; return -1;
} }
task_entries->nr = 0; task_entries->nr = 0;
task_entries->start = 0; task_entries->start = CR_STATE_RESTORE;
pipes = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0); pipes = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0);
if (pipes == MAP_FAILED) { if (pipes == MAP_FAILED) {
...@@ -433,6 +433,8 @@ static int prepare_shared(int ps_fd) ...@@ -433,6 +433,8 @@ static int prepare_shared(int ps_fd)
lseek(ps_fd, e.nr_children * sizeof(u32) + e.nr_threads * sizeof(u32), SEEK_CUR); lseek(ps_fd, e.nr_children * sizeof(u32) + e.nr_threads * sizeof(u32), SEEK_CUR);
} }
task_entries->nr_in_progress = task_entries->nr;
lseek(ps_fd, sizeof(u32), SEEK_SET); lseek(ps_fd, sizeof(u32), SEEK_SET);
show_saved_shmems(); show_saved_shmems();
...@@ -1231,6 +1233,9 @@ static int restore_root_task(int fd, bool detach) ...@@ -1231,6 +1233,9 @@ static int restore_root_task(int fd, bool detach)
if (ret < 0) if (ret < 0)
return -1; return -1;
pr_info("Wait until all tasks are restored");
cr_wait_until(&task_entries->nr_in_progress, 0);
for (i = 0; i < task_entries->nr; i++) { for (i = 0; i < task_entries->nr; i++) {
pr_info("Wait while the task %d restored\n", pr_info("Wait while the task %d restored\n",
task_entries->entries[i].pid); task_entries->entries[i].pid);
...@@ -1238,7 +1243,7 @@ static int restore_root_task(int fd, bool detach) ...@@ -1238,7 +1243,7 @@ static int restore_root_task(int fd, bool detach)
} }
pr_info("Go on!!!\n"); pr_info("Go on!!!\n");
cr_wait_set(&task_entries->start, 1); cr_wait_set(&task_entries->start, CR_STATE_COMPLETE);
if (!detach) if (!detach)
wait(NULL); wait(NULL);
......
...@@ -193,6 +193,11 @@ struct shmems { ...@@ -193,6 +193,11 @@ struct shmems {
#define TASK_ENTRIES_SIZE 4096 #define TASK_ENTRIES_SIZE 4096
enum {
CR_STATE_RESTORE,
CR_STATE_COMPLETE
};
struct task_entry { struct task_entry {
int pid; int pid;
u32 done; // futex u32 done; // futex
...@@ -200,6 +205,7 @@ struct task_entry { ...@@ -200,6 +205,7 @@ struct task_entry {
struct task_entries { struct task_entries {
int nr; int nr;
u32 nr_in_progress;
u32 start; //futex u32 start; //futex
struct task_entry entries[0]; struct task_entry entries[0];
}; };
......
...@@ -505,10 +505,11 @@ long restore_task(struct task_restore_core_args *args) ...@@ -505,10 +505,11 @@ long restore_task(struct task_restore_core_args *args)
} }
task_entry = task_get_entry(args->task_entries, my_pid); task_entry = task_get_entry(args->task_entries, my_pid);
cr_wait_dec(&args->task_entries->nr_in_progress);
cr_wait_set(&task_entry->done, 1); cr_wait_set(&task_entry->done, 1);
write_num(sys_getpid()); write_num(sys_getpid());
write_string_n(": Restored"); write_string_n(": Restored");
cr_wait_while(&args->task_entries->start, 0); cr_wait_while(&args->task_entries->start, CR_STATE_RESTORE);
ret = sys_munmap(args->task_entries, TASK_ENTRIES_SIZE); ret = sys_munmap(args->task_entries, TASK_ENTRIES_SIZE);
if (ret < 0) { if (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