Commit 48f624ee authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

restore: Drop real_pid member from shmem_info structure

It's not needed anymore, it was handing cases
where no fork-with-pid functionality were in
kernel, but now it's simply unneeded.

Also drop redundant getpid() calls.

Passes all tests (except fork test which known to fail).
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Acked-by: 's avatarPavel Emelyanov <xemul@parllels.com>
parent cf74b78b
...@@ -101,7 +101,7 @@ static int nr_pipes; ...@@ -101,7 +101,7 @@ static int nr_pipes;
static pid_t pstree_pid; static pid_t pstree_pid;
static int restore_task_with_children(int my_pid); static int restore_task_with_children(int pid);
static void sigreturn_restore(pid_t pstree_pid, pid_t pid); static void sigreturn_restore(pid_t pstree_pid, pid_t pid);
static void show_saved_shmems(void) static void show_saved_shmems(void)
...@@ -142,34 +142,25 @@ static struct pipe_info *find_pipe(unsigned int pipeid) ...@@ -142,34 +142,25 @@ static struct pipe_info *find_pipe(unsigned int pipeid)
return NULL; return NULL;
} }
static void shmem_update_real_pid(int vpid, int rpid) static int shmem_wait_and_open(int pid, struct shmem_info *si)
{
int i;
for (i = 0; i < shmems->nr_shmems; i++)
if (shmems->entries[i].pid == vpid)
shmems->entries[i].real_pid = rpid;
}
static int shmem_wait_and_open(struct shmem_info *si)
{ {
unsigned long time = 1; unsigned long time = 1;
char path[128]; char path[128];
int ret; int ret;
sprintf(path, "/proc/%d/map_files/%lx-%lx", sprintf(path, "/proc/%d/map_files/%lx-%lx",
si->real_pid, si->start, si->end); si->pid, si->start, si->end);
pr_info("%d: Waiting for [%s] to appear\n", getpid(), path); pr_info("%d: Waiting for [%s] to appear\n", pid, path);
cr_wait_until(&si->lock, 1); cr_wait_until(&si->lock, 1);
pr_info("%d: Opening shmem [%s] \n", getpid(), path); pr_info("%d: Opening shmem [%s] \n", pid, path);
ret = open(path, O_RDWR); ret = open(path, O_RDWR);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
else if (ret < 0) else if (ret < 0)
pr_perror(" %d: Can't stat shmem at %s\n", pr_perror(" %d: Can't stat shmem at %s\n",
si->real_pid, path); si->pid, path);
return ret; return ret;
} }
...@@ -213,7 +204,6 @@ static int collect_shmem(int pid, struct shmem_entry *e) ...@@ -213,7 +204,6 @@ static int collect_shmem(int pid, struct shmem_entry *e)
entries[nr_shmems].end = e->end; entries[nr_shmems].end = e->end;
entries[nr_shmems].shmid = e->shmid; entries[nr_shmems].shmid = e->shmid;
entries[nr_shmems].pid = pid; entries[nr_shmems].pid = pid;
entries[nr_shmems].real_pid = 0;
cr_wait_init(&entries[nr_shmems].lock); cr_wait_init(&entries[nr_shmems].lock);
...@@ -554,7 +544,7 @@ static int try_fixup_shared_map(int pid, struct vma_entry *vi, int fd) ...@@ -554,7 +544,7 @@ static int try_fixup_shared_map(int pid, struct vma_entry *vi, int fd)
if (si->pid != pid) { if (si->pid != pid) {
int sh_fd; int sh_fd;
sh_fd = shmem_wait_and_open(si); sh_fd = shmem_wait_and_open(pid, si);
pr_info("%d: Fixing %lx vma to %lx/%d shmem -> %d\n", pr_info("%d: Fixing %lx vma to %lx/%d shmem -> %d\n",
pid, vi->start, si->shmid, si->pid, sh_fd); pid, vi->start, si->shmid, si->pid, sh_fd);
if (sh_fd < 0) { if (sh_fd < 0) {
...@@ -817,7 +807,6 @@ static int create_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi, int ...@@ -817,7 +807,6 @@ static int create_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi, int
{ {
unsigned long time = 1000; unsigned long time = 1000;
int pfd[2], tmp; int pfd[2], tmp;
u32 real_pid;
pr_info("\t%d: Creating pipe %x%s\n", pid, e->pipeid, pipe_is_rw(pi) ? "(rw)" : ""); pr_info("\t%d: Creating pipe %x%s\n", pid, e->pipeid, pipe_is_rw(pi) ? "(rw)" : "");
...@@ -834,7 +823,7 @@ static int create_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi, int ...@@ -834,7 +823,7 @@ static int create_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi, int
if (reopen_pipe(pfd[1], &pi->write_fd, &pi->read_fd, pipes_fd)) if (reopen_pipe(pfd[1], &pi->write_fd, &pi->read_fd, pipes_fd))
return -1; return -1;
cr_wait_set(&pi->real_pid, getpid()); cr_wait_set(&pi->real_pid, pid);
pi->status |= PIPE_CREATED; pi->status |= PIPE_CREATED;
...@@ -1132,7 +1121,11 @@ static inline int fork_with_pid(int pid) ...@@ -1132,7 +1121,11 @@ static inline int fork_with_pid(int pid)
return -1; return -1;
} }
ret = restore_task_with_children(my_pid); /*
* We should never return here.
*/
ret = restore_task_with_children(pid);
pr_err("%d: Something failed with code %d\n", pid, ret); pr_err("%d: Something failed with code %d\n", pid, ret);
exit(1); exit(1);
} }
...@@ -1160,28 +1153,31 @@ static void sigchld_handler(int signal, siginfo_t *siginfo, void *data) ...@@ -1160,28 +1153,31 @@ static void sigchld_handler(int signal, siginfo_t *siginfo, void *data)
cr_wait_set(&task_entries->nr_in_progress, -1); cr_wait_set(&task_entries->nr_in_progress, -1);
} }
static int restore_task_with_children(int my_pid) static int restore_task_with_children(int pid)
{ {
int *pids; int *pids;
int fd, ret, i; int fd, ret, i;
struct pstree_entry e; struct pstree_entry e;
sigset_t blockmask; sigset_t blockmask;
/* The block mask will be restored in sigresturn /*
* This code should be removed, when a freezer will be added */ * The block mask will be restored in sigresturn.
*
* TODO: This code should be removed, when a freezer will be added.
*/
sigfillset(&blockmask); sigfillset(&blockmask);
sigdelset(&blockmask, SIGCHLD); sigdelset(&blockmask, SIGCHLD);
ret = sigprocmask(SIG_BLOCK, &blockmask, NULL); ret = sigprocmask(SIG_BLOCK, &blockmask, NULL);
if (ret) { if (ret) {
pr_perror("%d: Can't block signals\n", my_pid); pr_perror("%d: Can't block signals\n", pid);
exit(1); exit(1);
} }
pr_info("%d: Starting restore\n", my_pid); pr_info("%d: Starting restore\n", pid);
fd = open_image_ro_nocheck(FMT_FNAME_PSTREE, pstree_pid); fd = open_image_ro_nocheck(FMT_FNAME_PSTREE, pstree_pid);
if (fd < 0) { if (fd < 0) {
pr_perror("%d: Can't reopen pstree image\n", my_pid); pr_perror("%d: Can't reopen pstree image\n", pid);
exit(1); exit(1);
} }
...@@ -1192,13 +1188,13 @@ static int restore_task_with_children(int my_pid) ...@@ -1192,13 +1188,13 @@ static int restore_task_with_children(int my_pid)
break; break;
if (ret != sizeof(e)) { if (ret != sizeof(e)) {
pr_err("%d: Read returned %d\n", my_pid, ret); pr_err("%d: Read returned %d\n", pid, ret);
if (ret < 0) if (ret < 0)
pr_perror("%d: Can't read pstree\n", my_pid); pr_perror("%d: Can't read pstree\n", pid);
exit(1); exit(1);
} }
if (e.pid != my_pid) { if (e.pid != pid) {
lseek(fd, e.nr_children * sizeof(u32) + e.nr_threads * sizeof(u32), SEEK_CUR); lseek(fd, e.nr_children * sizeof(u32) + e.nr_threads * sizeof(u32), SEEK_CUR);
continue; continue;
} }
...@@ -1214,15 +1210,15 @@ static int restore_task_with_children(int my_pid) ...@@ -1214,15 +1210,15 @@ static int restore_task_with_children(int my_pid)
ret = read(fd, pids, i); ret = read(fd, pids, i);
if (ret != i) { if (ret != i) {
pr_perror("%d: Can't read children pids\n", my_pid); pr_perror("%d: Can't read children pids\n", pid);
exit(1); exit(1);
} }
close(fd); close(fd);
pr_info("%d: Restoring %d children:\n", my_pid, e.nr_children); pr_info("%d: Restoring %d children:\n", pid, e.nr_children);
for (i = 0; i < e.nr_children; i++) { for (i = 0; i < e.nr_children; i++) {
pr_info("\tFork %d from %d\n", pids[i], my_pid); pr_info("\tFork %d from %d\n", pids[i], pid);
ret = fork_with_pid(pids[i]); ret = fork_with_pid(pids[i]);
if (ret < 0) if (ret < 0)
exit(1); exit(1);
...@@ -1230,9 +1226,7 @@ static int restore_task_with_children(int my_pid) ...@@ -1230,9 +1226,7 @@ static int restore_task_with_children(int my_pid)
} else } else
close(fd); close(fd);
shmem_update_real_pid(my_pid, getpid()); return restore_one_task(pid);
return restore_one_task(my_pid);
} }
static int restore_root_task(int fd, bool detach) static int restore_root_task(int fd, bool detach)
...@@ -1406,7 +1400,7 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid) ...@@ -1406,7 +1400,7 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid)
if (pid_dir < 0) if (pid_dir < 0)
goto err; goto err;
ret = parse_maps(getpid(), pid_dir, &self_vma_list, false); ret = parse_maps(pid, pid_dir, &self_vma_list, false);
close(pid_dir); close(pid_dir);
if (ret) if (ret)
goto err; goto err;
...@@ -1426,7 +1420,8 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid) ...@@ -1426,7 +1420,8 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid)
if (fd_core < 0) if (fd_core < 0)
pr_perror("Can't open core-out-%d\n", pid); pr_perror("Can't open core-out-%d\n", pid);
if (get_image_path(self_vmas_path, sizeof(self_vmas_path), FMT_FNAME_VMAS, getpid())) if (get_image_path(self_vmas_path, sizeof(self_vmas_path),
FMT_FNAME_VMAS, pid))
goto err; goto err;
fd_self_vmas = open(self_vmas_path, O_CREAT | O_RDWR | O_TRUNC, CR_FD_PERM); fd_self_vmas = open(self_vmas_path, O_CREAT | O_RDWR | O_TRUNC, CR_FD_PERM);
......
...@@ -182,7 +182,6 @@ struct shmem_info { ...@@ -182,7 +182,6 @@ struct shmem_info {
unsigned long end; unsigned long end;
unsigned long shmid; unsigned long shmid;
int pid; int pid;
int real_pid;
u32 lock; /* futex */ u32 lock; /* futex */
}; };
...@@ -222,7 +221,7 @@ find_shmem_by_pid(struct shmems *shmems, unsigned long start, int pid) ...@@ -222,7 +221,7 @@ find_shmem_by_pid(struct shmems *shmems, unsigned long start, int pid)
si = &shmems->entries[i]; si = &shmems->entries[i];
if (si->start == start && if (si->start == start &&
si->end > start && si->end > start &&
si->real_pid == pid) si->pid == pid)
return si; return si;
} }
......
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