[CRIU] [PATCH 1/2] libcriu: Add ability to request for notifications from service

Pavel Emelyanov xemul at parallels.com
Thu Jun 26 03:01:56 PDT 2014


On 06/26/2014 12:31 PM, Andrew Vagin wrote:
> On Thu, Jun 26, 2014 at 12:11:30PM +0400, Pavel Emelyanov wrote:
>> On 06/26/2014 12:05 PM, Andrew Vagin wrote:
>>> On Wed, Jun 25, 2014 at 07:36:14PM +0400, Pavel Emelyanov wrote:
>>>> This is achieved by supplying the callback. Every time a notification
>>>> arrives the callback is called. Return value of 0 means continue,
>>>> any other value aborst the request and the value is reported back
>>>> to the caller (from criu_dump/criu_restore calls).
>>>>
>>>> Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
>>>> ---
>>>>  lib/criu.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++------
>>>>  lib/criu.h |  1 +
>>>>  2 files changed, 52 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/lib/criu.c b/lib/criu.c
>>>> index 4b1be8a..a827671 100644
>>>> --- a/lib/criu.c
>>>> +++ b/lib/criu.c
>>>> @@ -19,6 +19,7 @@ const char *criu_lib_version = CRIU_VERSION;
>>>>  
>>>>  static char *service_address = CR_DEFAULT_SERVICE_ADDRESS;
>>>>  static CriuOpts *opts;
>>>> +static int (*notify)(char *action);
>>>>  static int saved_errno;
>>>>  
>>>>  void criu_set_service_address(char *path)
>>>> @@ -31,8 +32,10 @@ void criu_set_service_address(char *path)
>>>>  
>>>>  int criu_init_opts(void)
>>>>  {
>>>> -	if (opts)
>>>> +	if (opts) {
>>>> +		notify = NULL;
>>>>  		criu_opts__free_unpacked(opts, NULL);
>>>> +	}
>>>>  
>>>>  	opts = malloc(sizeof(CriuOpts));
>>>>  	if (opts == NULL) {
>>>> @@ -44,6 +47,13 @@ int criu_init_opts(void)
>>>>  	return 0;
>>>>  }
>>>>  
>>>> +void criu_set_notify(int (*cb)(char *action))
>>>
>>> I wourld prefer to get pid in callbacks.
>>
>> So would I. Any ideas how to make this in non-ugly manner? Pid is
>> only available in one action.
> 
> It's available for all restore actions, isn't it?
> post-restore, setup-namespaces, network-unlock

For restore -- yes, in theory (the cr-service.c supplies one
for setup-namespaces only, but this, probably, can be fixed). 
For dump it's the same -- not supplied currently.

Other than this, there can be more notify arguments in the future,
we need some generic mechanism for getting such, not just and
argument.

I will send a patch with such generic way shortly.

Thanks,
Pavel



More information about the CRIU mailing list