mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-01 06:45:35 +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:
@@ -52,7 +52,7 @@
|
|||||||
#include "restorer-blob.h"
|
#include "restorer-blob.h"
|
||||||
#include "crtools.h"
|
#include "crtools.h"
|
||||||
#include "namespaces.h"
|
#include "namespaces.h"
|
||||||
#include "shmem.h"
|
#include "mem.h"
|
||||||
#include "mount.h"
|
#include "mount.h"
|
||||||
#include "fsnotify.h"
|
#include "fsnotify.h"
|
||||||
#include "pstree.h"
|
#include "pstree.h"
|
||||||
@@ -177,7 +177,7 @@ static int root_prepare_shared(void)
|
|||||||
if (pi->state == TASK_HELPER)
|
if (pi->state == TASK_HELPER)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ret = prepare_shmem_pid(pi->pid.virt);
|
ret = prepare_mm_pid(pi);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@@ -4,7 +4,9 @@
|
|||||||
struct parasite_ctl;
|
struct parasite_ctl;
|
||||||
struct vm_area_list;
|
struct vm_area_list;
|
||||||
struct page_pipe;
|
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 int do_task_reset_dirty_track(int pid);
|
||||||
extern unsigned int dump_pages_args_size(struct vm_area_list *vmas);
|
extern unsigned int dump_pages_args_size(struct vm_area_list *vmas);
|
||||||
extern int parasite_dump_pages_seized(struct parasite_ctl *ctl,
|
extern int parasite_dump_pages_seized(struct parasite_ctl *ctl,
|
||||||
|
@@ -21,7 +21,8 @@ struct shmem_info {
|
|||||||
futex_t lock;
|
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 int prepare_shmem_restore(void);
|
||||||
extern void show_saved_shmems(void);
|
extern void show_saved_shmems(void);
|
||||||
extern int get_shmem_fd(int pid, VmaEntry *vi);
|
extern int get_shmem_fd(int pid, VmaEntry *vi);
|
||||||
|
40
mem.c
40
mem.c
@@ -15,6 +15,8 @@
|
|||||||
#include "kerndat.h"
|
#include "kerndat.h"
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
#include "vma.h"
|
#include "vma.h"
|
||||||
|
#include "shmem.h"
|
||||||
|
#include "pstree.h"
|
||||||
|
|
||||||
#include "protobuf.h"
|
#include "protobuf.h"
|
||||||
#include "protobuf/pagemap.pb-c.h"
|
#include "protobuf/pagemap.pb-c.h"
|
||||||
@@ -338,3 +340,41 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl,
|
|||||||
return ret;
|
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
39
shmem.c
@@ -38,7 +38,7 @@ static struct shmem_info *find_shmem_by_id(unsigned long id)
|
|||||||
return find_shmem(si, nr_shmems, 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;
|
unsigned long size = vi->pgoff + vi->end - vi->start;
|
||||||
struct shmem_info *si;
|
struct shmem_info *si;
|
||||||
@@ -85,43 +85,6 @@ static int collect_shmem(int pid, VmaEntry *vi)
|
|||||||
return 0;
|
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)
|
static int shmem_wait_and_open(int pid, struct shmem_info *si)
|
||||||
{
|
{
|
||||||
char path[128];
|
char path[128];
|
||||||
|
Reference in New Issue
Block a user