[11/28] ns: Add top_net_ns global variable

Submitted by Kirill Tkhai on June 5, 2017, 5:25 p.m.

Details

Message ID 149668350520.25229.14889623981961915417.stgit@localhost.localdomain
State New
Series "Support sockets leaked to child user_ns task"
Headers show

Commit Message

Kirill Tkhai June 5, 2017, 5:25 p.m.
It will be need for fast obtaining root_item's net_ns,
and to fixup old dumps.

lookup_ns_by_id() can't fail otherwise it'd failed
in MARK_ROOT_NS().

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/include/namespaces.h |    1 +
 criu/namespaces.c         |    2 ++
 2 files changed, 3 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 631d6228a..4e06ebc0f 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -163,6 +163,7 @@  struct ns_id {
 extern struct ns_id *ns_ids;
 extern struct ns_id *top_pid_ns;
 extern struct ns_id *root_user_ns;
+extern struct ns_id *top_net_ns;
 
 #define NS_DESC_ENTRY(_cflag, _str, _alt_str)		\
 	{						\
diff --git a/criu/namespaces.c b/criu/namespaces.c
index d73b2d9f9..ea8e3e391 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -895,6 +895,7 @@  static int set_ns_hookups(struct ns_id *ns)
 
 struct ns_id *top_pid_ns = NULL;
 struct ns_id *root_user_ns = NULL;
+struct ns_id *top_net_ns = NULL;
 /* Mapping NS_ROOT to NS_CRIU */
 UsernsEntry *userns_entry;
 
@@ -2158,6 +2159,7 @@  int set_ns_roots(void)
 	if (MARK_ROOT_NS(ids, net) || MARK_ROOT_NS(ids, ipc) || MARK_ROOT_NS(ids, uts) ||
 	    MARK_ROOT_NS(ids, mnt) || MARK_ROOT_NS(ids, cgroup))
 		return -1;
+	top_net_ns = lookup_ns_by_id(ids->net_ns_id, &net_ns_desc);
 	return 0;
 }
 

Comments

Andrei Vagin June 6, 2017, 5:48 p.m.
On Mon, Jun 05, 2017 at 08:25:05PM +0300, Kirill Tkhai wrote:
> It will be need for fast obtaining root_item's net_ns,
> and to fixup old dumps.
> 
> lookup_ns_by_id() can't fail otherwise it'd failed
> in MARK_ROOT_NS().
> 
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> ---
>  criu/include/namespaces.h |    1 +
>  criu/namespaces.c         |    2 ++
>  2 files changed, 3 insertions(+)
> 
> diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
> index 631d6228a..4e06ebc0f 100644
> --- a/criu/include/namespaces.h
> +++ b/criu/include/namespaces.h
> @@ -163,6 +163,7 @@ struct ns_id {
>  extern struct ns_id *ns_ids;
>  extern struct ns_id *top_pid_ns;
>  extern struct ns_id *root_user_ns;

Pls, add a description what top_net_ns is and how we are going to use
it?

> +extern struct ns_id *top_net_ns;
>  
>  #define NS_DESC_ENTRY(_cflag, _str, _alt_str)		\
>  	{						\
> diff --git a/criu/namespaces.c b/criu/namespaces.c
> index d73b2d9f9..ea8e3e391 100644
> --- a/criu/namespaces.c
> +++ b/criu/namespaces.c
> @@ -895,6 +895,7 @@ static int set_ns_hookups(struct ns_id *ns)
>  
>  struct ns_id *top_pid_ns = NULL;
>  struct ns_id *root_user_ns = NULL;
> +struct ns_id *top_net_ns = NULL;
>  /* Mapping NS_ROOT to NS_CRIU */
>  UsernsEntry *userns_entry;
>  
> @@ -2158,6 +2159,7 @@ int set_ns_roots(void)
>  	if (MARK_ROOT_NS(ids, net) || MARK_ROOT_NS(ids, ipc) || MARK_ROOT_NS(ids, uts) ||
>  	    MARK_ROOT_NS(ids, mnt) || MARK_ROOT_NS(ids, cgroup))
>  		return -1;
> +	top_net_ns = lookup_ns_by_id(ids->net_ns_id, &net_ns_desc);

It is a second lookup of ids->net_ns_id in this function, can we avoid
it?

>  	return 0;
>  }
>  
>
Kirill Tkhai June 6, 2017, 10:11 p.m.
On 06.06.2017 20:48, Andrei Vagin wrote:
> On Mon, Jun 05, 2017 at 08:25:05PM +0300, Kirill Tkhai wrote:
>> It will be need for fast obtaining root_item's net_ns,
>> and to fixup old dumps.
>>
>> lookup_ns_by_id() can't fail otherwise it'd failed
>> in MARK_ROOT_NS().
>>
>> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
>> ---
>>  criu/include/namespaces.h |    1 +
>>  criu/namespaces.c         |    2 ++
>>  2 files changed, 3 insertions(+)
>>
>> diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
>> index 631d6228a..4e06ebc0f 100644
>> --- a/criu/include/namespaces.h
>> +++ b/criu/include/namespaces.h
>> @@ -163,6 +163,7 @@ struct ns_id {
>>  extern struct ns_id *ns_ids;
>>  extern struct ns_id *top_pid_ns;
>>  extern struct ns_id *root_user_ns;
> Pls, add a description what top_net_ns is and how we are going to use
> it?

Ok

>
>> +extern struct ns_id *top_net_ns;
>>  
>>  #define NS_DESC_ENTRY(_cflag, _str, _alt_str)		\
>>  	{						\
>> diff --git a/criu/namespaces.c b/criu/namespaces.c
>> index d73b2d9f9..ea8e3e391 100644
>> --- a/criu/namespaces.c
>> +++ b/criu/namespaces.c
>> @@ -895,6 +895,7 @@ static int set_ns_hookups(struct ns_id *ns)
>>  
>>  struct ns_id *top_pid_ns = NULL;
>>  struct ns_id *root_user_ns = NULL;
>> +struct ns_id *top_net_ns = NULL;
>>  /* Mapping NS_ROOT to NS_CRIU */
>>  UsernsEntry *userns_entry;
>>  
>> @@ -2158,6 +2159,7 @@ int set_ns_roots(void)
>>  	if (MARK_ROOT_NS(ids, net) || MARK_ROOT_NS(ids, ipc) || MARK_ROOT_NS(ids, uts) ||
>>  	    MARK_ROOT_NS(ids, mnt) || MARK_ROOT_NS(ids, cgroup))
>>  		return -1;
>> +	top_net_ns = lookup_ns_by_id(ids->net_ns_id, &net_ns_desc);
> It is a second lookup of ids->net_ns_id in this function, can we avoid
> it?

Sure, thanks

>
>>  	return 0;
>>  }
>>  
>>