mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-22 01:51:51 +00:00
protobuf: Convert vma_entry to PB format v3
v2: - Use regular uint types in message proto - Use PB engine for "show" v3: - drop usage of temp. variable in prepare_shmem_pid Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
ffd40996ea
commit
4806e1395f
@ -391,7 +391,7 @@ static int dump_task_fs(pid_t pid, struct cr_fdset *fdset)
|
||||
return pb_write(fdset_fd(fdset, CR_FD_FS), &fe, fs_entry);
|
||||
}
|
||||
|
||||
static int dump_filemap(pid_t pid, struct vma_entry *vma, int file_fd,
|
||||
static int dump_filemap(pid_t pid, VmaEntry *vma, int file_fd,
|
||||
const struct cr_fdset *fdset)
|
||||
{
|
||||
struct fd_parms p = FD_PARMS_INIT;
|
||||
@ -423,7 +423,7 @@ static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list,
|
||||
fd = fdset_fd(cr_fdset, CR_FD_VMAS);
|
||||
|
||||
list_for_each_entry(vma_area, vma_area_list, list) {
|
||||
struct vma_entry *vma = &vma_area->vma;
|
||||
VmaEntry *vma = &vma_area->vma;
|
||||
|
||||
pr_info_vma(vma_area);
|
||||
|
||||
@ -439,7 +439,7 @@ static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list,
|
||||
ret = 0;
|
||||
|
||||
if (!ret)
|
||||
ret = write_img(fd, vma);
|
||||
ret = pb_write(fd, vma, vma_entry);
|
||||
if (ret)
|
||||
goto err;
|
||||
}
|
||||
|
15
cr-restore.c
15
cr-restore.c
@ -52,6 +52,7 @@
|
||||
#include "protobuf.h"
|
||||
#include "protobuf/sa.pb-c.h"
|
||||
#include "protobuf/itimer.pb-c.h"
|
||||
#include "protobuf/vma.pb-c.h"
|
||||
|
||||
static struct pstree_item *me;
|
||||
|
||||
@ -141,6 +142,7 @@ static int read_and_open_vmas(int pid, struct list_head *vmas, int *nr_vmas)
|
||||
*nr_vmas = 0;
|
||||
while (1) {
|
||||
struct vma_area *vma;
|
||||
VmaEntry *e;
|
||||
|
||||
ret = -1;
|
||||
vma = alloc_vma_area();
|
||||
@ -149,10 +151,13 @@ static int read_and_open_vmas(int pid, struct list_head *vmas, int *nr_vmas)
|
||||
|
||||
(*nr_vmas)++;
|
||||
list_add_tail(&vma->list, vmas);
|
||||
ret = read_img_eof(fd, &vma->vma);
|
||||
ret = pb_read_eof(fd, &e, vma_entry);
|
||||
if (ret <= 0)
|
||||
break;
|
||||
|
||||
vma->vma = *e;
|
||||
vma_entry__free_unpacked(e, NULL);
|
||||
|
||||
if (!(vma_entry_is(&vma->vma, VMA_AREA_REGULAR)))
|
||||
continue;
|
||||
|
||||
@ -1055,9 +1060,9 @@ static int prepare_creds(int pid, struct task_restore_core_args *args)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct vma_entry *vma_list_remap(void *addr, unsigned long len, struct list_head *vmas)
|
||||
static VmaEntry *vma_list_remap(void *addr, unsigned long len, struct list_head *vmas)
|
||||
{
|
||||
struct vma_entry *vma, *ret;
|
||||
VmaEntry *vma, *ret;
|
||||
struct vma_area *vma_area;
|
||||
|
||||
ret = vma = mmap(addr, len, PROT_READ | PROT_WRITE,
|
||||
@ -1146,8 +1151,8 @@ static int sigreturn_restore(pid_t pid, struct list_head *tgt_vmas, int nr_vmas)
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
self_vmas_len = round_up((ret + 1) * sizeof(struct vma_entry), PAGE_SIZE);
|
||||
vmas_len = round_up((nr_vmas + 1) * sizeof(struct vma_entry), PAGE_SIZE);
|
||||
self_vmas_len = round_up((ret + 1) * sizeof(VmaEntry), PAGE_SIZE);
|
||||
vmas_len = round_up((nr_vmas + 1) * sizeof(VmaEntry), PAGE_SIZE);
|
||||
|
||||
/* pr_info_vma_list(&self_vma_list); */
|
||||
|
||||
|
20
cr-show.c
20
cr-show.c
@ -38,6 +38,7 @@
|
||||
#include "protobuf/sa.pb-c.h"
|
||||
#include "protobuf/itimer.pb-c.h"
|
||||
#include "protobuf/mm.pb-c.h"
|
||||
#include "protobuf/vma.pb-c.h"
|
||||
#include "protobuf/creds.pb-c.h"
|
||||
|
||||
#define DEF_PAGES_PER_LINE 6
|
||||
@ -166,24 +167,7 @@ void show_fs(int fd_fs, struct cr_options *o)
|
||||
|
||||
void show_vmas(int fd_vma, struct cr_options *o)
|
||||
{
|
||||
struct vma_area vma_area = {};
|
||||
struct vma_entry ve;
|
||||
|
||||
pr_img_head(CR_FD_VMAS);
|
||||
|
||||
while (1) {
|
||||
int ret;
|
||||
|
||||
ret = read_img_eof(fd_vma, &ve);
|
||||
if (ret <= 0)
|
||||
break;
|
||||
|
||||
/* Simply in a sake of fancy printing */
|
||||
vma_area.vma = ve;
|
||||
pr_msg_vma(&vma_area);
|
||||
}
|
||||
|
||||
pr_img_tail(CR_FD_VMAS);
|
||||
pb_show_plain(fd_vma, vma_entry);
|
||||
}
|
||||
|
||||
static int nice_width_for(unsigned long addr)
|
||||
|
2
files.c
2
files.c
@ -531,7 +531,7 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int get_filemap_fd(int pid, struct vma_entry *vma_entry)
|
||||
int get_filemap_fd(int pid, VmaEntry *vma_entry)
|
||||
{
|
||||
return open_reg_by_id(vma_entry->shmid);
|
||||
}
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include "util.h"
|
||||
#include "image.h"
|
||||
|
||||
#include "../protobuf/vma.pb-c.h"
|
||||
|
||||
#define CR_FD_PERM (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)
|
||||
#define CR_FD_PERM_DUMP (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
|
||||
|
||||
@ -168,7 +170,7 @@ void free_mappings(struct list_head *vma_area_list);
|
||||
|
||||
struct vma_area {
|
||||
struct list_head list;
|
||||
struct vma_entry vma;
|
||||
VmaEntry vma;
|
||||
int vm_file_fd;
|
||||
};
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "../protobuf/fdinfo.pb-c.h"
|
||||
#include "../protobuf/fown.pb-c.h"
|
||||
#include "../protobuf/vma.pb-c.h"
|
||||
|
||||
struct pstree_item;
|
||||
struct file_desc;
|
||||
@ -87,7 +88,7 @@ extern void show_saved_files(void);
|
||||
extern int prepare_fds(struct pstree_item *me);
|
||||
extern int prepare_fd_pid(int pid, struct rst_info *rst_info);
|
||||
extern int prepare_shared_fdinfo(void);
|
||||
extern int get_filemap_fd(int pid, struct vma_entry *vma_entry);
|
||||
extern int get_filemap_fd(int pid, VmaEntry *vma_entry);
|
||||
extern int prepare_fs(int pid);
|
||||
extern int set_fd_flags(int fd, int flags);
|
||||
|
||||
|
@ -55,17 +55,6 @@
|
||||
|
||||
#define USK_EXTERN (1 << 0)
|
||||
|
||||
struct vma_entry {
|
||||
u64 start;
|
||||
u64 end;
|
||||
u64 pgoff;
|
||||
u64 shmid;
|
||||
u32 prot;
|
||||
u32 flags;
|
||||
u32 status;
|
||||
s64 fd;
|
||||
} __packed;
|
||||
|
||||
#define VMA_AREA_NONE (0 << 0)
|
||||
#define VMA_AREA_REGULAR (1 << 0) /* Dumpable area */
|
||||
#define VMA_AREA_STACK (1 << 1)
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
#include "util-net.h"
|
||||
|
||||
#include "../protobuf/vma.pb-c.h"
|
||||
|
||||
#define __head __used __section(.head.text)
|
||||
|
||||
enum {
|
||||
@ -42,7 +44,7 @@ struct parasite_init_args {
|
||||
};
|
||||
|
||||
struct parasite_dump_pages_args {
|
||||
struct vma_entry vma_entry;
|
||||
VmaEntry vma_entry;
|
||||
unsigned long nrpages_dumped; /* how many pages are dumped */
|
||||
unsigned long nrpages_skipped;
|
||||
unsigned long nrpages_total;
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "crtools.h"
|
||||
|
||||
#include "../protobuf/mm.pb-c.h"
|
||||
#include "../protobuf/vma.pb-c.h"
|
||||
#include "../protobuf/creds.pb-c.h"
|
||||
|
||||
#ifndef CONFIG_X86_64
|
||||
@ -80,8 +81,8 @@ struct task_restore_core_args {
|
||||
struct thread_restore_args *thread_args; /* array of thread arguments */
|
||||
struct shmems *shmems;
|
||||
struct task_entries *task_entries;
|
||||
struct vma_entry *self_vmas;
|
||||
struct vma_entry *tgt_vmas;
|
||||
VmaEntry *self_vmas;
|
||||
VmaEntry *tgt_vmas;
|
||||
rt_sigaction_t sigchld_act;
|
||||
|
||||
struct itimerval itimers[3];
|
||||
|
@ -1,16 +1,18 @@
|
||||
#ifndef __CR_SHMEM_H__
|
||||
#define __CR_SHMEM_H__
|
||||
|
||||
#include "../protobuf/vma.pb-c.h"
|
||||
|
||||
int prepare_shmem_pid(int pid);
|
||||
int prepare_shmem_restore(void);
|
||||
void show_saved_shmems(void);
|
||||
struct vma_entry;
|
||||
int get_shmem_fd(int pid, struct vma_entry *vi);
|
||||
int get_shmem_fd(int pid, VmaEntry *vi);
|
||||
|
||||
struct shmems;
|
||||
extern struct shmems *rst_shmems;
|
||||
|
||||
int cr_dump_shmem(void);
|
||||
int add_shmem_area(pid_t pid, struct vma_entry *vma);
|
||||
int add_shmem_area(pid_t pid, VmaEntry *vma);
|
||||
int init_shmem_dump(void);
|
||||
void fini_shmem_dump(void);
|
||||
#endif
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include "types.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "../protobuf/vma.pb-c.h"
|
||||
|
||||
#define PREF_SHIFT_OP(pref, op, size) ((size) op (pref ##BYTES_SHIFT))
|
||||
#define KBYTES_SHIFT 10
|
||||
#define MBYTES_SHIFT 20
|
||||
@ -155,6 +157,7 @@ extern void pr_vma(unsigned int loglevel, const struct vma_area *vma_area);
|
||||
({ \
|
||||
struct vma_area *p__ = xzalloc(sizeof(*p__)); \
|
||||
if (p__) { \
|
||||
vma_entry__init(&p__->vma); \
|
||||
p__->vm_file_fd = -1; \
|
||||
p__->vma.fd = -1; \
|
||||
} \
|
||||
|
@ -102,7 +102,7 @@ static void sys_write_msg(const char *msg)
|
||||
#define PME_SWAP (1ULL << 62)
|
||||
#define PME_FILE (1ULL << 61)
|
||||
|
||||
static inline int should_dump_page(struct vma_entry *vmae, u64 pme)
|
||||
static inline int should_dump_page(VmaEntry *vmae, u64 pme)
|
||||
{
|
||||
return (pme & (PME_PRESENT | PME_SWAP)) &&
|
||||
/*
|
||||
|
@ -48,6 +48,7 @@ PROTO_FILES += ipc-shm.proto
|
||||
PROTO_FILES += ipc-msg.proto
|
||||
PROTO_FILES += ipc-sem.proto
|
||||
PROTO_FILES += creds.proto
|
||||
PROTO_FILES += vma.proto
|
||||
|
||||
HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
|
||||
SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
|
||||
|
10
protobuf/vma.proto
Normal file
10
protobuf/vma.proto
Normal file
@ -0,0 +1,10 @@
|
||||
message vma_entry {
|
||||
required uint64 start = 1;
|
||||
required uint64 end = 2;
|
||||
required uint64 pgoff = 3;
|
||||
required uint64 shmid = 4;
|
||||
required uint32 prot = 5;
|
||||
required uint32 flags = 6;
|
||||
required uint32 status = 7;
|
||||
required sint64 fd = 8;
|
||||
}
|
@ -244,7 +244,7 @@ static long restore_self_exe_late(struct task_restore_core_args *args)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u64 restore_mapping(const struct vma_entry *vma_entry)
|
||||
static u64 restore_mapping(const VmaEntry *vma_entry)
|
||||
{
|
||||
int prot = vma_entry->prot;
|
||||
int flags = vma_entry->flags | MAP_FIXED;
|
||||
@ -295,7 +295,7 @@ long __export_restore_task(struct task_restore_core_args *args)
|
||||
{
|
||||
long ret = -1;
|
||||
struct core_entry *core_entry;
|
||||
struct vma_entry *vma_entry;
|
||||
VmaEntry *vma_entry;
|
||||
u64 va;
|
||||
|
||||
struct rt_sigframe *rt_sigframe;
|
||||
|
24
shmem.c
24
shmem.c
@ -7,6 +7,8 @@
|
||||
#include "crtools.h"
|
||||
#include "restorer.h"
|
||||
|
||||
#include "protobuf.h"
|
||||
|
||||
struct shmems *rst_shmems;
|
||||
|
||||
void show_saved_shmems(void)
|
||||
@ -22,7 +24,7 @@ void show_saved_shmems(void)
|
||||
rst_shmems->entries[i].pid);
|
||||
}
|
||||
|
||||
static int collect_shmem(int pid, struct vma_entry *vi)
|
||||
static int collect_shmem(int pid, VmaEntry *vi)
|
||||
{
|
||||
int nr_shmems = rst_shmems->nr_shmems;
|
||||
unsigned long size = vi->pgoff + vi->end - vi->start;
|
||||
@ -77,7 +79,7 @@ static int collect_shmem(int pid, struct vma_entry *vi)
|
||||
int prepare_shmem_pid(int pid)
|
||||
{
|
||||
int fd, ret = -1;
|
||||
struct vma_entry vi;
|
||||
VmaEntry *vi;
|
||||
|
||||
fd = open_image_ro(CR_FD_VMAS, pid);
|
||||
if (fd < 0) {
|
||||
@ -88,19 +90,21 @@ int prepare_shmem_pid(int pid)
|
||||
}
|
||||
|
||||
while (1) {
|
||||
ret = read_img_eof(fd, &vi);
|
||||
ret = pb_read_eof(fd, &vi, vma_entry);
|
||||
if (ret <= 0)
|
||||
break;
|
||||
|
||||
pr_info("vma 0x%lx 0x%lx\n", vi.start, vi.end);
|
||||
pr_info("vma 0x%lx 0x%lx\n", vi->start, vi->end);
|
||||
|
||||
if (!vma_entry_is(&vi, VMA_ANON_SHARED))
|
||||
if (!vma_entry_is(vi, VMA_ANON_SHARED) ||
|
||||
vma_entry_is(vi, VMA_AREA_SYSVIPC)) {
|
||||
vma_entry__free_unpacked(vi, NULL);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (vma_entry_is(&vi, VMA_AREA_SYSVIPC))
|
||||
continue;
|
||||
ret = collect_shmem(pid, vi);
|
||||
vma_entry__free_unpacked(vi, NULL);
|
||||
|
||||
ret = collect_shmem(pid, &vi);
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
@ -156,7 +160,7 @@ static int restore_shmem_content(void *addr, struct shmem_info *si)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int get_shmem_fd(int pid, struct vma_entry *vi)
|
||||
int get_shmem_fd(int pid, VmaEntry *vi)
|
||||
{
|
||||
struct shmem_info *si;
|
||||
void *addr;
|
||||
@ -241,7 +245,7 @@ static struct shmem_info_dump* shmem_find(unsigned long shmid)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int add_shmem_area(pid_t pid, struct vma_entry *vma)
|
||||
int add_shmem_area(pid_t pid, VmaEntry *vma)
|
||||
{
|
||||
struct shmem_info_dump *si;
|
||||
unsigned long size = vma->pgoff + (vma->end - vma->start);
|
||||
|
Loading…
x
Reference in New Issue
Block a user