RPC

From CRIU
Revision as of 18:38, 21 September 2013 by Efiop (talk | contribs)
Jump to navigation Jump to search

CRIU-RPC is a remote procedure call (RPC) protocol which uses Google Protocol Buffers to encode its calls and SOCK_SEQPACKET Unix domain socket as a transport mechanism.

Preconditions

Well described here: Self_dump.

CRIU request

criu_req is used to wrap requests to provide compatibility with an older versions of rpc. Any request must be wrapped into criu_req to send to criu.

message criu_req {
	required criu_req_type type	= 1;

	optional criu_dump_req dump	= 2;
}

There is only 1 request/response type for now.

enum criu_req_type {
	EMPTY		= 0;
	DUMP		= 1;
}

CRIU dump request

criu_dump_req is used to store dump options.

message criu_dump_req {
	required int32 images_dir_fd	= 1;
	optional int32 pid		= 2;

	optional bool leave_running	= 3;
	optional bool ext_unix_sk	= 4;
	optional bool tcp_established	= 5;
	optional bool evasive_devices	= 6;
	optional bool shell_job		= 7;
	optional bool file_locks	= 8;
	optional int32 log_level	= 9 [default = 2];
}

If no pid is set, CRIU will dump client process by default. Note: Whole tree <pid> must have the same uid, as a client, or client's uid must be == 0, otherwise CRIU won't dump nothing at all.

Only images_dir_fd is required, all other fields may not be set. Client must open directory for images by himself and set images_dir_fd to it's fd. CRIU will open /proc/<client's_pid>/fd/<images_dir_fd>, so it will work, if client is in another namespace.

For other options description, please run "criu -h".

CRIU response

criu_resp is a wrapper for responses. It consists of success bool field, response type field and response, that depends on sent request type.

message criu_resp {
	required criu_req_type type	= 1;
	required bool success		= 2;

	optional criu_dump_resp	dump	= 3;
}

CRIU dump response

criu_dump_resp is used to store response from CRIU.

message criu_dump_resp {
	optional bool restored		= 1;
}

Field "restored" is set to "true" if process was restored.

Server

On a server side, CRIU creates SOCK_SEQPACKET Unix socket and listens for connections on it. After receiving criu_req, CRIU processes it, do what is requested and sends response back.

To launch service server run:

#criu service --address <socket_address>

If no address is set, "/tmp/criu_service.socket" is used by default. You may also like to demonize server(-d), set log level(-v<N>) or set log file(-o <logname>). For the full list of options, please run "criu -h".

Client

Client, in its turn, must connect to service socket, send criu_msg with request in it, and wait for a criu_resp with response. You can find examples of client programs in C and Python in test/rpc/.