From fb177e03121e1c551209b6a2b50f331e4adb9109 Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Tue, 17 Jan 2012 15:28:13 +0300 Subject: [PATCH] restore: generalize mechanism of remapping memory to restorer (v2) Sometime we want to have a shared mapping in restorer. E.g. A storage for shared memory entries. This entries contains locks, which should be released in restorer. v2: fixed according to Pavel's comments Signed-off-by: Andrey Vagin Acked-by: Pavel Emelyanov --- cr-restore.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/cr-restore.c b/cr-restore.c index 4ac76707a..b39b115e5 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -334,14 +334,14 @@ static int prepare_pipes_pid(int pid) return 0; } -static int shmem_remap(struct shmems *old_addr, struct shmems *new_addr) +static int shmem_remap(void *old_addr, void *new_addr, unsigned long size) { char path[PATH_MAX]; int fd; void *ret; sprintf(path, "/proc/self/map_files/%p-%p", - old_addr, (void *)old_addr + SHMEMS_SIZE); + old_addr, (void *)old_addr + size); fd = open(path, O_RDWR); if (fd < 0) { @@ -349,18 +349,13 @@ static int shmem_remap(struct shmems *old_addr, struct shmems *new_addr) return -1; } - ret = mmap(new_addr, SHMEMS_SIZE, PROT_READ | PROT_WRITE, + ret = mmap(new_addr, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0); if (ret != new_addr) { pr_perror("mmap failed\n"); return -1; } - if (new_addr->nr_shmems != old_addr->nr_shmems) { - pr_err("shmem_remap failed\n"); - return -1; - } - close(fd); return 0; } @@ -1289,7 +1284,6 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid) { long restore_task_code_len, restore_task_vma_len; long restore_thread_code_len, restore_thread_vma_len; - long restore_shmem_vma_len; void *exec_mem = MAP_FAILED; void *restore_thread_exec_start; @@ -1321,7 +1315,6 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid) restore_task_vma_len = 0; restore_thread_code_len = 0; restore_thread_vma_len = 0; - restore_shmem_vma_len = SHMEMS_SIZE; pid_dir = open_pid_proc(pid); if (pid_dir < 0) @@ -1336,6 +1329,7 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid) BUILD_BUG_ON(sizeof(struct task_restore_core_args) & 1); BUILD_BUG_ON(sizeof(struct thread_restore_args) & 1); + BUILD_BUG_ON(SHMEMS_SIZE % PAGE_SIZE); fd_pstree = open_image_ro_nocheck(FMT_FNAME_PSTREE, pstree_pid); if (fd_pstree < 0) @@ -1427,7 +1421,7 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid) exec_mem_hint = restorer_get_vma_hint(pid, &self_vma_list, restore_task_vma_len + restore_thread_vma_len + - restore_shmem_vma_len); + SHMEMS_SIZE); if (exec_mem_hint == -1) { pr_err("No suitable area for task_restore bootstrap (%dK)\n", restore_task_vma_len + restore_thread_vma_len); @@ -1484,15 +1478,15 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid) shmems_ref = (struct shmems *)(exec_mem_hint + restore_task_vma_len + restore_thread_vma_len); - ret = shmem_remap(shmems, shmems_ref); + ret = shmem_remap(shmems, shmems_ref, SHMEMS_SIZE); if (ret < 0) goto err; + task_args->shmems = shmems_ref; /* * Arguments for task restoration. */ task_args->pid = pid; - task_args->shmems = shmems_ref; task_args->fd_core = fd_core; task_args->fd_self_vmas = fd_self_vmas;