[CRIU] [PATCH 1/2] sk-unix: Add trivial name resolver for sockets with relative names

Pavel Emelyanov xemul at parallels.com
Wed Jul 29 07:46:55 PDT 2015


OK, applied. Two things to fix on top.

> ---
>  protobuf/sk-unix.proto |   5 ++
>  sk-unix.c              | 161 ++++++++++++++++++++++++++++++++++++++++++++-----
>  2 files changed, 150 insertions(+), 16 deletions(-)
> 
> diff --git a/protobuf/sk-unix.proto b/protobuf/sk-unix.proto
> index 7dd0765c93e1..e2b5c6806138 100644
> --- a/protobuf/sk-unix.proto
> +++ b/protobuf/sk-unix.proto
> @@ -40,4 +40,9 @@ message unix_sk_entry {
>  	optional sk_shutdown		shutdown	= 12;
>  
>  	optional file_perms_entry	file_perms	= 13;
> +
> +	/*
> +	 * Relative socket name may have prefix.
> +	 */
> +	optional bytes			name_dir	= 14;

This field can be string. Bytes is selected for unix sk name since
the name may contain '\0' at the head for anonymous sockets.

>  }
> diff --git a/sk-unix.c b/sk-unix.c
> index d17cc8ebf13e..b789e1439bff 100644
> --- a/sk-unix.c
> +++ b/sk-unix.c
> @@ -34,6 +34,12 @@
>  #undef	LOG_PREFIX
>  #define LOG_PREFIX "sk unix: "
>  
> +typedef struct {
> +	char			*dir;
> +	unsigned int		udiag_vfs_dev;
> +	unsigned int		udiag_vfs_ino;
> +} rel_name_desc_t;
> +
>  struct unix_sk_desc {
>  	struct socket_desc	sd;
>  	unsigned int		type;
> @@ -43,6 +49,7 @@ struct unix_sk_desc {
>  	unsigned int		wqlen;
>  	unsigned int		namelen;
>  	char			*name;
> +	rel_name_desc_t		*rel_name;
>  	unsigned int		nr_icons;
>  	unsigned int		*icons;
>  	unsigned char		shutdown;
> @@ -148,6 +155,71 @@ static int write_unix_entry(struct unix_sk_desc *sk)
>  	return ret;
>  }
>  
> +static int resolve_rel_name(struct unix_sk_desc *sk, const struct fd_parms *p)
> +{
> +	rel_name_desc_t *rel_name = sk->rel_name;
> +	const char *dirs[] = { "cwd", "root" };
> +	struct pstree_item *task;
> +	int mntns_root, i;
> +	struct ns_id *ns;
> +
> +	for_each_pstree_item(task) {
> +		if (task->pid.real == p->pid)

We can safely put pstree_item on fd_parms, but this would require
patching all the call-stack :)

> +			break;
> +	}
> +	if (!task)
> +		return -ENOENT;
> +
> +	ns = lookup_ns_by_id(task->ids->mnt_ns_id, &mnt_ns_desc);
> +	if (!ns)
> +		return -ENOENT;
> +
> +	mntns_root = mntns_get_root_fd(ns);
> +	if (mntns_root < 0)
> +		return -ENOENT;
> +
> +	pr_debug("Resolving relative name %s for socket %x\n",
> +		 sk->name, sk->sd.ino);
> +
> +	for (i = 0; i < ARRAY_SIZE(dirs); i++) {



More information about the CRIU mailing list