[CRIU] [PATCH 27/28] files: Add new master to file_desc if owners of existing fles have no permissions

Andrei Vagin avagin at virtuozzo.com
Tue Jun 6 22:17:34 MSK 2017


On Mon, Jun 05, 2017 at 08:27:24PM +0300, Kirill Tkhai wrote:
> Iterate over fake_master_head and add a fake fake fle of root_item,
> which becomes new master and have permissions to restore file_desc.
> 
> Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
> ---
>  criu/cr-restore.c    |    5 +++++
>  criu/files.c         |   31 +++++++++++++++++++++++++++++++
>  criu/include/files.h |    1 +
>  3 files changed, 37 insertions(+)
> 
> diff --git a/criu/cr-restore.c b/criu/cr-restore.c
> index 88a9c50a5..9f69cd9bd 100644
> --- a/criu/cr-restore.c
> +++ b/criu/cr-restore.c
> @@ -348,6 +348,11 @@ static int root_prepare_shared(void)
>  	if (ret)
>  		goto err;
>  
> +	/* This func may add new files, so it must be called before post prepare */
> +	ret = add_fake_fds_masters();
> +	if (ret)
> +		goto err;
> +
>  	ret = run_post_prepare();
>  	if (ret)
>  		goto err;
> diff --git a/criu/files.c b/criu/files.c
> index b66217c02..0282b782c 100644
> --- a/criu/files.c
> +++ b/criu/files.c
> @@ -1742,3 +1742,34 @@ int open_transport_socket(void)
>  out:
>  	return ret;
>  }
> +
> +int add_fake_fds_masters(void)
> +{
> +	struct fdinfo_list_entry *fle;
> +	struct file_desc *fdesc, *tmp;
> +	FdinfoEntry *fe;
> +	int fd;
> +
> +	list_for_each_entry_safe(fdesc, tmp, &fake_master_head, fake_master_list) {
> +		fle = list_first_entry(&fdesc->fd_info_head,
> +				       struct fdinfo_list_entry, desc_list);
> +		/*
> +		 * All masters are created in root_item for now.
> +		 * Distribute them over pstree if someone reports,
> +		 * their number is too big, or you want support
> +		 * file->user_ns.
> +		 */
> +		fd = find_unused_fd(root_item, -1);

why do we need to allocate a file descriptor for a fake master?

We need to open it and send to other processes, then we can close it.
Looks like this descriptor doesn't have to live long time.

> +		fe = dup_fdinfo(fle->fe, fd, fle->fe->flags);
> +		if (!fe)
> +			goto err;
> +
> +		if (collect_fd(vpid(root_item), fe, rsti(root_item), true))
> +			goto err;
> +	}
> +	BUG_ON(!list_empty(&fake_master_head));
> +	return 0;
> +err:
> +	pr_err("Can't prepare fds masters\n");
> +	return -1;
> +}
> diff --git a/criu/include/files.h b/criu/include/files.h
> index 812ef8947..6f651827b 100644
> --- a/criu/include/files.h
> +++ b/criu/include/files.h
> @@ -151,6 +151,7 @@ extern int rst_file_params(int fd, FownEntry *fown, int flags);
>  
>  extern void show_saved_files(void);
>  
> +extern int add_fake_fds_masters(void);
>  extern int prepare_fds(struct pstree_item *me);
>  extern int prepare_fd_pid(struct pstree_item *me);
>  extern int prepare_ctl_tty(int pid, struct rst_info *rst_info, u32 ctl_tty_id);
> 


More information about the CRIU mailing list