[CRIU] [PATCH 11/12] posix-timer: Restore timers, need create and delete 'fake' timers

Pavel Emelyanov xemul at parallels.com
Thu May 30 07:09:13 EDT 2013


On 05/30/2013 03:36 AM, Pavel Tikhomirov wrote:
> 
> Signed-off-by: Pavel Tikhomirov <snorcht at gmail.com>
> ---
>  pie/restorer.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/pie/restorer.c b/pie/restorer.c
> index 69f0a0d..a367773 100644
> --- a/pie/restorer.c
> +++ b/pie/restorer.c
> @@ -473,6 +473,50 @@ static int vma_remap(unsigned long src, unsigned long dst, unsigned long len)
>  	return 0;
>  }
>  
> +static int restore_posix_timers(struct task_restore_core_args *args)
> +{
> +	int ret = 0;
> +	if (args->timer_n > 0) {
> +		int i, j;
> +		int tmp_id = 0;
> +		timer_t timeridt;
> +		timer_t timerid;
> +		struct sigevent sev;
> +		for (i = 0; i < args->timer_n; i++) {
> +			for (j = tmp_id; j < args->posix_timers[i].it_id; j++) {

This means, that timers should be sorted in args->. I haven't found any sorting in patch #10
which read timers in.

Also, kernel doesn't guarantee to allocate timer IDs one by one :) We just know it does so,
but need to verify it anyway. Thus this loop should look like

while (1) {
	next_id = sys_timer_create();
	if (next_id == id_we_want)
		break;
	if (next_id > id_we_want) {
		pr_error("We are screwed\n");
		return -1;
	}

	sys_timer_delete(next_id);
	continue;
}

> +				ret = sys_timer_create(CLOCK_REALTIME, NULL, &timeridt);
> +				if (ret < 0) {
> +					pr_err("Can't create temporary posix timer %lx\n", (long) timeridt);
> +					return ret;
> +				}
> +				ret = sys_timer_delete(timeridt);
> +				if (ret < 0) {
> +					pr_err("Can't remove temporaty posix timer %lx\n", (long) timeridt);
> +					return ret;
> +				}
> +			}
> +			sev.sigev_notify = args->posix_timers[i].it_sigev_notify;
> +			sev.sigev_signo = args->posix_timers[i].si_signo;
> +			sev.sigev_value.sival_ptr = args->posix_timers[i].sival_ptr.p;
> +
> +			ret = sys_timer_create(args->posix_timers[i].clock_id, &sev, &timerid);
> +			if (ret < 0) {
> +				pr_err("Can't create posix timer - %d\n", i);
> +				return ret;
> +			}
> +
> +			ret = sys_timer_settime(timerid, 0, &args->posix_timers[i].val, NULL);
> +			if (ret < 0) {
> +				pr_err("Can't set posix timer %lx\n", (long) timerid);
> +				return ret;
> +			}
> +
> +			tmp_id = args->posix_timers[i].it_id + 1;
> +		}
> +	}
> +	return 0;
> +}
> +
>  /*
>   * The main routine to restore task via sigreturn.
>   * This one is very special, we never return there
> @@ -839,6 +883,12 @@ long __export_restore_task(struct task_restore_core_args *args)
>  		}
>  	}
>  
> +	ret = restore_posix_timers(args);
> +	if (ret < 0){
> +		pr_err("Can't restore posix timers %ld\n", ret);
> +		goto core_restore_end;
> +	}
> +
>  	rst_tcp_socks_all(args->rst_tcp_socks, args->rst_tcp_socks_size);
>  
>  	/* 
> 




More information about the CRIU mailing list