[CRIU] Re: [PATCH cr 3/8] tcp: unset TCP_REPAIR at the last moment after unlocking network

Andrew Vagin avagin at parallels.com
Thu Sep 13 19:37:21 EDT 2012


On Fri, Sep 14, 2012 at 03:20:13PM +0400, Pavel Emelyanov wrote:
> On 09/14/2012 02:25 PM, Andrey Vagin wrote:
> > TCP_REPAIR should be droppet when a network is unlocked.
> > A network should be unlocked at the last moment, because
> > after this moment restore must not failed, otherwise a state of
> > a tcp connection can be changed and a state of one side in our image
> > will be invalid.
> > 
> > Signed-off-by: Andrey Vagin <avagin at openvz.org>
...
> >  
> >  int check_tcp_repair(void);
> > +
> > +extern int rst_tcp_socks_size;
> > +extern int rst_tcp_socks_remap(void *addr);
> > +
> > +static inline void rst_tcp_socks_all(int *arr, int size)
> 
> Why in header?
because will be used in restorer. I can move it in restorer.c
> 
> > +{
> > +	int i;
> > +
> > +	for (i =0; i < size / sizeof(int) && arr[i] >= 0; i++)
> 
> Why &&? Let's make a single end-of-array condition
> (the arr[i] < 0 one looks nicer).
I did not want to allocate a new page for "-1".
Ok, I will do that.
> 
> > +		tcp_repair_off(arr[i]);
> > +
...
> > +
> > +static int rst_tcp_socks_add(int fd)
> > +{
> > +	if (rst_tcp_socks == NULL) {
> > +		rst_tcp_socks_size += PAGE_SIZE;
> > +		rst_tcp_socks = mmap(NULL, rst_tcp_socks_size,
> > +					    PROT_WRITE | PROT_READ,
> > +					    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> > +	}
> > +
> > +	if ((rst_tcp_socks_num + 1) * sizeof(int) > rst_tcp_socks_size) {
> > +		rst_tcp_socks = mremap(rst_tcp_socks,
> > +						rst_tcp_socks_size,
> > +						rst_tcp_socks_size + PAGE_SIZE,
> > +						MREMAP_MAYMOVE);
> > +		rst_tcp_socks_size += PAGE_SIZE;
> > +	}
> 
> I heavily doubt that a task will have more than 1 page of inet socket descriptors :)
> Let's not overkill on this and use xrealloc() and mmap+memcpy in rst_tcp_socks_remap.
Hmmmm. I am not sure, that it will be simpler.
> 
> > +
> > +	if (rst_tcp_socks == MAP_FAILED) {
> > +		pr_perror("Can't allocate memory\n");
> > +		return -1;
> > +	}
> > +
> > +	rst_tcp_socks[rst_tcp_socks_num++] = fd;
> > +	return 0;
> > +}
> > +
> >  int restore_one_tcp(int fd, struct inet_sk_info *ii)
> >  {
> >  	pr_info("Restoring TCP connection\n");
> > @@ -480,6 +541,9 @@ int restore_one_tcp(int fd, struct inet_sk_info *ii)
> >  	if (tcp_repair_on(fd))
> >  		return -1;
> >  
> > +	if (rst_tcp_socks_add(fd))
> > +		return -1;
> > +
> >  	nf_unlock_connection_info(ii);
> >  
> >  	if (restore_tcp_conn_state(fd, ii))
> 


More information about the CRIU mailing list