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

Andrew Vagin avagin at parallels.com
Mon Jul 1 06:02:55 EDT 2013


On Thu, Jun 27, 2013 at 11:32:26PM +0400, Pavel Tikhomirov wrote:
> 
> Signed-off-by: Pavel Tikhomirov <snorcht at gmail.com>
> ---
>  pie/restorer.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
> 
> diff --git a/pie/restorer.c b/pie/restorer.c
> index 06b24a9..7598e57 100644
> --- a/pie/restorer.c
> +++ b/pie/restorer.c
> @@ -473,6 +473,52 @@ 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) {

Why do we need this check?


FYI:
"""
Now, some people will claim that having 8-character indentations makes
the code move too far to the right, and makes it hard to read on a
80-character terminal screen.  The answer to that is that if you need
more than 3 levels of indentation, you're screwed anyway, and should fix
your program.
"""

> +		int i;
> +		timer_t next_id;
> +		struct sigevent sev;
> +
> +		for (i = 0; i < args->timer_n; i++) {
> +			sev.sigev_notify = args->posix_timers[i].spt.it_sigev_notify;
> +			sev.sigev_signo = args->posix_timers[i].spt.si_signo;
> +			sev.sigev_value.sival_ptr = args->posix_timers[i].spt.sival_ptr;
> +
> +			while (1) {
> +				ret = sys_timer_create(args->posix_timers[i].spt.clock_id, &sev, &next_id);
> +				if (ret < 0) {
> +					pr_err("Can't create posix timer - %d\n", i);

We need to print ret to know a reason

> +					return ret;
> +				}

Is next_id per-process? Does its value inherit after fork?

> +
> +				if ((long)next_id == args->posix_timers[i].spt.it_id)
> +					break;
> +
> +				ret = sys_timer_delete(next_id);
> +				if (ret < 0) {
> +					pr_err("Can't remove temporaty posix timer %lx\n", (long) next_id);
> +					return ret;
> +				}
> +
> +				if ((long)next_id > args->posix_timers[i].spt.it_id) {
> +					pr_err("Can't create timers, kernel don't give them consequently");
> +					return -1;
> +				}
> +			}
> +
> +			ret = sys_timer_settime(next_id, 0, &args->posix_timers[i].val, NULL);
> +			if (ret < 0) {
> +				pr_err("Can't set posix timer %lx\n", (long) next_id);
> +				return ret;
> +			}
> +		}
> +	}
> +	return 0;
> +}
> +
>  /*
>   * The main routine to restore task via sigreturn.
>   * This one is very special, we never return there
> @@ -839,6 +885,12 @@ long __export_restore_task(struct task_restore_core_args *args)
>  		}
>  	}
>  
> +	ret = restore_posix_timers(args);
> +	if (ret < 0){
	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);
>  
>  	/* 
> -- 
> 1.7.9.5
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list