[CRIU] [PATCH v1] files-reg: find appropriate dir to create link remap

Pavel Emelyanov xemul at virtuozzo.com
Wed Aug 10 06:33:30 PDT 2016


On 08/09/2016 04:15 PM, Egor Gorbunov wrote:
> Currently during criu dump we create link remap in the same dir
> where original file was opened. But that dir may not exist during
> link remap creation. At the same time it's okay to create link
> remap in any dir on the same mount point.
> In this patch we do this. We check existance of every dir bottom
> up through the original file path. We use the first existing dir.
> 
> Similar approach is used on criu restore during ghost file creation.

OK. Can you also cook a zdtm test that triggers this error?

> Signed-off-by: Egor Gorbunov <egor-mailbox at ya.ru>
> Signed-off-by: Eugene Batalov <eabatalov89 at gmail.com>
> ---
>  criu/files-reg.c                       | 12 +++++++++++-
>  test/zdtm/static/unlink_regular00.desc |  2 +-
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/criu/files-reg.c b/criu/files-reg.c
> index 2b7a211..29b48fe 100644
> --- a/criu/files-reg.c
> +++ b/criu/files-reg.c
> @@ -718,6 +718,7 @@ static int create_link_remap(char *path, int len, int lfd,
>  	RegFileEntry rfe = REG_FILE_ENTRY__INIT;
>  	FownEntry fwn = FOWN_ENTRY__INIT;
>  	int mntns_root;
> +	int ret;
>  
>  	if (!opts.link_remap_ok) {
>  		pr_err("Can't create link remap for %s. "
> @@ -754,7 +755,16 @@ static int create_link_remap(char *path, int len, int lfd,
>  
>  	mntns_root = mntns_get_root_fd(nsid);
>  
> -	if (linkat(lfd, "", mntns_root, link_name, AT_EMPTY_PATH) < 0) {
> +again:
> +	ret = linkat(lfd, "", mntns_root, link_name, AT_EMPTY_PATH);
> +	if (ret < 0 && errno == ENOENT) {
> +		/* Use grand parent, if parent directory does not exist. */
> +		if (trim_last_parent(link_name) < 0) {
> +			pr_err("trim failed: @%s@\n", link_name);
> +			return -1;
> +		}
> +		goto again;
> +	} else if (ret < 0) {
>  		pr_perror("Can't link remap to %s", path);
>  		return -1;
>  	}
> diff --git a/test/zdtm/static/unlink_regular00.desc b/test/zdtm/static/unlink_regular00.desc
> index 14d4c06..cd3aa9d 100644
> --- a/test/zdtm/static/unlink_regular00.desc
> +++ b/test/zdtm/static/unlink_regular00.desc
> @@ -1 +1 @@
> -{'flavor': 'ns', 'flags': 'suid crfail', 'opts': '--link-remap'}
> +{'flavor': 'ns', 'flags': 'suid', 'opts': '--link-remap'}
> 



More information about the CRIU mailing list