[CRIU] Re: [PATCH 2/5] This patch introduces base message prototypes Google's protobuf facility.

Stanislav Kinsbursky skinsbursky at parallels.com
Thu Jul 5 01:48:25 EDT 2012


04.07.2012 22:05, Cyrill Gorcunov пишет:
> 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 every image snippet should be convered
> to use this facility.
>
> 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
>
>   - message img_hdr, message obj_hdr
>
>          This is most important messages, the first one
>          img_hdr should be used as a header for any image
>          file. The obj_hdr in turn provides a way to describe
>          objects being stored in image by flexible way.
>
>          See more details in image.base.proto file itself.
>
> 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         |   54 +++++++++++++++++++++++++++++
>   protobuf/fdinfo.proto     |    6 +++
>   protobuf/fown.proto       |    7 ++++
>   protobuf/image.base.proto |   82 +++++++++++++++++++++++++++++++++++++++++++++
>   protobuf/regfile.proto    |   10 +++++
>   6 files changed, 169 insertions(+), 4 deletions(-)
>   create mode 100644 protobuf/Makefile
>   create mode 100644 protobuf/fdinfo.proto
>   create mode 100644 protobuf/fown.proto
>   create mode 100644 protobuf/image.base.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..764374f
> --- /dev/null
> +++ b/protobuf/Makefile
> @@ -0,0 +1,54 @@
> +-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	+= image.base.proto
> +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..e0445c6
> --- /dev/null
> +++ b/protobuf/fdinfo.proto
> @@ -0,0 +1,6 @@
> +message fdinfo_entry {
> +	required fixed32	fd	= 1;
> +	required fixed32	type	= 2;
> +	required fixed32	flags	= 3;
> +	required fixed32	id	= 4;
> +}
> diff --git a/protobuf/fown.proto b/protobuf/fown.proto
> new file mode 100644
> index 0000000..15d49bf
> --- /dev/null
> +++ b/protobuf/fown.proto
> @@ -0,0 +1,7 @@
> +message fown_t {
> +	required fixed32	uid		= 1;
> +	required fixed32	euid		= 2;
> +	required fixed32	signum		= 3;
> +	required fixed32	pid_type	= 4;
> +	required fixed32	pid		= 5;
> +}
> diff --git a/protobuf/image.base.proto b/protobuf/image.base.proto
> new file mode 100644
> index 0000000..5676c56
> --- /dev/null
> +++ b/protobuf/image.base.proto
> @@ -0,0 +1,82 @@
> +/*
> + * These are base types for crtools Protocol Buffers (PB) objects.
> + * They are immutable and should reman such forever.
> + *
> + * The only thing which is allowed to change -- add
> + * new OBJ_ types if needed.
> + *
> + * Basically every image consist of PB sequense
> + *
> + *    +---------------+
> + *    |    img_hdr    | general header
> + *    +---------------+
> + *    |    obj_hdr    | header for the next object
> + *    +---------------+
> + *    |    object     |
> + *    +---------------+
> + *          ...
> + *
> + * If some PB sequence is supposed to be sent by
> + * a stream then the sequence should be wrapped with
> + * start/stop markers.
> + *
> + *    +---------------+
> + *    |    img_hdr    | general header
> + *    +---------------+
> + *    |    OBJ_START  | header with type OBJ_START and packed_size 0
> + *    +---------------+
> + *    |    obj_hdr    | header for the next object
> + *    +---------------+
> + *    |    object     |
> + *    +---------------+
> + *          ...
> + *           ...
> + *    +---------------+
> + *    |    obj_hdr    | header for the next object
> + *    +---------------+
> + *    |    object     |
> + *    +---------------+
> + *    |    OBJ_STOP   | header with type OBJ_STOP and packed_size 0
> + *    +---------------+
> + *
> + * In case if there an array of PB objects then one should use
> + * array start/stop markers.
> + *
> + *    +---------------+
> + *    |    img_hdr    | general header
> + *    +---------------+
> + *    |   OBJ_STARTA  | header with type OBJ_STARTA and packed_size = sizeof one object
> + *    +---------------+
> + *    |    object     |
> + *    +---------------+
> + *          ...
> + *           ...
> + *    +---------------+
> + *    |    object     |
> + *    +---------------+
> + *    |    OBJ_ENDA   | header with type OBJ_ENDA and packed_size 0
> + *    +---------------+
> + */
> +
> +message img_hdr {
> +	required fixed64			magic		= 1;
> +	required fixed64			version		= 2;
> +	required fixed64			flags		= 3;

What are these flags stands for?

> +}
> +
> +message obj_hdr {
> +	enum obj_type {
> +		OBJ_UNKNOWN		=	0;
> +		OBJ_START		=	1;
> +		OBJ_STOP		=	2;
> +
> +		OBJ_STARTA		=	3;
> +		OBJ_ENDA		=	4;
> +
> +		OBJ_FDINFO		=	5;
> +		OBJ_REGFILE		=	6;
> +	}
> +

Do we really need this obj_type?

> +	required fixed32			type		= 1;

Why file magic is not enough?

> +	required fixed64			pksize		= 2;
> +}
> diff --git a/protobuf/regfile.proto b/protobuf/regfile.proto
> new file mode 100644
> index 0000000..5dcb0d6
> --- /dev/null
> +++ b/protobuf/regfile.proto
> @@ -0,0 +1,10 @@
> +import "fown.proto";
> +
> +message reg_file_entry {
> +	required fixed32	id	= 1;
> +	required fixed32	flags	= 2;
> +	required fixed64	pos	= 3;
> +	required fixed32	len	= 4;
> +	required fown_t		fown	= 5;
> +	optional string		name	= 6;
> +}





More information about the CRIU mailing list