mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-22 09:58:09 +00:00
protobuf: Start switching our image entries to Google's protobuf
A short story -- there were a long conversation on which format should be used to keep checkpointed data on disk image. We ended up in using Google's Protocol Buffers (see https://developers.google.com/protocol-buffers/ for detailed description). Thus image entries should be convered to PB. This patch converts fdinfo_entry to PB "message fdinfo_entry". Build note: one should have protobuf and protobuf-c installed to be able to build crtools. - http://code.google.com/p/protobuf/ - http://code.google.com/p/protobuf-c/ Inspired-by: Pavel Emelianov <xemul@parallels.com> Inspired-by: Kinsbursky Stanislav <skinsbursky@openvz.org> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
c75b4b70fc
commit
a1fe3caf04
14
Makefile
14
Makefile
@ -3,7 +3,7 @@ include Makefile.inc
|
||||
CFLAGS += -I./include
|
||||
CFLAGS += -O0 -ggdb3
|
||||
|
||||
LIBS += -lrt -lpthread
|
||||
LIBS += -lrt -lpthread -lprotobuf-c
|
||||
|
||||
DEFINES += -D_FILE_OFFSET_BITS=64
|
||||
DEFINES += -D_GNU_SOURCE
|
||||
@ -61,6 +61,8 @@ OBJS += inotify.o
|
||||
OBJS += pstree.o
|
||||
OBJS += protobuf.o
|
||||
|
||||
PROTOBUF-LIB := protobuf/protobuf-lib.o
|
||||
|
||||
DEPS := $(patsubst %.o,%.d,$(OBJS))
|
||||
|
||||
MAKEFLAGS += --no-print-directory
|
||||
@ -69,13 +71,16 @@ include Makefile.syscall
|
||||
include Makefile.pie
|
||||
|
||||
.PHONY: all test-legacy zdtm test rebuild clean distclean tags cscope \
|
||||
docs help pie
|
||||
docs help pie protobuf
|
||||
|
||||
all: pie
|
||||
all: protobuf pie
|
||||
$(Q) $(MAKE) $(PROGRAM)
|
||||
|
||||
pie: $(PIE-GEN)
|
||||
|
||||
protobuf:
|
||||
$(Q) $(MAKE) -C protobuf/ all
|
||||
|
||||
%.o: %.c
|
||||
$(E) " CC " $@
|
||||
$(Q) $(CC) -c $(CFLAGS) $< -o $@
|
||||
@ -92,7 +97,7 @@ pie: $(PIE-GEN)
|
||||
$(E) " DEP " $@
|
||||
$(Q) $(CC) -M -MT $@ -MT $(patsubst %.d,%.o,$@) $(CFLAGS) $< -o $@
|
||||
|
||||
$(PROGRAM): $(OBJS) $(SYS-OBJ)
|
||||
$(PROGRAM): $(OBJS) $(SYS-OBJ) $(PROTOBUF-LIB)
|
||||
$(E) " LINK " $@
|
||||
$(Q) $(CC) $(CFLAGS) $^ $(LIBS) -o $@
|
||||
|
||||
@ -121,6 +126,7 @@ clean: cleanpie cleansyscall
|
||||
$(Q) $(RM) -f ./*.bin
|
||||
$(Q) $(RM) -f ./$(PROGRAM)
|
||||
$(Q) $(RM) -rf ./test/dump/
|
||||
$(Q) $(MAKE) -C protobuf/ clean
|
||||
$(Q) $(MAKE) -C test/legacy clean
|
||||
$(Q) $(MAKE) -C test/zdtm cleandep
|
||||
$(Q) $(MAKE) -C test/zdtm clean
|
||||
|
14
cr-dump.c
14
cr-dump.c
@ -45,6 +45,9 @@
|
||||
#include "inotify.h"
|
||||
#include "pstree.h"
|
||||
|
||||
#include "protobuf.h"
|
||||
#include "protobuf/fdinfo.pb-c.h"
|
||||
|
||||
#ifndef CONFIG_X86_64
|
||||
# error No x86-32 support yet
|
||||
#endif
|
||||
@ -130,7 +133,7 @@ u32 make_gen_id(const struct fd_parms *p)
|
||||
int do_dump_gen_file(struct fd_parms *p, int lfd,
|
||||
const struct fdtype_ops *ops, const struct cr_fdset *cr_fdset)
|
||||
{
|
||||
struct fdinfo_entry e;
|
||||
FdinfoEntry e = FDINFO_ENTRY__INIT;
|
||||
int ret = -1;
|
||||
|
||||
e.type = ops->type;
|
||||
@ -143,17 +146,12 @@ int do_dump_gen_file(struct fd_parms *p, int lfd,
|
||||
ret = ops->dump(lfd, e.id, p);
|
||||
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
return -1;
|
||||
|
||||
pr_info("fdinfo: type: 0x%2x flags: 0x%4x pos: 0x%8lx fd: %d\n",
|
||||
ops->type, p->flags, p->pos, p->fd);
|
||||
|
||||
if (write_img(fdset_fd(cr_fdset, CR_FD_FDINFO), &e))
|
||||
goto err;
|
||||
|
||||
ret = 0;
|
||||
err:
|
||||
return ret;
|
||||
return pb_write(fdset_fd(cr_fdset, CR_FD_FDINFO), &e, fdinfo_entry);
|
||||
}
|
||||
|
||||
static int dump_task_exe_link(pid_t pid, struct mm_entry *mm)
|
||||
|
18
cr-show.c
18
cr-show.c
@ -24,6 +24,9 @@
|
||||
#include "ipc_ns.h"
|
||||
#include "pstree.h"
|
||||
|
||||
#include "protobuf.h"
|
||||
#include "protobuf/fdinfo.pb-c.h"
|
||||
|
||||
#define DEF_PAGES_PER_LINE 6
|
||||
|
||||
#ifndef CONFIG_X86_64
|
||||
@ -77,21 +80,16 @@ static char *fdtype2s(u8 type)
|
||||
|
||||
void show_files(int fd_files, struct cr_options *o)
|
||||
{
|
||||
struct fdinfo_entry e;
|
||||
|
||||
pr_img_head(CR_FD_FDINFO);
|
||||
|
||||
while (1) {
|
||||
int ret;
|
||||
|
||||
ret = read_img_eof(fd_files, &e);
|
||||
FdinfoEntry *e;
|
||||
int ret = pb_read_eof(fd_files, &e, fdinfo_entry);
|
||||
if (ret <= 0)
|
||||
goto out;
|
||||
|
||||
pr_msg("type: %-5s fd: %-5d id: %#x flags %#x",
|
||||
fdtype2s(e.type), e.fd, e.id, e.flags);
|
||||
|
||||
pr_msg("\n");
|
||||
pr_msg("type: %-5s fd: %-5d id: %#x flags %#x\n",
|
||||
fdtype2s(e->type), e->fd, e->id, e->flags);
|
||||
fdinfo_entry__free_unpacked(e, NULL);
|
||||
}
|
||||
|
||||
out:
|
||||
|
@ -30,7 +30,7 @@ u32 fd_id_generate_special(void)
|
||||
return fd_tree.subid++;
|
||||
}
|
||||
|
||||
int fd_id_generate(pid_t pid, struct fdinfo_entry *fe)
|
||||
int fd_id_generate(pid_t pid, FdinfoEntry *fe)
|
||||
{
|
||||
u32 id;
|
||||
struct kid_elem e;
|
||||
|
24
files.c
24
files.c
@ -24,6 +24,8 @@
|
||||
#include "sockets.h"
|
||||
#include "pstree.h"
|
||||
|
||||
#include "protobuf.h"
|
||||
|
||||
static struct fdinfo_list_entry *fdinfo_list;
|
||||
static int nr_fdinfo_list;
|
||||
|
||||
@ -71,7 +73,7 @@ struct file_desc *find_file_desc_raw(int type, u32 id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline struct file_desc *find_file_desc(struct fdinfo_entry *fe)
|
||||
static inline struct file_desc *find_file_desc(FdinfoEntry *fe)
|
||||
{
|
||||
return find_file_desc_raw(fe->type, fe->id);
|
||||
}
|
||||
@ -152,7 +154,7 @@ int rst_file_params(int fd, fown_t *fown, int flags)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int collect_fd(int pid, struct fdinfo_entry *e, struct rst_info *rst_info)
|
||||
static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
|
||||
{
|
||||
struct fdinfo_list_entry *l, *le = &fdinfo_list[nr_fdinfo_list];
|
||||
struct file_desc *fdesc;
|
||||
@ -206,20 +208,18 @@ int prepare_fd_pid(int pid, struct rst_info *rst_info)
|
||||
}
|
||||
|
||||
while (1) {
|
||||
struct fdinfo_entry *e = xmalloc(sizeof(*e));
|
||||
if (!e) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
FdinfoEntry *e;
|
||||
|
||||
ret = read_img_eof(fdinfo_fd, e);
|
||||
ret = pb_read_eof(fdinfo_fd, &e, fdinfo_entry);
|
||||
if (ret <= 0)
|
||||
break;
|
||||
|
||||
ret = collect_fd(pid, e, rst_info);
|
||||
if (ret < 0)
|
||||
if (ret < 0) {
|
||||
fdinfo_entry__free_unpacked(e, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
close(fdinfo_fd);
|
||||
return ret;
|
||||
@ -255,7 +255,7 @@ static void transport_name_gen(struct sockaddr_un *addr, int *len,
|
||||
*addr->sun_path = '\0';
|
||||
}
|
||||
|
||||
static int should_open_transport(struct fdinfo_entry *fe, struct file_desc *fd)
|
||||
static int should_open_transport(FdinfoEntry *fe, struct file_desc *fd)
|
||||
{
|
||||
if (fd->ops->want_transport)
|
||||
return fd->ops->want_transport(fe, fd);
|
||||
@ -326,7 +326,7 @@ int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle, int tsk)
|
||||
return send_fd(tsk, &saddr, len, fd);
|
||||
}
|
||||
|
||||
static int open_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d)
|
||||
static int open_fd(int pid, FdinfoEntry *fe, struct file_desc *d)
|
||||
{
|
||||
int tmp;
|
||||
int sock;
|
||||
@ -383,7 +383,7 @@ static int open_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int receive_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d)
|
||||
static int receive_fd(int pid, FdinfoEntry *fe, struct file_desc *d)
|
||||
{
|
||||
int tmp;
|
||||
struct fdinfo_list_entry *fle;
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "types.h"
|
||||
#include "rbtree.h"
|
||||
|
||||
#include "../protobuf/fdinfo.pb-c.h"
|
||||
|
||||
#define FD_PID_INVALID (-2U)
|
||||
#define FD_DESC_INVALID (-3U)
|
||||
|
||||
@ -12,7 +14,7 @@
|
||||
(((u32)(dev) ^ (u32)(ino) ^ (u32)(pos)))
|
||||
|
||||
struct fdinfo_entry;
|
||||
extern int fd_id_generate(pid_t pid, struct fdinfo_entry *fe);
|
||||
extern int fd_id_generate(pid_t pid, FdinfoEntry *fe);
|
||||
extern u32 fd_id_generate_special(void);
|
||||
extern void fd_id_show_tree(void);
|
||||
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include "list.h"
|
||||
#include "image.h"
|
||||
|
||||
#include "../protobuf/fdinfo.pb-c.h"
|
||||
|
||||
struct pstree_item;
|
||||
struct file_desc;
|
||||
struct cr_fdset;
|
||||
@ -38,13 +40,13 @@ struct fdinfo_list_entry {
|
||||
struct list_head ps_list;
|
||||
int pid;
|
||||
futex_t real_pid;
|
||||
struct fdinfo_entry *fe;
|
||||
FdinfoEntry *fe;
|
||||
};
|
||||
|
||||
struct file_desc_ops {
|
||||
unsigned int type;
|
||||
int (*open)(struct file_desc *d);
|
||||
int (*want_transport)(struct fdinfo_entry *fe, struct file_desc *d);
|
||||
int (*want_transport)(FdinfoEntry *fe, struct file_desc *d);
|
||||
};
|
||||
|
||||
struct file_desc {
|
||||
|
@ -131,13 +131,6 @@ struct inotify_file_entry {
|
||||
fown_t fown;
|
||||
} __packed;
|
||||
|
||||
struct fdinfo_entry {
|
||||
u32 fd;
|
||||
u8 type;
|
||||
u8 flags;
|
||||
u32 id;
|
||||
} __packed;
|
||||
|
||||
struct fs_entry {
|
||||
u32 cwd_id;
|
||||
u32 root_id;
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
struct fdinfo_list_entry;
|
||||
struct sk_opts_entry;
|
||||
struct fdinfo_entry;
|
||||
struct cr_options;
|
||||
struct file_desc;
|
||||
struct fd_parms;
|
||||
|
2
pipes.c
2
pipes.c
@ -294,7 +294,7 @@ static int open_pipe(struct file_desc *d)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static int want_transport(struct fdinfo_entry *fe, struct file_desc *d)
|
||||
static int want_transport(FdinfoEntry *fe, struct file_desc *d)
|
||||
{
|
||||
struct pipe_info *pi;
|
||||
|
||||
|
51
protobuf/Makefile
Normal file
51
protobuf/Makefile
Normal file
@ -0,0 +1,51 @@
|
||||
-include ../Makefile.inc
|
||||
|
||||
CFLAGS += -I./include
|
||||
CFLAGS += -O0 -ggdb3
|
||||
|
||||
DEFINES += -D_FILE_OFFSET_BITS=64
|
||||
DEFINES += -D_GNU_SOURCE
|
||||
|
||||
ifneq ($(WERROR),0)
|
||||
WARNINGS += -Werror
|
||||
endif
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
DEFINES += -DCR_DEBUG
|
||||
endif
|
||||
|
||||
WARNINGS += -Wall
|
||||
CFLAGS += $(WARNINGS) $(DEFINES)
|
||||
|
||||
LIBRARY := protobuf-lib.o
|
||||
|
||||
PROTO_FILES += fdinfo.proto
|
||||
|
||||
HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
|
||||
SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
|
||||
OBJS := $(patsubst %.c,%.o,$(SRCS))
|
||||
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
%.pb-c.c: %.proto
|
||||
$(E) " PROTOBUF "$@
|
||||
$(Q) protoc-c --c_out=./ $<
|
||||
|
||||
%.o: %.c
|
||||
$(E) " CC "$@
|
||||
$(Q) $(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
.SECONDARY:
|
||||
|
||||
$(LIBRARY): $(OBJS)
|
||||
$(E) " LINK "$@
|
||||
$(Q) ld -r -o $@ $(OBJS)
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(LIBRARY)
|
||||
|
||||
clean:
|
||||
$(E) " CLEAN PROTOBUF"
|
||||
$(Q) rm -f $(SRCS) $(HDRS) $(OBJS) $(LIBRARY)
|
||||
|
6
protobuf/fdinfo.proto
Normal file
6
protobuf/fdinfo.proto
Normal file
@ -0,0 +1,6 @@
|
||||
message fdinfo_entry {
|
||||
required uint32 id = 1;
|
||||
required uint32 flags = 2;
|
||||
required uint32 type = 3;
|
||||
required uint32 fd = 4;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user