Commit 4806e139 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

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: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent ffd40996
...@@ -391,7 +391,7 @@ static int dump_task_fs(pid_t pid, struct cr_fdset *fdset) ...@@ -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); 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) const struct cr_fdset *fdset)
{ {
struct fd_parms p = FD_PARMS_INIT; 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, ...@@ -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); fd = fdset_fd(cr_fdset, CR_FD_VMAS);
list_for_each_entry(vma_area, vma_area_list, list) { 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); pr_info_vma(vma_area);
...@@ -439,7 +439,7 @@ static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list, ...@@ -439,7 +439,7 @@ static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list,
ret = 0; ret = 0;
if (!ret) if (!ret)
ret = write_img(fd, vma); ret = pb_write(fd, vma, vma_entry);
if (ret) if (ret)
goto err; goto err;
} }
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "protobuf.h" #include "protobuf.h"
#include "protobuf/sa.pb-c.h" #include "protobuf/sa.pb-c.h"
#include "protobuf/itimer.pb-c.h" #include "protobuf/itimer.pb-c.h"
#include "protobuf/vma.pb-c.h"
static struct pstree_item *me; static struct pstree_item *me;
...@@ -141,6 +142,7 @@ static int read_and_open_vmas(int pid, struct list_head *vmas, int *nr_vmas) ...@@ -141,6 +142,7 @@ static int read_and_open_vmas(int pid, struct list_head *vmas, int *nr_vmas)
*nr_vmas = 0; *nr_vmas = 0;
while (1) { while (1) {
struct vma_area *vma; struct vma_area *vma;
VmaEntry *e;
ret = -1; ret = -1;
vma = alloc_vma_area(); vma = alloc_vma_area();
...@@ -149,10 +151,13 @@ static int read_and_open_vmas(int pid, struct list_head *vmas, int *nr_vmas) ...@@ -149,10 +151,13 @@ static int read_and_open_vmas(int pid, struct list_head *vmas, int *nr_vmas)
(*nr_vmas)++; (*nr_vmas)++;
list_add_tail(&vma->list, 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) if (ret <= 0)
break; break;
vma->vma = *e;
vma_entry__free_unpacked(e, NULL);
if (!(vma_entry_is(&vma->vma, VMA_AREA_REGULAR))) if (!(vma_entry_is(&vma->vma, VMA_AREA_REGULAR)))
continue; continue;
...@@ -1055,9 +1060,9 @@ static int prepare_creds(int pid, struct task_restore_core_args *args) ...@@ -1055,9 +1060,9 @@ static int prepare_creds(int pid, struct task_restore_core_args *args)
return 0; 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; struct vma_area *vma_area;
ret = vma = mmap(addr, len, PROT_READ | PROT_WRITE, 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) ...@@ -1146,8 +1151,8 @@ static int sigreturn_restore(pid_t pid, struct list_head *tgt_vmas, int nr_vmas)
if (ret < 0) if (ret < 0)
goto err; goto err;
self_vmas_len = round_up((ret + 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(struct vma_entry), PAGE_SIZE); vmas_len = round_up((nr_vmas + 1) * sizeof(VmaEntry), PAGE_SIZE);
/* pr_info_vma_list(&self_vma_list); */ /* pr_info_vma_list(&self_vma_list); */
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "protobuf/sa.pb-c.h" #include "protobuf/sa.pb-c.h"
#include "protobuf/itimer.pb-c.h" #include "protobuf/itimer.pb-c.h"
#include "protobuf/mm.pb-c.h" #include "protobuf/mm.pb-c.h"
#include "protobuf/vma.pb-c.h"
#include "protobuf/creds.pb-c.h" #include "protobuf/creds.pb-c.h"
#define DEF_PAGES_PER_LINE 6 #define DEF_PAGES_PER_LINE 6
...@@ -166,24 +167,7 @@ void show_fs(int fd_fs, struct cr_options *o) ...@@ -166,24 +167,7 @@ void show_fs(int fd_fs, struct cr_options *o)
void show_vmas(int fd_vma, struct cr_options *o) void show_vmas(int fd_vma, struct cr_options *o)
{ {
struct vma_area vma_area = {}; pb_show_plain(fd_vma, vma_entry);
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);
} }
static int nice_width_for(unsigned long addr) static int nice_width_for(unsigned long addr)
......
...@@ -531,7 +531,7 @@ err: ...@@ -531,7 +531,7 @@ err:
return ret; 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); return open_reg_by_id(vma_entry->shmid);
} }
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "util.h" #include "util.h"
#include "image.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 (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) #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); ...@@ -168,7 +170,7 @@ void free_mappings(struct list_head *vma_area_list);
struct vma_area { struct vma_area {
struct list_head list; struct list_head list;
struct vma_entry vma; VmaEntry vma;
int vm_file_fd; int vm_file_fd;
}; };
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "../protobuf/fdinfo.pb-c.h" #include "../protobuf/fdinfo.pb-c.h"
#include "../protobuf/fown.pb-c.h" #include "../protobuf/fown.pb-c.h"
#include "../protobuf/vma.pb-c.h"
struct pstree_item; struct pstree_item;
struct file_desc; struct file_desc;
...@@ -87,7 +88,7 @@ extern void show_saved_files(void); ...@@ -87,7 +88,7 @@ extern void show_saved_files(void);
extern int prepare_fds(struct pstree_item *me); extern int prepare_fds(struct pstree_item *me);
extern int prepare_fd_pid(int pid, struct rst_info *rst_info); extern int prepare_fd_pid(int pid, struct rst_info *rst_info);
extern int prepare_shared_fdinfo(void); 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 prepare_fs(int pid);
extern int set_fd_flags(int fd, int flags); extern int set_fd_flags(int fd, int flags);
......
...@@ -55,17 +55,6 @@ ...@@ -55,17 +55,6 @@
#define USK_EXTERN (1 << 0) #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_NONE (0 << 0)
#define VMA_AREA_REGULAR (1 << 0) /* Dumpable area */ #define VMA_AREA_REGULAR (1 << 0) /* Dumpable area */
#define VMA_AREA_STACK (1 << 1) #define VMA_AREA_STACK (1 << 1)
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "util-net.h" #include "util-net.h"
#include "../protobuf/vma.pb-c.h"
#define __head __used __section(.head.text) #define __head __used __section(.head.text)
enum { enum {
...@@ -42,7 +44,7 @@ struct parasite_init_args { ...@@ -42,7 +44,7 @@ struct parasite_init_args {
}; };
struct parasite_dump_pages_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_dumped; /* how many pages are dumped */
unsigned long nrpages_skipped; unsigned long nrpages_skipped;
unsigned long nrpages_total; unsigned long nrpages_total;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "crtools.h" #include "crtools.h"
#include "../protobuf/mm.pb-c.h" #include "../protobuf/mm.pb-c.h"
#include "../protobuf/vma.pb-c.h"
#include "../protobuf/creds.pb-c.h" #include "../protobuf/creds.pb-c.h"
#ifndef CONFIG_X86_64 #ifndef CONFIG_X86_64
...@@ -80,8 +81,8 @@ struct task_restore_core_args { ...@@ -80,8 +81,8 @@ struct task_restore_core_args {
struct thread_restore_args *thread_args; /* array of thread arguments */ struct thread_restore_args *thread_args; /* array of thread arguments */
struct shmems *shmems; struct shmems *shmems;
struct task_entries *task_entries; struct task_entries *task_entries;
struct vma_entry *self_vmas; VmaEntry *self_vmas;
struct vma_entry *tgt_vmas; VmaEntry *tgt_vmas;
rt_sigaction_t sigchld_act; rt_sigaction_t sigchld_act;
struct itimerval itimers[3]; struct itimerval itimers[3];
......
#ifndef __CR_SHMEM_H__ #ifndef __CR_SHMEM_H__
#define __CR_SHMEM_H__ #define __CR_SHMEM_H__
#include "../protobuf/vma.pb-c.h"
int prepare_shmem_pid(int pid); int prepare_shmem_pid(int pid);
int prepare_shmem_restore(void); int prepare_shmem_restore(void);
void show_saved_shmems(void); void show_saved_shmems(void);
struct vma_entry; int get_shmem_fd(int pid, VmaEntry *vi);
int get_shmem_fd(int pid, struct vma_entry *vi);
struct shmems; struct shmems;
extern struct shmems *rst_shmems; extern struct shmems *rst_shmems;
int cr_dump_shmem(void); 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); int init_shmem_dump(void);
void fini_shmem_dump(void); void fini_shmem_dump(void);
#endif #endif
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "types.h" #include "types.h"
#include "log.h" #include "log.h"
#include "../protobuf/vma.pb-c.h"
#define PREF_SHIFT_OP(pref, op, size) ((size) op (pref ##BYTES_SHIFT)) #define PREF_SHIFT_OP(pref, op, size) ((size) op (pref ##BYTES_SHIFT))
#define KBYTES_SHIFT 10 #define KBYTES_SHIFT 10
#define MBYTES_SHIFT 20 #define MBYTES_SHIFT 20
...@@ -155,6 +157,7 @@ extern void pr_vma(unsigned int loglevel, const struct vma_area *vma_area); ...@@ -155,6 +157,7 @@ extern void pr_vma(unsigned int loglevel, const struct vma_area *vma_area);
({ \ ({ \
struct vma_area *p__ = xzalloc(sizeof(*p__)); \ struct vma_area *p__ = xzalloc(sizeof(*p__)); \
if (p__) { \ if (p__) { \
vma_entry__init(&p__->vma); \
p__->vm_file_fd = -1; \ p__->vm_file_fd = -1; \
p__->vma.fd = -1; \ p__->vma.fd = -1; \
} \ } \
......
...@@ -102,7 +102,7 @@ static void sys_write_msg(const char *msg) ...@@ -102,7 +102,7 @@ static void sys_write_msg(const char *msg)
#define PME_SWAP (1ULL << 62) #define PME_SWAP (1ULL << 62)
#define PME_FILE (1ULL << 61) #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)) && return (pme & (PME_PRESENT | PME_SWAP)) &&
/* /*
......
...@@ -48,6 +48,7 @@ PROTO_FILES += ipc-shm.proto ...@@ -48,6 +48,7 @@ PROTO_FILES += ipc-shm.proto
PROTO_FILES += ipc-msg.proto PROTO_FILES += ipc-msg.proto
PROTO_FILES += ipc-sem.proto PROTO_FILES += ipc-sem.proto
PROTO_FILES += creds.proto PROTO_FILES += creds.proto
PROTO_FILES += vma.proto
HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES)) HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES)) SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
......
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) ...@@ -244,7 +244,7 @@ static long restore_self_exe_late(struct task_restore_core_args *args)
return 0; 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 prot = vma_entry->prot;
int flags = vma_entry->flags | MAP_FIXED; int flags = vma_entry->flags | MAP_FIXED;
...@@ -295,7 +295,7 @@ long __export_restore_task(struct task_restore_core_args *args) ...@@ -295,7 +295,7 @@ long __export_restore_task(struct task_restore_core_args *args)
{ {
long ret = -1; long ret = -1;
struct core_entry *core_entry; struct core_entry *core_entry;
struct vma_entry *vma_entry; VmaEntry *vma_entry;
u64 va; u64 va;
struct rt_sigframe *rt_sigframe; struct rt_sigframe *rt_sigframe;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "crtools.h" #include "crtools.h"
#include "restorer.h" #include "restorer.h"
#include "protobuf.h"
struct shmems *rst_shmems; struct shmems *rst_shmems;
void show_saved_shmems(void) void show_saved_shmems(void)
...@@ -22,7 +24,7 @@ void show_saved_shmems(void) ...@@ -22,7 +24,7 @@ void show_saved_shmems(void)
rst_shmems->entries[i].pid); 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; int nr_shmems = rst_shmems->nr_shmems;
unsigned long size = vi->pgoff + vi->end - vi->start; unsigned long size = vi->pgoff + vi->end - vi->start;
...@@ -77,7 +79,7 @@ static int collect_shmem(int pid, struct vma_entry *vi) ...@@ -77,7 +79,7 @@ static int collect_shmem(int pid, struct vma_entry *vi)
int prepare_shmem_pid(int pid) int prepare_shmem_pid(int pid)
{ {
int fd, ret = -1; int fd, ret = -1;
struct vma_entry vi; VmaEntry *vi;
fd = open_image_ro(CR_FD_VMAS, pid); fd = open_image_ro(CR_FD_VMAS, pid);
if (fd < 0) { if (fd < 0) {
...@@ -88,19 +90,21 @@ int prepare_shmem_pid(int pid) ...@@ -88,19 +90,21 @@ int prepare_shmem_pid(int pid)
} }
while (1) { while (1) {
ret = read_img_eof(fd, &vi); ret = pb_read_eof(fd, &vi, vma_entry);
if (ret <= 0) if (ret <= 0)
break; 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; continue;
}
if (vma_entry_is(&vi, VMA_AREA_SYSVIPC)) ret = collect_shmem(pid, vi);
continue; vma_entry__free_unpacked(vi, NULL);
ret = collect_shmem(pid, &vi);
if (ret) if (ret)
break; break;
} }
...@@ -156,7 +160,7 @@ static int restore_shmem_content(void *addr, struct shmem_info *si) ...@@ -156,7 +160,7 @@ static int restore_shmem_content(void *addr, struct shmem_info *si)
return ret; return ret;
} }
int get_shmem_fd(int pid, struct vma_entry *vi) int get_shmem_fd(int pid, VmaEntry *vi)
{ {
struct shmem_info *si; struct shmem_info *si;
void *addr; void *addr;
...@@ -241,7 +245,7 @@ static struct shmem_info_dump* shmem_find(unsigned long shmid) ...@@ -241,7 +245,7 @@ static struct shmem_info_dump* shmem_find(unsigned long shmid)
return NULL; 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; struct shmem_info_dump *si;
unsigned long size = vma->pgoff + (vma->end - vma->start); unsigned long size = vma->pgoff + (vma->end - vma->start);
......
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