[v2,04/15] unix: Link all sockets in unix_sockets list

Submitted by Kirill Tkhai on May 27, 2016, 1:06 p.m.

Details

Message ID 146435437296.31234.12048176072457772117.stgit@pro
State Rejected
Series "Support for packet's msg_name in receive queue of promiscous DGRAM sockets"
Headers show

Commit Message

Kirill Tkhai May 27, 2016, 1:06 p.m.
List "unix_sockets" is used to link external sockets.
Change this, to link all unix sockets there. To differ
really external sockets in fix_external_unix_sockets(),
we may check for socket's already_dumped value.

This may be useful to traverse over all unix sockets
in a namespace.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/sk-unix.c |   13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index 3363cea..40cb9db 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -364,11 +364,7 @@  static int dump_one_unix_fd(int lfd, u32 id, const struct fd_parms *p)
 		 * until all sockets the program owns are processed.
 		 */
 		if (!peer->sd.already_dumped) {
-			if (list_empty(&peer->list)) {
-				show_one_unix("Add a peer", peer);
-				list_add_tail(&peer->list, &unix_sockets);
-			}
-
+			show_one_unix("Add a peer", peer);
 			list_add(&sk->peer_node, &peer->peer_list);
 			sk->fd = dup(lfd);
 			if (sk->fd < 0) {
@@ -464,7 +460,6 @@  static int dump_one_unix_fd(int lfd, u32 id, const struct fd_parms *p)
 	if (list_empty(&sk->peer_node) && write_unix_entry(sk))
 		return -1;
 
-	list_del_init(&sk->list);
 	sk->sd.already_dumped = 1;
 
 	while (!list_empty(&sk->peer_list)) {
@@ -677,6 +672,7 @@  static int unix_collect_one(const struct unix_diag_msg *m,
 	}
 
 	sk_collect_one(m->udiag_ino, AF_UNIX, &d->sd);
+	list_add_tail(&d->list, &unix_sockets);
 	show_one_unix("Collected", d);
 
 	return 0;
@@ -757,9 +753,10 @@  int fix_external_unix_sockets(void)
 		FownEntry fown = FOWN_ENTRY__INIT;
 		SkOptsEntry skopts = SK_OPTS_ENTRY__INIT;
 
-		show_one_unix("Dumping extern", sk);
+		if (sk->sd.already_dumped)
+			continue;
 
-		BUG_ON(sk->sd.already_dumped);
+		show_one_unix("Dumping extern", sk);
 
 		fd_id_generate_special(NULL, &e.id);
 		e.ino		= sk->sd.ino;

Comments

Pavel Emelyanov May 30, 2016, 11:38 a.m.
On 05/27/2016 04:06 PM, Kirill Tkhai wrote:
> List "unix_sockets" is used to link external sockets.

Dump-time. On restore time this list already contains all the sockets.

> Change this, to link all unix sockets there. To differ
> really external sockets in fix_external_unix_sockets(),
> we may check for socket's already_dumped value.
> 
> This may be useful to traverse over all unix sockets
> in a namespace.

Dump-time.
Please, explain why do you need to traverse all unix sockets dump time.

> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> ---
>  criu/sk-unix.c |   13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/criu/sk-unix.c b/criu/sk-unix.c
> index 3363cea..40cb9db 100644
> --- a/criu/sk-unix.c
> +++ b/criu/sk-unix.c
> @@ -364,11 +364,7 @@ static int dump_one_unix_fd(int lfd, u32 id, const struct fd_parms *p)
>  		 * until all sockets the program owns are processed.
>  		 */
>  		if (!peer->sd.already_dumped) {
> -			if (list_empty(&peer->list)) {
> -				show_one_unix("Add a peer", peer);
> -				list_add_tail(&peer->list, &unix_sockets);
> -			}
> -
> +			show_one_unix("Add a peer", peer);
>  			list_add(&sk->peer_node, &peer->peer_list);
>  			sk->fd = dup(lfd);
>  			if (sk->fd < 0) {
> @@ -464,7 +460,6 @@ static int dump_one_unix_fd(int lfd, u32 id, const struct fd_parms *p)
>  	if (list_empty(&sk->peer_node) && write_unix_entry(sk))
>  		return -1;
>  
> -	list_del_init(&sk->list);
>  	sk->sd.already_dumped = 1;
>  
>  	while (!list_empty(&sk->peer_list)) {
> @@ -677,6 +672,7 @@ static int unix_collect_one(const struct unix_diag_msg *m,
>  	}
>  
>  	sk_collect_one(m->udiag_ino, AF_UNIX, &d->sd);
> +	list_add_tail(&d->list, &unix_sockets);
>  	show_one_unix("Collected", d);
>  
>  	return 0;
> @@ -757,9 +753,10 @@ int fix_external_unix_sockets(void)
>  		FownEntry fown = FOWN_ENTRY__INIT;
>  		SkOptsEntry skopts = SK_OPTS_ENTRY__INIT;
>  
> -		show_one_unix("Dumping extern", sk);
> +		if (sk->sd.already_dumped)
> +			continue;
>  
> -		BUG_ON(sk->sd.already_dumped);
> +		show_one_unix("Dumping extern", sk);
>  
>  		fd_id_generate_special(NULL, &e.id);
>  		e.ino		= sk->sd.ino;
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
> .
>
Kirill Tkhai May 30, 2016, 12:21 p.m.
On 30.05.2016 14:38, Pavel Emelyanov wrote:
> On 05/27/2016 04:06 PM, Kirill Tkhai wrote:
>> List "unix_sockets" is used to link external sockets.
> 
> Dump-time. On restore time this list already contains all the sockets.
> 
>> Change this, to link all unix sockets there. To differ
>> really external sockets in fix_external_unix_sockets(),
>> we may check for socket's already_dumped value.
>>
>> This may be useful to traverse over all unix sockets
>> in a namespace.
> 
> Dump-time.
> Please, explain why do you need to traverse all unix sockets dump time.

We need to dump a sender inode for every DGRAM packet, and it's used on restore.
Received skb does not contain this information: it contains the sender's name
as string.

Dumping of (int) requires less space than dumping a string.

>> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
>> ---
>>  criu/sk-unix.c |   13 +++++--------
>>  1 file changed, 5 insertions(+), 8 deletions(-)
>>
>> diff --git a/criu/sk-unix.c b/criu/sk-unix.c
>> index 3363cea..40cb9db 100644
>> --- a/criu/sk-unix.c
>> +++ b/criu/sk-unix.c
>> @@ -364,11 +364,7 @@ static int dump_one_unix_fd(int lfd, u32 id, const struct fd_parms *p)
>>  		 * until all sockets the program owns are processed.
>>  		 */
>>  		if (!peer->sd.already_dumped) {
>> -			if (list_empty(&peer->list)) {
>> -				show_one_unix("Add a peer", peer);
>> -				list_add_tail(&peer->list, &unix_sockets);
>> -			}
>> -
>> +			show_one_unix("Add a peer", peer);
>>  			list_add(&sk->peer_node, &peer->peer_list);
>>  			sk->fd = dup(lfd);
>>  			if (sk->fd < 0) {
>> @@ -464,7 +460,6 @@ static int dump_one_unix_fd(int lfd, u32 id, const struct fd_parms *p)
>>  	if (list_empty(&sk->peer_node) && write_unix_entry(sk))
>>  		return -1;
>>  
>> -	list_del_init(&sk->list);
>>  	sk->sd.already_dumped = 1;
>>  
>>  	while (!list_empty(&sk->peer_list)) {
>> @@ -677,6 +672,7 @@ static int unix_collect_one(const struct unix_diag_msg *m,
>>  	}
>>  
>>  	sk_collect_one(m->udiag_ino, AF_UNIX, &d->sd);
>> +	list_add_tail(&d->list, &unix_sockets);
>>  	show_one_unix("Collected", d);
>>  
>>  	return 0;
>> @@ -757,9 +753,10 @@ int fix_external_unix_sockets(void)
>>  		FownEntry fown = FOWN_ENTRY__INIT;
>>  		SkOptsEntry skopts = SK_OPTS_ENTRY__INIT;
>>  
>> -		show_one_unix("Dumping extern", sk);
>> +		if (sk->sd.already_dumped)
>> +			continue;
>>  
>> -		BUG_ON(sk->sd.already_dumped);
>> +		show_one_unix("Dumping extern", sk);
>>  
>>  		fd_id_generate_special(NULL, &e.id);
>>  		e.ino		= sk->sd.ino;
>>
>> _______________________________________________
>> CRIU mailing list
>> CRIU@openvz.org
>> https://lists.openvz.org/mailman/listinfo/criu
>> .
>>
>