[CRIU] [PATCH] images: Implement collect_images() to minimaze code lines

Kirill Tkhai ktkhai at virtuozzo.com
Thu May 4 11:38:28 PDT 2017


Please, ignore this. v2 will be instead.

On 04.05.2017 21:31, Kirill Tkhai wrote:
> Pack repeated actions in one. No functional changes.
> 
> Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
> ---
>  criu/cr-restore.c       |   19 +++++--------------
>  criu/include/protobuf.h |   10 ++++++++++
>  2 files changed, 15 insertions(+), 14 deletions(-)
> 
> diff --git a/criu/cr-restore.c b/criu/cr-restore.c
> index afdc9eb75..ebcb77da5 100644
> --- a/criu/cr-restore.c
> +++ b/criu/cr-restore.c
> @@ -327,7 +327,7 @@ static int run_post_prepare(void)
>  
>  static int root_prepare_shared(void)
>  {
> -	int ret = 0, i;
> +	int ret = 0;
>  	struct pstree_item *pi;
>  
>  	pr_info("Preparing info about shared resources\n");
> @@ -341,11 +341,8 @@ static int root_prepare_shared(void)
>  	if (prepare_seccomp_filters())
>  		return -1;
>  
> -	for (i = 0; i < ARRAY_SIZE(cinfos); i++) {
> -		ret = collect_image(cinfos[i]);
> -		if (ret)
> -			return -1;
> -	}
> +	if (collect_images(cinfos, ARRAY_SIZE(cinfos)))
> +		return -1;
>  
>  	for_each_pstree_item(pi) {
>  		if (pi->pid->state == TASK_HELPER)
> @@ -1531,8 +1528,6 @@ static int restore_task_with_children(void *_arg)
>  
>  	/* Restore root task */
>  	if (current->parent == NULL) {
> -		int i;
> -
>  		if (prepare_shared_tty())
>  			goto err;
>  
> @@ -1554,12 +1549,8 @@ static int restore_task_with_children(void *_arg)
>  		if (mount_proc())
>  			goto err;
>  
> -		for (i = 0; i < ARRAY_SIZE(before_ns_cinfos); i++) {
> -			ret = collect_image(before_ns_cinfos[i]);
> -			if (ret)
> -				return -1;
> -		}
> -
> +		if (collect_images(before_ns_cinfos, ARRAY_SIZE(before_ns_cinfos)))
> +			return -1;
>  
>  		if (prepare_namespace(current, ca->clone_flags))
>  			goto err;
> diff --git a/criu/include/protobuf.h b/criu/include/protobuf.h
> index a90fcd1b2..ff6136f5c 100644
> --- a/criu/include/protobuf.h
> +++ b/criu/include/protobuf.h
> @@ -40,4 +40,14 @@ struct collect_image_info {
>  
>  extern int collect_image(struct collect_image_info *);
>  
> +static inline int collect_images(struct collect_image_info **array, unsigned size)
> +{
> +	int i;
> +	for (i = 0; i < size; i++) {
> +		if (collect_image(array[i]))
> +			return -1;
> +	}
> +	return 0;
> +}
> +
>  #endif /* __CR_PROTOBUF_H__ */
> 


More information about the CRIU mailing list