[CRIU] [PATCH RFC 22/30] inet: Link sockets in port_type list

Pavel Emelyanov xemul at virtuozzo.com
Tue Nov 8 05:07:46 PST 2016


Comment is needed here.

On 11/01/2016 05:33 PM, Kirill Tkhai wrote:
> Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
> ---
>  criu/include/sk-inet.h |    1 +
>  criu/sk-inet.c         |   11 ++++++++---
>  2 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/criu/include/sk-inet.h b/criu/include/sk-inet.h
> index a06a8ac..cce2ea2 100644
> --- a/criu/include/sk-inet.h
> +++ b/criu/include/sk-inet.h
> @@ -41,6 +41,7 @@ struct inet_sk_info {
>  	InetSkEntry *ie;
>  	struct file_desc d;
>  	struct inet_port *port;
> +	struct list_head port_list;
>  	/*
>  	 * This is an fd by which the socket is opened.
>  	 * It will be carried down to restorer code to
> diff --git a/criu/sk-inet.c b/criu/sk-inet.c
> index 924cf8c..6a0a2d2 100644
> --- a/criu/sk-inet.c
> +++ b/criu/sk-inet.c
> @@ -32,19 +32,21 @@ static LIST_HEAD(inet_ports);
>  struct inet_port {
>  	int port;
>  	int type;
> +	struct list_head type_list;
>  	futex_t users;
>  	mutex_t reuseaddr_lock;
>  	struct list_head list;
>  };
>  
> -static struct inet_port *port_add(int type, int port)
> +static struct inet_port *port_add(struct inet_sk_info *ii, int port)
>  {
> +	int type = ii->ie->type;
>  	struct inet_port *e;
>  
>  	list_for_each_entry(e, &inet_ports, list)
>  		if (e->type == type && e->port == port) {
>  			futex_inc(&e->users);
> -			return e;
> +			goto out_link;
>  		}
>  
>  	e = shmalloc(sizeof(*e));
> @@ -58,8 +60,11 @@ static struct inet_port *port_add(int type, int port)
>  	futex_init(&e->users);
>  	futex_inc(&e->users);
>  	mutex_init(&e->reuseaddr_lock);
> +	INIT_LIST_HEAD(&e->type_list);
>  
>  	list_add(&e->list, &inet_ports);
> +out_link:
> +	list_add(&ii->port_list, &e->type_list);
>  
>  	return e;
>  }
> @@ -470,7 +475,7 @@ static int collect_one_inetsk(void *o, ProtobufCMessage *base, struct cr_img *i)
>  	 * so a value of SO_REUSEADDR can be restored after restoring all
>  	 * sockets.
>  	 */
> -	ii->port = port_add(ii->ie->type, ii->ie->src_port);
> +	ii->port = port_add(ii, ii->ie->src_port);
>  	if (ii->port == NULL)
>  		return -1;
>  
> 
> .
> 



More information about the CRIU mailing list