2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00

mem: Move shmem preparation routine and rename

We'll collect VmaEntries early before fork.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Pavel Emelyanov
2014-02-03 15:12:08 +04:00
parent c643ed76e7
commit 0786f831d7
5 changed files with 47 additions and 41 deletions

View File

@@ -52,7 +52,7 @@
#include "restorer-blob.h"
#include "crtools.h"
#include "namespaces.h"
#include "shmem.h"
#include "mem.h"
#include "mount.h"
#include "fsnotify.h"
#include "pstree.h"
@@ -177,7 +177,7 @@ static int root_prepare_shared(void)
if (pi->state == TASK_HELPER)
continue;
ret = prepare_shmem_pid(pi->pid.virt);
ret = prepare_mm_pid(pi);
if (ret < 0)
break;

View File

@@ -4,7 +4,9 @@
struct parasite_ctl;
struct vm_area_list;
struct page_pipe;
struct pstree_item;
extern int prepare_mm_pid(struct pstree_item *i);
extern int do_task_reset_dirty_track(int pid);
extern unsigned int dump_pages_args_size(struct vm_area_list *vmas);
extern int parasite_dump_pages_seized(struct parasite_ctl *ctl,

View File

@@ -21,7 +21,8 @@ struct shmem_info {
futex_t lock;
};
extern int prepare_shmem_pid(int pid);
struct _VmaEntry;
extern int collect_shmem(int pid, struct _VmaEntry *vi);
extern int prepare_shmem_restore(void);
extern void show_saved_shmems(void);
extern int get_shmem_fd(int pid, VmaEntry *vi);

40
mem.c
View File

@@ -15,6 +15,8 @@
#include "kerndat.h"
#include "stats.h"
#include "vma.h"
#include "shmem.h"
#include "pstree.h"
#include "protobuf.h"
#include "protobuf/pagemap.pb-c.h"
@@ -338,3 +340,41 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl,
return ret;
}
int prepare_mm_pid(struct pstree_item *i)
{
pid_t pid = i->pid.virt;
int fd, ret = -1;
VmaEntry *vi;
fd = open_image(CR_FD_VMAS, O_RSTR, pid);
if (fd < 0) {
if (errno == ENOENT)
return 0;
else
return -1;
}
while (1) {
ret = pb_read_one_eof(fd, &vi, PB_VMA);
if (ret <= 0)
break;
pr_info("vma 0x%"PRIx64" 0x%"PRIx64"\n", vi->start, vi->end);
if (!vma_entry_is(vi, VMA_ANON_SHARED) ||
vma_entry_is(vi, VMA_AREA_SYSVIPC)) {
vma_entry__free_unpacked(vi, NULL);
continue;
}
ret = collect_shmem(pid, vi);
vma_entry__free_unpacked(vi, NULL);
if (ret)
break;
}
close(fd);
return ret;
}

39
shmem.c
View File

@@ -38,7 +38,7 @@ static struct shmem_info *find_shmem_by_id(unsigned long id)
return find_shmem(si, nr_shmems, id);
}
static int collect_shmem(int pid, VmaEntry *vi)
int collect_shmem(int pid, VmaEntry *vi)
{
unsigned long size = vi->pgoff + vi->end - vi->start;
struct shmem_info *si;
@@ -85,43 +85,6 @@ static int collect_shmem(int pid, VmaEntry *vi)
return 0;
}
int prepare_shmem_pid(int pid)
{
int fd, ret = -1;
VmaEntry *vi;
fd = open_image(CR_FD_VMAS, O_RSTR, pid);
if (fd < 0) {
if (errno == ENOENT)
return 0;
else
return -1;
}
while (1) {
ret = pb_read_one_eof(fd, &vi, PB_VMA);
if (ret <= 0)
break;
pr_info("vma 0x%"PRIx64" 0x%"PRIx64"\n", vi->start, vi->end);
if (!vma_entry_is(vi, VMA_ANON_SHARED) ||
vma_entry_is(vi, VMA_AREA_SYSVIPC)) {
vma_entry__free_unpacked(vi, NULL);
continue;
}
ret = collect_shmem(pid, vi);
vma_entry__free_unpacked(vi, NULL);
if (ret)
break;
}
close(fd);
return ret;
}
static int shmem_wait_and_open(int pid, struct shmem_info *si)
{
char path[128];