[CRIU] Re: [PATCH cr 1/2] restore: auto-unlink for ghost files

Pavel Emelyanov xemul at parallels.com
Mon Sep 10 09:45:35 EDT 2012


On 09/10/2012 05:34 PM, Andrey Vagin wrote:
> 
> A ghost file is deleted, when the last user opens it.

Comment sucks.

> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  cr-restore.c        |    6 ------
>  files-reg.c         |   36 +++++++++++++++++-------------------
>  include/files-reg.h |    3 ++-
>  3 files changed, 19 insertions(+), 26 deletions(-)

> @@ -124,9 +113,11 @@ static int open_remap_ghost(struct reg_file_info *rfi,
>  	close(gfd);
>  
>  	gf->id = rfe->remap_id;
> +	gf->users = 0;
>  	list_add_tail(&gf->list, &ghost_files);
>  gf_found:
> -	rfi->remap_path = gf->path;
> +	gf->users++;

Need comments saying why non-atomic is OK here.

> +	rfi->ghost = gf;
>  	return 0;
>  
>  err:



> @@ -372,8 +363,15 @@ static int open_path(struct file_desc *d,
>  		return -1;
>  	}
>  
> -	if (rfi->remap_path)
> +	if (rfi->ghost) {
> +		int users;
>  		unlink(rfi->path);
> +		users = atomic_dec(&rfi->ghost->users);
> +		if (users == 1) {

Why 1? Maybe it's worth having atomic_dec_and_test?

> +			pr_info("Unlink the ghost %s\n", rfi->ghost->path);
> +			unlink(rfi->ghost->path);
> +		}
> +	}
>  
>  	if (restore_fown(tmp, rfi->rfe->fown))
>  		return -1;



More information about the CRIU mailing list