[CRIU] [PATCH 05/16] files: save mnt_id on fd_param

Pavel Emelyanov xemul at parallels.com
Wed Apr 9 07:58:29 PDT 2014


On 04/09/2014 03:34 AM, Andrey Vagin wrote:
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  cr-dump.c       | 29 +++++++++++++++++++++++++++--
>  files.c         |  1 +
>  include/files.h |  2 ++
>  3 files changed, 30 insertions(+), 2 deletions(-)
> 
> diff --git a/cr-dump.c b/cr-dump.c
> index 23bd13a..85246f2 100644
> --- a/cr-dump.c
> +++ b/cr-dump.c
> @@ -240,6 +240,17 @@ static int collect_fds(pid_t pid, struct parasite_drain_fd *dfds)
>  	return 0;
>  }
>  
> +static int get_fd_mntid(int fd, int *mnt_id)
> +{
> +	struct fdinfo_common fdinfo = { .mnt_id = -1};
> +
> +	if (parse_fdinfo(fd, FD_TYPES__UND, NULL, &fdinfo))
> +		return -1;
> +
> +	*mnt_id = fdinfo.mnt_id;
> +	return 0;
> +}
> +
>  static int dump_task_exe_link(pid_t pid, MmEntry *mm)
>  {
>  	struct fd_parms params = FD_PARMS_INIT;
> @@ -254,8 +265,12 @@ static int dump_task_exe_link(pid_t pid, MmEntry *mm)
>  		return -1;
>  	}
>  
> -	if (fd_id_generate_special(&params.stat, &mm->exe_file_id))
> +	if (get_fd_mntid(fd, &params.mnt_id))

I would make fd_id_generate_special get the fd ID instead of
calling it every time before.

> +		return -1;
> +
> +	if (fd_id_generate_special(&params.stat, &mm->exe_file_id)) {
>  		ret = dump_one_reg_file(fd, mm->exe_file_id, &params);
> +	}
>  
>  	close(fd);
>  	return ret;
> @@ -279,6 +294,9 @@ static int dump_task_fs(pid_t pid, struct parasite_dump_misc *misc, struct cr_fd
>  		return -1;
>  	}
>  
> +	if (get_fd_mntid(fd, &p.mnt_id))
> +		return -1;
> +
>  	if (fd_id_generate_special(&p.stat, &fe.cwd_id)) {
>  		ret = dump_one_reg_file(fd, fe.cwd_id, &p);
>  		if (ret < 0)
> @@ -297,6 +315,9 @@ static int dump_task_fs(pid_t pid, struct parasite_dump_misc *misc, struct cr_fd
>  		return -1;
>  	}
>  
> +	if (get_fd_mntid(fd, &p.mnt_id))
> +		return -1;
> +
>  	if (fd_id_generate_special(&p.stat, &fe.root_id)) {
>  		ret = dump_one_reg_file(fd, fe.root_id, &p);
>  		if (ret < 0)
> @@ -346,10 +367,14 @@ static int dump_filemap(pid_t pid, struct vma_area *vma_area,
>  	BUG_ON(!vma_area->st);
>  	p.stat = *vma_area->st;
>  
> +	if (get_fd_mntid(vma_area->vm_file_fd, &p.mnt_id))
> +		return -1;
> +
>  	/* Flags will be set during restore in get_filemap_fd() */
>  
> -	if (fd_id_generate_special(&p.stat, &id))
> +	if (fd_id_generate_special(&p.stat, &id)) {
>  		ret = dump_one_reg_file(vma_area->vm_file_fd, id, &p);
> +	}
>  
>  	vma->shmid = id;
>  	return ret;
> diff --git a/files.c b/files.c
> index e2ebeb6..cfbbb4b 100644
> --- a/files.c
> +++ b/files.c
> @@ -225,6 +225,7 @@ static int fill_fd_params(struct parasite_ctl *ctl, int fd, int lfd,
>  	p->fd		= fd;
>  	p->pos		= fdinfo.pos;
>  	p->flags	= fdinfo.flags;
> +	p->mnt_id	= fdinfo.mnt_id;
>  	p->pid		= ctl->pid.real;
>  	p->fd_flags	= opts->flags;
>  
> diff --git a/include/files.h b/include/files.h
> index cfa40ac..a18d56e 100644
> --- a/include/files.h
> +++ b/include/files.h
> @@ -46,6 +46,7 @@ struct fd_parms {
>  	FownEntry	fown;
>  	struct fd_link	*link;
>  	long		fs_type;
> +	int		mnt_id;
>  
>  	struct parasite_ctl *ctl;
>  };
> @@ -55,6 +56,7 @@ struct fd_parms {
>  	.fd	= FD_DESC_INVALID,	\
>  	.fown	= FOWN_ENTRY__INIT,	\
>  	.link	= NULL,			\
> +	.mnt_id = -1,			\
>  }
>  
>  extern int fill_fdlink(int lfd, const struct fd_parms *p, struct fd_link *link);
> 




More information about the CRIU mailing list