[CRIU] [PATCH]v2 service: add "one connection -- multiple requests" support

Ruslan Kuprieiev kupruser at gmail.com
Fri Nov 22 12:40:40 PST 2013


On 22.11.2013 21:39, Pavel Emelyanov wrote:
> On 11/23/2013 12:36 AM, 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 | 53 +++++++++++++++++++++++++++++++----------------------
>>   1 file changed, 31 insertions(+), 22 deletions(-)
>>
>> diff --git a/cr-service.c b/cr-service.c
>> index eba5342..73158f7 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,44 @@ static int check(int sk)
>>   
>>   static int cr_service_work(int sk)
>>   {
>> +	int ret;
>>   	CriuReq *msg = 0;
>> +	CriuResp err_resp = CRIU_RESP__INIT;
>> +
>> +	err_resp.type = CRIU_REQ_TYPE__EMPTY;
>> +	err_resp.success = false;
>>   
>>   	init_opts();
>>   
>> -	if (recv_criu_msg(sk, &msg) == -1) {
>> -		pr_perror("Can't recv request");
>> -		goto err;
>> -	}
>> +	do {
>> +		ret = recv_criu_msg(sk, &msg);
>> +		if (ret < 0)
>> +			goto err;
>>   
>> -	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);
>> +		if (ret == 0)
>> +			break;
>>   
>> -	default: {
>> -		CriuResp resp = CRIU_RESP__INIT;
>> +		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);
>>   
>> -		resp.type = CRIU_REQ_TYPE__EMPTY;
>> -		resp.success = false;
>> -		/* XXX -- add optional error code to CriuResp */
>> +		default:
>> +			goto err;
>> +		}
>>   
>> -		pr_perror("Invalid request");
>> -		send_criu_msg(sk, &resp);
>> +	} while (1);
> Please explain me how this loop can continue? It's body is
> either ended with break; or return <something>; :\

Sorry. Will redo.

>>   
>> -		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