[CRIU] [PATCH] service: add "one connection -- multiple requests" support
Ruslan Kuprieiev
kupruser at gmail.com
Fri Nov 22 12:18:16 PST 2013
On 22.11.2013 21:13, Pavel Emelyanov wrote:
> On 11/22/2013 11:45 PM, Ruslan Kuprieiev wrote:
>> Currently we use "one connection -- one request" politics. This patch allows to connect to criu once and send multiple requests.
>>
>> Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
>> ---
>> cr-service.c | 61 +++++++++++++++++++++++++++++++++++++-----------------------
>> 1 file changed, 38 insertions(+), 23 deletions(-)
>>
>> diff --git a/cr-service.c b/cr-service.c
>> index eba5342..51c56b8 100644
>> --- a/cr-service.c
>> +++ b/cr-service.c
>> @@ -33,13 +33,16 @@ static int recv_criu_msg(int socket_fd, CriuReq **msg)
>> return -1;
>> }
>>
>> + if (len == 0)
>> + return 0;
>> +
>> *msg = criu_req__unpack(NULL, len, buf);
>> if (!*msg) {
>> pr_perror("Failed unpacking request");
>> return -1;
>> }
>>
>> - return 0;
>> + return 1;
>> }
>>
>> static int send_criu_msg(int socket_fd, CriuResp *msg)
>> @@ -231,38 +234,50 @@ static int check(int sk)
>>
>> static int cr_service_work(int sk)
>> {
>> + int pid, ret;
>> CriuReq *msg = 0;
>> + CriuResp err_resp = CRIU_RESP__INIT;
>>
>> - init_opts();
>> + err_resp.type = CRIU_REQ_TYPE__EMPTY;
>> + err_resp.success = false;
>>
>> - if (recv_criu_msg(sk, &msg) == -1) {
>> - pr_perror("Can't recv request");
>> - goto err;
>> - }
>> + init_opts();
>>
>> - switch (msg->type) {
>> - case CRIU_REQ_TYPE__DUMP:
>> - return dump_using_req(sk, msg->opts);
>> - case CRIU_REQ_TYPE__RESTORE:
>> - return restore_using_req(sk, msg->opts);
>> - case CRIU_REQ_TYPE__CHECK:
>> - return check(sk);
>> + do {
>> + ret = recv_criu_msg(sk, &msg);
>> + if (ret < 0)
>> + goto err;
>>
>> - default: {
>> - CriuResp resp = CRIU_RESP__INIT;
>> + if (ret == 0)
>> + break;
>> +
>> + pid = fork();
> NAK. Each request should be synchronous withing session.
Oh, yeah. I will add wait() after loop. Ok?
>> + if (pid == 0) {
>> + switch (msg->type) {
>> + case CRIU_REQ_TYPE__DUMP:
>> + return dump_using_req(sk, msg->opts);
>> + case CRIU_REQ_TYPE__RESTORE:
>> + return restore_using_req(sk, msg->opts);
>> + case CRIU_REQ_TYPE__CHECK:
>> + return check(sk);
>> +
>> + default:
>> + goto err;
>> + }
>> + }
>>
>> - resp.type = CRIU_REQ_TYPE__EMPTY;
>> - resp.success = false;
>> - /* XXX -- add optional error code to CriuResp */
>> + if (pid < 0)
>> + goto err;
>>
>> - pr_perror("Invalid request");
>> - send_criu_msg(sk, &resp);
>> + } while (1);
>>
>> - goto err;
>> - }
>> - }
>> + return 0;
>>
>> err:
>> + /* XXX -- add optional error code to CriuResp */
>> +
>> + send_criu_msg(sk, &err_resp);
>> +
>> return -1;
>> }
>>
>>
>
More information about the CRIU
mailing list