[CRIU] [PATCH 3/3] unix: allow --external unix[ino]:string

Ruslan Kuprieiev rkuprieiev at cloudlinux.com
Tue Jan 10 05:01:50 PST 2017


On dump, if --external unix[ino]:foo is specified, criu will treat 
specified unix socket almost the same
way it handles criu service socket. It will dump it as closed and will 
put "foo" string into images, to put
that "foo" string into that socket on restore. This is almost identical 
to what criu does with service
socket, but instead of putting a Criu_Resp message into it on restore, 
it puts an arbitrary string.


On 01/10/2017 02:56 PM, Pavel Emelyanov wrote:
> On 01/05/2017 03:42 PM, Ruslan Kuprieiev wrote:
>
> Can you elaborate what this option should do? It's not 100% clear
> from the code.
>
>> Needles to say that it's useful for debug, but this is also
>> very useful when you syncronise checkpoint/restore whith a
>> dumpee using unix socketpair and want it to painlessly
>> receive notification on restore.
>>
>> Signed-off-by: Ruslan Kuprieiev <rkuprieiev at cloudlinux.com>
>> ---
>>   criu/sk-unix.c       | 23 +++++++++++++++++++++--
>>   images/sk-unix.proto |  5 +++++
>>   2 files changed, 26 insertions(+), 2 deletions(-)
>>
>> diff --git a/criu/sk-unix.c b/criu/sk-unix.c
>> index 5cbe07a..4527dd6 100644
>> --- a/criu/sk-unix.c
>> +++ b/criu/sk-unix.c
>> @@ -263,6 +263,8 @@ static int dump_one_unix_fd(int lfd, u32 id, const struct fd_parms *p)
>>   	SkOptsEntry *skopts;
>>   	FilePermsEntry *perms;
>>   	FownEntry *fown;
>> +	char buf[PATH_MAX];
>> +	char *ext = NULL;
>>   
>>   	ue = xmalloc(sizeof(UnixSkEntry) +
>>   			sizeof(SkOptsEntry) +
>> @@ -322,6 +324,16 @@ static int dump_one_unix_fd(int lfd, u32 id, const struct fd_parms *p)
>>   		ue->uflags |= USK_SERVICE;
>>   	}
>>   
>> +	/* Same as with service_sk, but for custom sockets */
>> +	snprintf(buf, sizeof(buf), "unix[%u]", ue->peer);
>> +	ext = external_lookup_by_key(buf);
>> +	if (unlikely(!IS_ERR_OR_NULL(ext))) {
>> +		ue->state = TCP_CLOSE;
>> +		ue->peer = 0;
>> +		ue->uflags |= USK_SERVICE;
>> +		ue->stub = (void *)strtok(ext, ":");
>> +	}
>> +
>>   	if (sk->namelen && *sk->name) {
>>   		ue->file_perms = perms;
>>   
>> @@ -1139,8 +1151,15 @@ static int open_unixsk_standalone(struct unix_sk_info *ui)
>>   			return -1;
>>   		}
>>   
>> -		if (send_criu_dump_resp(sks[1], true, true) == -1)
>> -			return -1;
>> +		if (ui->ue->stub) {
>> +			unsigned int l;
>> +			l = strlen(ui->ue->stub);
>> +			if (write(sks[1], ui->ue->stub, l) != l)
>> +				return -1;
>> +		} else {
>> +			if (send_criu_dump_resp(sks[1], true, true) == -1)
>> +				return -1;
>> +		}
>>   
>>   		close(sks[1]);
>>   		sk = sks[0];
>> diff --git a/images/sk-unix.proto b/images/sk-unix.proto
>> index 3026214..4437700 100644
>> --- a/images/sk-unix.proto
>> +++ b/images/sk-unix.proto
>> @@ -48,4 +48,9 @@ message unix_sk_entry {
>>   	 */
>>   	optional string			name_dir	= 14;
>>   	optional bool			deleted		= 15;
>> +
>> +	/*
>> +	 * Stub to put into service socket on restore
>> +	 */
>> +        optional string			stub		= 16;
>>   }
>>



More information about the CRIU mailing list