[CRIU] [PATCH 2/4] protobuf: Start switching our image entries to
Google's protobuf
Cyrill Gorcunov
gorcunov at openvz.org
Fri Jul 6 08:10:46 EDT 2012
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.
But before anything else we need a scaffold, ie .proto files which declare
entries on disk.
Instead of squashing everything in one commit we introduce only a few
types needed for further work. In particular
- message fdinfo_entry
This message maps old fdinfo_entry structure
- message fown_t
This message maps old fown_t, which is embedded
in a number of another messages
- message reg_file_entry
This message maps old reg_file_entry structure
Note that there is no real use of this facility in our code yet.
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: Kinsbursky Stanislav <skinsbursky at openvz.org>
Inspired-by: Pavel Emelianov <xemul at parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
Makefile | 14 +++++++++---
protobuf/Makefile | 53 ++++++++++++++++++++++++++++++++++++++++++++++++
protobuf/fdinfo.proto | 6 +++++
protobuf/fown.proto | 7 ++++++
protobuf/regfile.proto | 10 +++++++++
5 files changed, 86 insertions(+), 4 deletions(-)
create mode 100644 protobuf/Makefile
create mode 100644 protobuf/fdinfo.proto
create mode 100644 protobuf/fown.proto
create mode 100644 protobuf/regfile.proto
diff --git a/Makefile b/Makefile
index 81c9ca8..db2e6f7 100644
--- a/Makefile
+++ b/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
@@ -60,6 +60,8 @@ OBJS += mount.o
OBJS += inotify.o
OBJS += pstree.o
+PROTOBUF-LIB := protobuf/protobuf-lib.o
+
DEPS := $(patsubst %.o,%.d,$(OBJS))
MAKEFLAGS += --no-print-directory
@@ -68,13 +70,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 $@
@@ -91,7 +96,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 $@
@@ -120,6 +125,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
diff --git a/protobuf/Makefile b/protobuf/Makefile
new file mode 100644
index 0000000..b8d46b0
--- /dev/null
+++ b/protobuf/Makefile
@@ -0,0 +1,53 @@
+-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 += fown.proto
+PROTO_FILES += fdinfo.proto
+PROTO_FILES += regfile.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)
+
diff --git a/protobuf/fdinfo.proto b/protobuf/fdinfo.proto
new file mode 100644
index 0000000..3b4a57c
--- /dev/null
+++ b/protobuf/fdinfo.proto
@@ -0,0 +1,6 @@
+message fdinfo_entry {
+ required uint32 id = 1;
+ required uint32 flags = 2;
+ required uint32 type = 3;
+ required uint32 fd = 4;
+}
diff --git a/protobuf/fown.proto b/protobuf/fown.proto
new file mode 100644
index 0000000..5f83a8d
--- /dev/null
+++ b/protobuf/fown.proto
@@ -0,0 +1,7 @@
+message fown_t {
+ required uint32 uid = 1;
+ required uint32 euid = 2;
+ required uint32 signum = 3;
+ required uint32 pid_type = 4;
+ required uint32 pid = 5;
+}
diff --git a/protobuf/regfile.proto b/protobuf/regfile.proto
new file mode 100644
index 0000000..7efac6c
--- /dev/null
+++ b/protobuf/regfile.proto
@@ -0,0 +1,10 @@
+import "fown.proto";
+
+message reg_file_entry {
+ required uint32 id = 1;
+ required uint32 flags = 2;
+ required uint64 pos = 3;
+ required uint32 len = 4;
+ required fown_t fown = 5;
+ optional string name = 6;
+}
--
1.7.7.6
More information about the CRIU
mailing list