Commit a1fe3caf authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

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: 's avatarPavel Emelianov <xemul@parallels.com>
Inspired-by: 's avatarKinsbursky Stanislav <skinsbursky@openvz.org>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent c75b4b70
...@@ -3,7 +3,7 @@ include Makefile.inc ...@@ -3,7 +3,7 @@ include Makefile.inc
CFLAGS += -I./include CFLAGS += -I./include
CFLAGS += -O0 -ggdb3 CFLAGS += -O0 -ggdb3
LIBS += -lrt -lpthread LIBS += -lrt -lpthread -lprotobuf-c
DEFINES += -D_FILE_OFFSET_BITS=64 DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_GNU_SOURCE DEFINES += -D_GNU_SOURCE
...@@ -61,6 +61,8 @@ OBJS += inotify.o ...@@ -61,6 +61,8 @@ OBJS += inotify.o
OBJS += pstree.o OBJS += pstree.o
OBJS += protobuf.o OBJS += protobuf.o
PROTOBUF-LIB := protobuf/protobuf-lib.o
DEPS := $(patsubst %.o,%.d,$(OBJS)) DEPS := $(patsubst %.o,%.d,$(OBJS))
MAKEFLAGS += --no-print-directory MAKEFLAGS += --no-print-directory
...@@ -69,13 +71,16 @@ include Makefile.syscall ...@@ -69,13 +71,16 @@ include Makefile.syscall
include Makefile.pie include Makefile.pie
.PHONY: all test-legacy zdtm test rebuild clean distclean tags cscope \ .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) $(Q) $(MAKE) $(PROGRAM)
pie: $(PIE-GEN) pie: $(PIE-GEN)
protobuf:
$(Q) $(MAKE) -C protobuf/ all
%.o: %.c %.o: %.c
$(E) " CC " $@ $(E) " CC " $@
$(Q) $(CC) -c $(CFLAGS) $< -o $@ $(Q) $(CC) -c $(CFLAGS) $< -o $@
...@@ -92,7 +97,7 @@ pie: $(PIE-GEN) ...@@ -92,7 +97,7 @@ pie: $(PIE-GEN)
$(E) " DEP " $@ $(E) " DEP " $@
$(Q) $(CC) -M -MT $@ -MT $(patsubst %.d,%.o,$@) $(CFLAGS) $< -o $@ $(Q) $(CC) -M -MT $@ -MT $(patsubst %.d,%.o,$@) $(CFLAGS) $< -o $@
$(PROGRAM): $(OBJS) $(SYS-OBJ) $(PROGRAM): $(OBJS) $(SYS-OBJ) $(PROTOBUF-LIB)
$(E) " LINK " $@ $(E) " LINK " $@
$(Q) $(CC) $(CFLAGS) $^ $(LIBS) -o $@ $(Q) $(CC) $(CFLAGS) $^ $(LIBS) -o $@
...@@ -121,6 +126,7 @@ clean: cleanpie cleansyscall ...@@ -121,6 +126,7 @@ clean: cleanpie cleansyscall
$(Q) $(RM) -f ./*.bin $(Q) $(RM) -f ./*.bin
$(Q) $(RM) -f ./$(PROGRAM) $(Q) $(RM) -f ./$(PROGRAM)
$(Q) $(RM) -rf ./test/dump/ $(Q) $(RM) -rf ./test/dump/
$(Q) $(MAKE) -C protobuf/ clean
$(Q) $(MAKE) -C test/legacy clean $(Q) $(MAKE) -C test/legacy clean
$(Q) $(MAKE) -C test/zdtm cleandep $(Q) $(MAKE) -C test/zdtm cleandep
$(Q) $(MAKE) -C test/zdtm clean $(Q) $(MAKE) -C test/zdtm clean
......
...@@ -45,6 +45,9 @@ ...@@ -45,6 +45,9 @@
#include "inotify.h" #include "inotify.h"
#include "pstree.h" #include "pstree.h"
#include "protobuf.h"
#include "protobuf/fdinfo.pb-c.h"
#ifndef CONFIG_X86_64 #ifndef CONFIG_X86_64
# error No x86-32 support yet # error No x86-32 support yet
#endif #endif
...@@ -130,7 +133,7 @@ u32 make_gen_id(const struct fd_parms *p) ...@@ -130,7 +133,7 @@ u32 make_gen_id(const struct fd_parms *p)
int do_dump_gen_file(struct fd_parms *p, int lfd, int do_dump_gen_file(struct fd_parms *p, int lfd,
const struct fdtype_ops *ops, const struct cr_fdset *cr_fdset) const struct fdtype_ops *ops, const struct cr_fdset *cr_fdset)
{ {
struct fdinfo_entry e; FdinfoEntry e = FDINFO_ENTRY__INIT;
int ret = -1; int ret = -1;
e.type = ops->type; e.type = ops->type;
...@@ -143,17 +146,12 @@ int do_dump_gen_file(struct fd_parms *p, int lfd, ...@@ -143,17 +146,12 @@ int do_dump_gen_file(struct fd_parms *p, int lfd,
ret = ops->dump(lfd, e.id, p); ret = ops->dump(lfd, e.id, p);
if (ret < 0) if (ret < 0)
goto err; return -1;
pr_info("fdinfo: type: 0x%2x flags: 0x%4x pos: 0x%8lx fd: %d\n", pr_info("fdinfo: type: 0x%2x flags: 0x%4x pos: 0x%8lx fd: %d\n",
ops->type, p->flags, p->pos, p->fd); ops->type, p->flags, p->pos, p->fd);
if (write_img(fdset_fd(cr_fdset, CR_FD_FDINFO), &e)) return pb_write(fdset_fd(cr_fdset, CR_FD_FDINFO), &e, fdinfo_entry);
goto err;
ret = 0;
err:
return ret;
} }
static int dump_task_exe_link(pid_t pid, struct mm_entry *mm) static int dump_task_exe_link(pid_t pid, struct mm_entry *mm)
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
#include "ipc_ns.h" #include "ipc_ns.h"
#include "pstree.h" #include "pstree.h"
#include "protobuf.h"
#include "protobuf/fdinfo.pb-c.h"
#define DEF_PAGES_PER_LINE 6 #define DEF_PAGES_PER_LINE 6
#ifndef CONFIG_X86_64 #ifndef CONFIG_X86_64
...@@ -77,21 +80,16 @@ static char *fdtype2s(u8 type) ...@@ -77,21 +80,16 @@ static char *fdtype2s(u8 type)
void show_files(int fd_files, struct cr_options *o) void show_files(int fd_files, struct cr_options *o)
{ {
struct fdinfo_entry e;
pr_img_head(CR_FD_FDINFO); pr_img_head(CR_FD_FDINFO);
while (1) { while (1) {
int ret; FdinfoEntry *e;
int ret = pb_read_eof(fd_files, &e, fdinfo_entry);
ret = read_img_eof(fd_files, &e);
if (ret <= 0) if (ret <= 0)
goto out; goto out;
pr_msg("type: %-5s fd: %-5d id: %#x flags %#x\n",
pr_msg("type: %-5s fd: %-5d id: %#x flags %#x", fdtype2s(e->type), e->fd, e->id, e->flags);
fdtype2s(e.type), e.fd, e.id, e.flags); fdinfo_entry__free_unpacked(e, NULL);
pr_msg("\n");
} }
out: out:
......
...@@ -30,7 +30,7 @@ u32 fd_id_generate_special(void) ...@@ -30,7 +30,7 @@ u32 fd_id_generate_special(void)
return fd_tree.subid++; 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; u32 id;
struct kid_elem e; struct kid_elem e;
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include "sockets.h" #include "sockets.h"
#include "pstree.h" #include "pstree.h"
#include "protobuf.h"
static struct fdinfo_list_entry *fdinfo_list; static struct fdinfo_list_entry *fdinfo_list;
static int nr_fdinfo_list; static int nr_fdinfo_list;
...@@ -71,7 +73,7 @@ struct file_desc *find_file_desc_raw(int type, u32 id) ...@@ -71,7 +73,7 @@ struct file_desc *find_file_desc_raw(int type, u32 id)
return NULL; 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); return find_file_desc_raw(fe->type, fe->id);
} }
...@@ -152,7 +154,7 @@ int rst_file_params(int fd, fown_t *fown, int flags) ...@@ -152,7 +154,7 @@ int rst_file_params(int fd, fown_t *fown, int flags)
return 0; 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 fdinfo_list_entry *l, *le = &fdinfo_list[nr_fdinfo_list];
struct file_desc *fdesc; struct file_desc *fdesc;
...@@ -206,19 +208,17 @@ int prepare_fd_pid(int pid, struct rst_info *rst_info) ...@@ -206,19 +208,17 @@ int prepare_fd_pid(int pid, struct rst_info *rst_info)
} }
while (1) { while (1) {
struct fdinfo_entry *e = xmalloc(sizeof(*e)); FdinfoEntry *e;
if (!e) {
ret = -1;
break;
}
ret = read_img_eof(fdinfo_fd, e); ret = pb_read_eof(fdinfo_fd, &e, fdinfo_entry);
if (ret <= 0) if (ret <= 0)
break; break;
ret = collect_fd(pid, e, rst_info); ret = collect_fd(pid, e, rst_info);
if (ret < 0) if (ret < 0) {
fdinfo_entry__free_unpacked(e, NULL);
break; break;
}
} }
close(fdinfo_fd); close(fdinfo_fd);
...@@ -255,7 +255,7 @@ static void transport_name_gen(struct sockaddr_un *addr, int *len, ...@@ -255,7 +255,7 @@ static void transport_name_gen(struct sockaddr_un *addr, int *len,
*addr->sun_path = '\0'; *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) if (fd->ops->want_transport)
return fd->ops->want_transport(fe, fd); 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) ...@@ -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); 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 tmp;
int sock; int sock;
...@@ -383,7 +383,7 @@ static int open_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d) ...@@ -383,7 +383,7 @@ static int open_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d)
return 0; 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; int tmp;
struct fdinfo_list_entry *fle; struct fdinfo_list_entry *fle;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "types.h" #include "types.h"
#include "rbtree.h" #include "rbtree.h"
#include "../protobuf/fdinfo.pb-c.h"
#define FD_PID_INVALID (-2U) #define FD_PID_INVALID (-2U)
#define FD_DESC_INVALID (-3U) #define FD_DESC_INVALID (-3U)
...@@ -12,7 +14,7 @@ ...@@ -12,7 +14,7 @@
(((u32)(dev) ^ (u32)(ino) ^ (u32)(pos))) (((u32)(dev) ^ (u32)(ino) ^ (u32)(pos)))
struct fdinfo_entry; 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 u32 fd_id_generate_special(void);
extern void fd_id_show_tree(void); extern void fd_id_show_tree(void);
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "list.h" #include "list.h"
#include "image.h" #include "image.h"
#include "../protobuf/fdinfo.pb-c.h"
struct pstree_item; struct pstree_item;
struct file_desc; struct file_desc;
struct cr_fdset; struct cr_fdset;
...@@ -38,13 +40,13 @@ struct fdinfo_list_entry { ...@@ -38,13 +40,13 @@ struct fdinfo_list_entry {
struct list_head ps_list; struct list_head ps_list;
int pid; int pid;
futex_t real_pid; futex_t real_pid;
struct fdinfo_entry *fe; FdinfoEntry *fe;
}; };
struct file_desc_ops { struct file_desc_ops {
unsigned int type; unsigned int type;
int (*open)(struct file_desc *d); 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 { struct file_desc {
......
...@@ -131,13 +131,6 @@ struct inotify_file_entry { ...@@ -131,13 +131,6 @@ struct inotify_file_entry {
fown_t fown; fown_t fown;
} __packed; } __packed;
struct fdinfo_entry {
u32 fd;
u8 type;
u8 flags;
u32 id;
} __packed;
struct fs_entry { struct fs_entry {
u32 cwd_id; u32 cwd_id;
u32 root_id; u32 root_id;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
struct fdinfo_list_entry; struct fdinfo_list_entry;
struct sk_opts_entry; struct sk_opts_entry;
struct fdinfo_entry;
struct cr_options; struct cr_options;
struct file_desc; struct file_desc;
struct fd_parms; struct fd_parms;
......
...@@ -294,7 +294,7 @@ static int open_pipe(struct file_desc *d) ...@@ -294,7 +294,7 @@ static int open_pipe(struct file_desc *d)
return tmp; 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; struct pipe_info *pi;
......
-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)
message fdinfo_entry {
required uint32 id = 1;
required uint32 flags = 2;
required uint32 type = 3;
required uint32 fd = 4;
}
...@@ -573,7 +573,7 @@ done: ...@@ -573,7 +573,7 @@ done:
return 0; return 0;
} }
static int unixsk_should_open_transport(struct fdinfo_entry *fe, static int unixsk_should_open_transport(FdinfoEntry *fe,
struct file_desc *d) struct file_desc *d)
{ {
struct unix_sk_info *ui; struct unix_sk_info *ui;
......
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