[CRIU] [PATCH 8/9] files: Add c/r for /proc/$pid/ns/$ids references

Pavel Emelyanov xemul at parallels.com
Fri May 17 09:57:32 EDT 2013


On 05/17/2013 05:20 PM, Cyrill Gorcunov wrote:
> 
> In this commit we implement c/r for files which have opened
> /proc/$pid/ns/$ids entries.
> 
> The idea is rather simple one
> 
> Checkpoint
> ==========
> 
> - Check if the file name is the one of known to be ns ref
> - If match then use generate_ns_id helper to generate namespace
>   ids (note if the ids came from nested namespace we issue error
>   out because it's not yet supported by criu)
> - Write protobuf entry
> 
> Restore
> =======
> 
> - Read all ns entries from the image
> - When criu tries to open one we lookup over process
>   tree to figure out which PID should be used in path
>   and then just open it.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  cr-restore.c         |   3 ++
>  files.c              |   5 +--
>  include/files.h      |   2 +
>  include/namespaces.h |   3 ++
>  namespaces.c         | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 131 insertions(+), 3 deletions(-)
> 


> +int dump_one_ns_file(int lfd, u32 id, const struct fd_parms *p)
> +{
> +	int fd = fdset_fd(glob_fdset, CR_FD_NS_FILES);
> +	NsFileEntry nfe = NS_FILE_ENTRY__INIT;
> +	struct ns_proc_entry *entry = p->arg;
> +
> +	nfe.id		= id;
> +	nfe.ns_id	= generate_ns_id(p->pid, (unsigned int)entry->i_ino, entry->d);



> +	nfe.type	= entry->type;

The nfe.type is write-only field in this patch. Not nice.

> +	nfe.flags	= p->flags;
> +
> +	if (!nfe.ns_id) {
> +		pr_err("Can't generate id for ns `%s' referred by fd %d (pid %d)\n",
> +		       entry->d->str, p->fd, p->pid);
> +		return -1;
> +	}
> +
> +	return pb_write_one(fd, &nfe, PB_NS_FILES);
> +}

> +int collect_ns_files(void)
> +{
> +	if (access_image(CR_FD_NS_FILES, F_OK) == 0)
> +		return collect_image(CR_FD_NS_FILES, PB_NS_FILES,
> +				     sizeof(struct ns_file_info),
> +				     collect_one_nsfile);
> +	return 0;
> +}
> +

Other "optional" images are collected w/o access_image by simply checking
the errno. Plz, use the same way.

> @@ -277,9 +277,8 @@ static int dump_one_file(struct parasite_ctl *ctl, int fd, int lfd, struct fd_op
>  		 * entry thus choose which strategy to dump it with.
>  		 */
>  		if (parse_ns_proc(&p.link->name[1], p.link->len - 1, &found) == 0) {
> -			pr_err("Dumping procfs namespace reference "
> -			       "is not yet implemented\n");
> -			return -1;
> +			p.arg = &found;
> +			return dump_ns_file(&p, lfd, fdinfo);

Internally dump_ns_file will call generate_ns_id. And your patch #6 does the same --
splits this logic into two calls -- parse_ns_proc and generate_ns_id. Why not have
a single function, that will just provide you ns ID if it's namespace link?

>  		}
>  
>  		return dump_reg_file(&p, lfd, fdinfo);



More information about the CRIU mailing list