[CRIU] [PATCH 2/3 v2] inventory: save dump_uptime for criu dump if track_mem is set

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Sat Apr 28 11:22:44 MSK 2018



On 04/28/2018 10:59 AM, Andrei Vagin wrote:
> A set of images from criu dump can be used as a previous point, when we
> are doing snapshots. In this case, each point contains a full set of
> images.
> 
> https://github.com/checkpoint-restore/criu/issues/479
> 
> v2: return -1 if invertory_save_uptime failed
> 
> Cc: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
> Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
> ---
>   criu/cr-dump.c         | 11 +++++++++--
>   criu/image.c           | 16 +++++++++++-----
>   criu/include/crtools.h |  2 +-
>   criu/mem.c             | 12 ++++++------
>   4 files changed, 27 insertions(+), 14 deletions(-)
> 
> diff --git a/criu/cr-dump.c b/criu/cr-dump.c
> index 00b84feed..7873e862e 100644
> --- a/criu/cr-dump.c
> +++ b/criu/cr-dump.c
> @@ -1574,10 +1574,14 @@ static int cr_pre_dump_finish(int ret)
>   	 * Restore registers for tasks only. The threads have not been
>   	 * infected. Therefore, the thread register sets have not been changed.
>   	 */
> -	if (arch_set_thread_regs(root_item, false) < 0)
> +	ret = arch_set_thread_regs(root_item, false);
> +	if (ret)
> +		goto err;
> +
> +	ret = invertory_save_uptime(&he);
> +	if (ret)
>   		goto err;
>   
> -	prepare_inventory_pre_dump(&he);
>   	pstree_switch_state(root_item, TASK_ALIVE);
>   
>   	timing_stop(TIME_FROZEN);
> @@ -2008,6 +2012,9 @@ int cr_dump_tasks(pid_t pid)
>   	if (ret)
>   		goto err;
>   
> +	if (invertory_save_uptime(&he))
> +		goto err;

Here we also need to set ret. Except that:
Reviewed-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>

> +
>   	ret = write_img_inventory(&he);
>   	if (ret)
>   		goto err;
> diff --git a/criu/image.c b/criu/image.c
> index fcdc081c1..108471b36 100644
> --- a/criu/image.c
> +++ b/criu/image.c
> @@ -113,14 +113,20 @@ int write_img_inventory(InventoryEntry *he)
>   	return 0;
>   }
>   
> -void prepare_inventory_pre_dump(InventoryEntry *he)
> +int invertory_save_uptime(InventoryEntry *he)
>   {
> -	pr_info("Perparing image inventory for pre-dump (version %u)\n", CRTOOLS_IMAGES_V1);
> +	if (!opts.track_mem)
> +		return 0;
>   
> -	he->img_version = CRTOOLS_IMAGES_V1_1;
> +	/*
> +	 * dump_uptime is used to detect whether a process was handled
> +	 * before or it is a new process with the same pid.
> +	 */
> +	if (parse_uptime(&he->dump_uptime))
> +		return -1;
>   
> -	if (!parse_uptime(&he->dump_uptime))
> -		he->has_dump_uptime = true;
> +	he->has_dump_uptime = true;
> +	return 0;
>   }
>   
>   InventoryEntry *get_parent_inventory(void)
> diff --git a/criu/include/crtools.h b/criu/include/crtools.h
> index 2c21e822a..7b2dc4523 100644
> --- a/criu/include/crtools.h
> +++ b/criu/include/crtools.h
> @@ -12,7 +12,7 @@
>   
>   extern int check_img_inventory(void);
>   extern int write_img_inventory(InventoryEntry *he);
> -extern void prepare_inventory_pre_dump(InventoryEntry *he);
> +extern int invertory_save_uptime(InventoryEntry *he);
>   extern InventoryEntry *get_parent_inventory(void);
>   extern int prepare_inventory(InventoryEntry *he);
>   struct pprep_head {
> diff --git a/criu/mem.c b/criu/mem.c
> index dc67fc50d..289f36297 100644
> --- a/criu/mem.c
> +++ b/criu/mem.c
> @@ -299,6 +299,12 @@ static int detect_pid_reuse(struct pstree_item *item,
>   	unsigned long long tps; /* ticks per second */
>   	int ret;
>   
> +	if (!parent_ie) {
> +		pr_err("Pid-reuse detection failed: no parent inventory, " \
> +		       "check warnings in get_parent_stats\n");
> +		return -1;
> +	}
> +
>   	tps = sysconf(_SC_CLK_TCK);
>   	if (tps == -1) {
>   		pr_perror("Failed to get clock ticks via sysconf");
> @@ -312,12 +318,6 @@ static int detect_pid_reuse(struct pstree_item *item,
>   			return -1;
>   	}
>   
> -	if (!parent_ie) {
> -		pr_err("Pid-reuse detection failed: no parent inventory, " \
> -		       "check warnings in get_parent_stats\n");
> -		return -1;
> -	}
> -
>   	dump_ticks = parent_ie->dump_uptime/(USEC_PER_SEC/tps);
>   
>   	if (pps->start_time >= dump_ticks) {
> 

-- 
Best regards, Tikhomirov Pavel
Software Developer, Virtuozzo.


More information about the CRIU mailing list