[CRIU] Re: [PATCH cr 2/2] sk-inet: restore option REUSEADDR

Pavel Emelyanov xemul at parallels.com
Thu Aug 16 12:43:32 EDT 2012


On 08/16/2012 05:45 PM, Andrey Vagin wrote:
> 
> All sockets are created with SO_REUSEADDR, it's needed for restoring.
> E.g.: A listen socket is created after a connected socket. Both of them
> are binded to one port.
> 
> So SO_REUSEADDR should be restored, when all sockets on a port were created.
> 
> This code creates a structure for each port of one type of sockets
> and accounts a number of sockets, which are not restored yet.
> 
> Sockets have a hook post_open(), in which it waits when all sockets for
> a defined port would be created and then it will restore SO_REUSEADDR.
> 
> struct port contains a type (udp, tcp, etc) and a port number.
> It doesn't contain family or addr, because it's extra loads of logic,
> which doesn't bring a significant profits.
> 
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  include/sk-inet.h      |    2 +
>  protobuf/sk-opts.proto |    1 +
>  sk-inet.c              |   81 ++++++++++++++++++++++++++++++++++++++++++++++--
>  sockets.c              |    9 +++++-
>  4 files changed, 89 insertions(+), 4 deletions(-)
> 

> +static struct inet_port *port_add(int type, int port)
> +{
> +	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;
> +		}
> +
> +	e = shmem + shmem_size;
> +	shmem_size += sizeof(*e);
> +	if (shmem_size > SHMEM_SIZE) {
> +		pr_err("Not enough memory\n");
> +		return NULL;
> +	}

I've pushed the shmalloc helper for this recently. Plz, use one.

> +
> +	e->port = port;
> +	e->type = type;
> +	futex_init(&e->users);
> +	futex_inc(&e->users);
> +
> +	list_add(&e->list, &inet_ports);
> +
> +	return e;
> +}



More information about the CRIU mailing list