[CRIU] [PATCH v2 3/8] stats: add a helper to get stats of parent pre-dump

Andrew Vagin avagin at virtuozzo.com
Wed Feb 14 01:32:13 MSK 2018


On Mon, Feb 12, 2018 at 01:31:00PM +0300, Pavel Tikhomirov wrote:
> From: ptikhomirov <ptikhomirov at virtuozzo.com>
> 
> will be used in the next patch
> 
> https://jira.sw.ru/browse/PSBM-67502
> 
> note: actually we need only one value from stats entry but I still
> prefer general helper as we still need to read and allocate memory
> for the whole structure
> 
> v2: fix get_parent_stats to have static typing
> 
> Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
> ---
>  criu/include/stats.h |  4 ++++
>  criu/stats.c         | 30 ++++++++++++++++++++++++++++++
>  2 files changed, 34 insertions(+)
> 
> diff --git a/criu/include/stats.h b/criu/include/stats.h
> index 81775c856..a25370587 100644
> --- a/criu/include/stats.h
> +++ b/criu/include/stats.h
> @@ -1,6 +1,8 @@
>  #ifndef __CR_STATS_H__
>  #define __CR_STATS_H__
>  
> +#include "images/stats.pb-c.h"
> +
>  enum {
>  	TIME_FREEZING,
>  	TIME_FROZEN,
> @@ -23,6 +25,8 @@ extern void timing_start(int t);
>  extern void timing_stop(int t);
>  extern int timing_uptime(int t);
>  
> +extern int get_parent_stats(StatsEntry **se);
> +
>  enum {
>  	CNT_PAGES_SCANNED,
>  	CNT_PAGES_SKIPPED_PARENT,
> diff --git a/criu/stats.c b/criu/stats.c
> index 2944474cd..ddc852a30 100644
> --- a/criu/stats.c
> +++ b/criu/stats.c
> @@ -213,6 +213,36 @@ void write_stats(int what)
>  		display_stats(what, &stats);
>  }
>  
> +__maybe_unused int get_parent_stats(StatsEntry **stats)

In the next patch, this helper is called for each task. Do we really need
to read the same state many times?

> +{
> +	struct cr_img *img;
> +	int dir;
> +
> +	dir = openat(get_service_fd(IMG_FD_OFF), CR_PARENT_LINK, O_RDONLY);
> +	if (dir == -1) {
> +		pr_perror("Failed to open parent directory");
> +		return -1;
> +	}
> +
> +	img = open_image_at(dir, CR_FD_STATS, O_RSTR, "dump");
> +	if (!img) {
> +		pr_perror("Failed to open parent dump stats");
> +		close(dir);
> +		return -1;
> +	}
> +
> +	if (pb_read_one(img, stats, PB_STATS) < 0) {
> +		pr_perror("Failed to read parent dump stats");
> +		close_image(img);
> +		close(dir);
> +		return -1;
> +	}
> +
> +	close_image(img);
> +	close(dir);
> +	return 0;
> +}
> +
>  int init_stats(int what)
>  {
>  	if (what == DUMP_STATS) {
> -- 
> 2.14.3
> 


More information about the CRIU mailing list