Commit e866b7c0 authored by Pavel Emelyanov's avatar Pavel Emelyanov

rpc: Split rpc req-s from rpc-resps

Now we don't have generic criu_msg thing -- instead, we have
explicit request (with per-type args) and explicit responce
(yet again -- with per-type args).
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent d285be5e
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
struct _cr_service_client *cr_service_client; struct _cr_service_client *cr_service_client;
static int recv_criu_msg(int socket_fd, CriuMsg **msg) static int recv_criu_msg(int socket_fd, CriuReq **msg)
{ {
unsigned char buf[MAX_MSG_SIZE]; unsigned char buf[MAX_MSG_SIZE];
int len; int len;
...@@ -31,7 +31,7 @@ static int recv_criu_msg(int socket_fd, CriuMsg **msg) ...@@ -31,7 +31,7 @@ static int recv_criu_msg(int socket_fd, CriuMsg **msg)
return -1; return -1;
} }
*msg = criu_msg__unpack(NULL, len, buf); *msg = criu_req__unpack(NULL, len, buf);
if (!*msg) { if (!*msg) {
puts("Failed unpacking request"); puts("Failed unpacking request");
return -1; return -1;
...@@ -40,14 +40,14 @@ static int recv_criu_msg(int socket_fd, CriuMsg **msg) ...@@ -40,14 +40,14 @@ static int recv_criu_msg(int socket_fd, CriuMsg **msg)
return 0; return 0;
} }
static int send_criu_msg(int socket_fd, CriuMsg *msg) static int send_criu_msg(int socket_fd, CriuResp *msg)
{ {
unsigned char buf[MAX_MSG_SIZE]; unsigned char buf[MAX_MSG_SIZE];
int len; int len;
len = criu_msg__get_packed_size(msg); len = criu_resp__get_packed_size(msg);
if (criu_msg__pack(msg, buf) != len) { if (criu_resp__pack(msg, buf) != len) {
pr_perror("Failed packing response"); pr_perror("Failed packing response");
return -1; return -1;
} }
...@@ -60,12 +60,13 @@ static int send_criu_msg(int socket_fd, CriuMsg *msg) ...@@ -60,12 +60,13 @@ static int send_criu_msg(int socket_fd, CriuMsg *msg)
return 0; return 0;
} }
int send_criu_dump_resp(int socket_fd, CriuDumpResp *resp) int send_criu_dump_resp(int socket_fd, bool success, CriuDumpResp *resp)
{ {
CriuMsg msg = CRIU_MSG__INIT; CriuResp msg = CRIU_RESP__INIT;
msg.type = CRIU_MSG__TYPE__DUMPRESP; msg.type = CRIU_REQ_TYPE__DUMP;
msg.dump_resp = resp; msg.success = success;
msg.dump = resp;
return send_criu_msg(socket_fd, &msg); return send_criu_msg(socket_fd, &msg);
} }
...@@ -146,6 +147,7 @@ static int setup_dump_from_req(CriuDumpReq *req) ...@@ -146,6 +147,7 @@ static int setup_dump_from_req(CriuDumpReq *req)
static int dump_using_req(CriuDumpReq *req) static int dump_using_req(CriuDumpReq *req)
{ {
CriuDumpResp resp = CRIU_DUMP_RESP__INIT; CriuDumpResp resp = CRIU_DUMP_RESP__INIT;
bool success = false;
if (setup_dump_from_req(req) == -1) { if (setup_dump_from_req(req) == -1) {
pr_perror("Arguments treating fail"); pr_perror("Arguments treating fail");
...@@ -157,19 +159,19 @@ static int dump_using_req(CriuDumpReq *req) ...@@ -157,19 +159,19 @@ static int dump_using_req(CriuDumpReq *req)
goto exit; goto exit;
} }
resp.success = true; success = true;
exit: exit:
if (req->has_leave_running && req->leave_running) { if (req->has_leave_running && req->leave_running) {
if (send_criu_dump_resp(cr_service_client->sk_fd, if (send_criu_dump_resp(cr_service_client->sk_fd,
&resp) == -1) { success, &resp) == -1) {
pr_perror("Can't send response"); pr_perror("Can't send response");
resp.success = false; success = false;
} }
} }
close(cr_service_client->sk_fd); close(cr_service_client->sk_fd);
return resp.success ? 0 : 1; return success ? 0 : 1;
} }
int cr_service(bool daemon_mode) int cr_service(bool daemon_mode)
...@@ -183,7 +185,7 @@ int cr_service(bool daemon_mode) ...@@ -183,7 +185,7 @@ int cr_service(bool daemon_mode)
socklen_t server_addr_len; socklen_t server_addr_len;
socklen_t client_addr_len; socklen_t client_addr_len;
CriuMsg *msg = 0; CriuReq *msg = 0;
CriuDumpResp resp = CRIU_DUMP_RESP__INIT; CriuDumpResp resp = CRIU_DUMP_RESP__INIT;
cr_service_client = malloc(sizeof(struct _cr_service_client)); cr_service_client = malloc(sizeof(struct _cr_service_client));
...@@ -264,12 +266,8 @@ int cr_service(bool daemon_mode) ...@@ -264,12 +266,8 @@ int cr_service(bool daemon_mode)
} }
switch (msg->type) { switch (msg->type) {
case CRIU_MSG__TYPE__EMPTY: case CRIU_REQ_TYPE__DUMP:
pr_perror("Empty msg"); exit(dump_using_req(msg->dump));
goto err;
case CRIU_MSG__TYPE__DUMPREQ:
exit(dump_using_req(msg->dump_req));
default: default:
pr_perror("Invalid request"); pr_perror("Invalid request");
...@@ -285,7 +283,7 @@ err: ...@@ -285,7 +283,7 @@ err:
* and extend it where needed. * and extend it where needed.
*/ */
if (send_criu_dump_resp(cr_service_client->sk_fd, if (send_criu_dump_resp(cr_service_client->sk_fd,
&resp) == -1) false, &resp) == -1)
pr_perror("Can't send responce"); pr_perror("Can't send responce");
close(cr_service_client->sk_fd); close(cr_service_client->sk_fd);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
int cr_service(bool deamon_mode); int cr_service(bool deamon_mode);
int send_criu_dump_resp(int socket_fd, CriuDumpResp *resp); int send_criu_dump_resp(int socket_fd, bool success, CriuDumpResp *resp);
struct _cr_service_client { struct _cr_service_client {
int sk_ino; int sk_ino;
......
...@@ -12,19 +12,33 @@ message criu_dump_req { ...@@ -12,19 +12,33 @@ message criu_dump_req {
} }
message criu_dump_resp { message criu_dump_resp {
required bool success = 1; optional bool restored = 1;
optional bool restored = 2;
} }
message criu_msg { enum criu_req_type {
enum Type { EMPTY = 0;
EMPTY = 0; DUMP = 1;
DUMPREQ = 1; }
DUMPRESP = 2;
} /*
* Request -- each type corresponds to must-be-there
* request arguments of respective type
*/
message criu_req {
required criu_req_type type = 1;
optional criu_dump_req dump = 2;
}
/*
* Responce -- it states whether the request was served
* and additional request-specific informarion
*/
required Type type = 1; message criu_resp {
required criu_req_type type = 1;
required bool success = 2;
optional criu_dump_req dump_req = 2; optional criu_dump_resp dump = 3;
optional criu_dump_resp dump_resp = 3;
} }
...@@ -753,7 +753,6 @@ static int open_unixsk_standalone(struct unix_sk_info *ui) ...@@ -753,7 +753,6 @@ static int open_unixsk_standalone(struct unix_sk_info *ui)
int sks[2]; int sks[2];
CriuDumpResp resp = CRIU_DUMP_RESP__INIT; CriuDumpResp resp = CRIU_DUMP_RESP__INIT;
resp.success = true;
resp.has_restored = true; resp.has_restored = true;
resp.restored = true; resp.restored = true;
...@@ -762,7 +761,7 @@ static int open_unixsk_standalone(struct unix_sk_info *ui) ...@@ -762,7 +761,7 @@ static int open_unixsk_standalone(struct unix_sk_info *ui)
return -1; return -1;
} }
if (send_criu_dump_resp(sks[1], &resp) == -1) if (send_criu_dump_resp(sks[1], true, &resp) == -1)
return -1; return -1;
close(sks[1]); close(sks[1]);
......
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