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

restore: shmem -- Don't poll, use wait helpers instead

Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
[gorcunov: A few tuneups]
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent bd8b2b0f
...@@ -144,33 +144,27 @@ static void shmem_update_real_pid(int vpid, int rpid) ...@@ -144,33 +144,27 @@ static void shmem_update_real_pid(int vpid, int rpid)
static int shmem_wait_and_open(struct shmem_info *si) static int shmem_wait_and_open(struct shmem_info *si)
{ {
unsigned long time = 1000; unsigned long time = 1;
char path[128]; char path[128];
int ret;
sleep(1); cr_wait_until(&si->lock, 1);
while (si->real_pid == 0)
usleep(time);
sprintf(path, "/proc/%d/map_files/%lx-%lx", sprintf(path, "/proc/%d/map_files/%lx-%lx",
si->real_pid, si->start, si->end); si->real_pid, si->start, si->end);
while (1) { pr_info("Waiting for [%s] to appear\n", path);
int ret = open(path, O_RDWR);
if (ret >= 0)
return ret;
if (ret < 0 && errno != ENOENT) { ret = open(path, O_RDWR);
pr_perror(" %d: Can't stat shmem at %s\n", if (ret >= 0)
si->real_pid, path); return ret;
return -1;
}
pr_info("Waiting for [%s] to appear\n", path); if (ret < 0) {
if (time < 20000000) pr_perror(" %d: Can't stat shmem at %s\n",
time <<= 1; si->real_pid, path);
usleep(time); return -1;
} }
return 0;
} }
static int collect_shmem(int pid, struct shmem_entry *e) static int collect_shmem(int pid, struct shmem_entry *e)
......
...@@ -296,6 +296,7 @@ struct shmem_info { ...@@ -296,6 +296,7 @@ struct shmem_info {
unsigned long shmid; unsigned long shmid;
int pid; int pid;
int real_pid; int real_pid;
u32 lock; /* futex */
}; };
struct shmems { struct shmems {
......
...@@ -277,6 +277,23 @@ self_len_end: ...@@ -277,6 +277,23 @@ self_len_end:
if (vma_entry->fd != -1UL) if (vma_entry->fd != -1UL)
sys_close(vma_entry->fd); sys_close(vma_entry->fd);
if (vma_entry_is(vma_entry, VMA_ANON_SHARED) &&
vma_entry->fd == -1UL) {
struct shmem_info *entry;
entry = find_shmem_by_pid(args->shmems,
vma_entry->start,
sys_getpid());
if (!entry) {
write_num_n(__LINE__);
write_hex_n(vma_entry->start);
goto core_restore_end;
}
cr_wait_set(&entry->lock, 1);
}
} }
/* /*
......
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