[1/3] ns: Override fake pid in rst_add_ns_id()

Submitted by Kirill Tkhai on Feb. 28, 2017, 1:41 p.m.

Details

Message ID 148828930313.1058.2875797885640652995.stgit@localhost.localdomain
State New
Series "Fix "NS_ROOT is not assigned""
Headers show

Commit Message

Kirill Tkhai Feb. 28, 2017, 1:41 p.m.
During reading of ns file, we add namespaces with fake pid -1.
Allow to override it later with real pid of a process.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/namespaces.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/namespaces.c b/criu/namespaces.c
index 992cd17e0..b1e65df43 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -320,7 +320,7 @@  int rst_add_ns_id(unsigned int id, struct pstree_item *i, struct ns_desc *nd)
 
 	nsid = lookup_ns_by_id(id, nd);
 	if (nsid) {
-		if (pid_rst_prio(pid, nsid->ns_pid))
+		if (nsid->ns_pid == -1 || pid_rst_prio(pid, nsid->ns_pid))
 			nsid->ns_pid = pid;
 		return 0;
 	}

Comments

Andrey Vagin March 1, 2017, 1:01 a.m.
On Tue, Feb 28, 2017 at 04:41:43PM +0300, Kirill Tkhai wrote:
> During reading of ns file, we add namespaces with fake pid -1.
> Allow to override it later with real pid of a process.
> 
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> ---
>  criu/namespaces.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/criu/namespaces.c b/criu/namespaces.c
> index 992cd17e0..b1e65df43 100644
> --- a/criu/namespaces.c
> +++ b/criu/namespaces.c
> @@ -320,7 +320,7 @@ int rst_add_ns_id(unsigned int id, struct pstree_item *i, struct ns_desc *nd)
>  
>  	nsid = lookup_ns_by_id(id, nd);
>  	if (nsid) {
> -		if (pid_rst_prio(pid, nsid->ns_pid))
> +		if (nsid->ns_pid == -1 || pid_rst_prio(pid, nsid->ns_pid))

Where is ns_pid used on restore?

>  			nsid->ns_pid = pid;
>  		return 0;
>  	}
>
Kirill Tkhai March 1, 2017, 9:13 a.m.
On 01.03.2017 04:01, Andrei Vagin wrote:
> On Tue, Feb 28, 2017 at 04:41:43PM +0300, Kirill Tkhai wrote:
>> During reading of ns file, we add namespaces with fake pid -1.
>> Allow to override it later with real pid of a process.
>>
>> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
>> ---
>>  criu/namespaces.c |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/criu/namespaces.c b/criu/namespaces.c
>> index 992cd17e0..b1e65df43 100644
>> --- a/criu/namespaces.c
>> +++ b/criu/namespaces.c
>> @@ -320,7 +320,7 @@ int rst_add_ns_id(unsigned int id, struct pstree_item *i, struct ns_desc *nd)
>>  
>>  	nsid = lookup_ns_by_id(id, nd);
>>  	if (nsid) {
>> -		if (pid_rst_prio(pid, nsid->ns_pid))
>> +		if (nsid->ns_pid == -1 || pid_rst_prio(pid, nsid->ns_pid))
> 
> Where is ns_pid used on restore?

I see it in mount's code. But you should know better the reason of why we need rst prio here...

commit eac462922cd3a461e1688191c59bd9f17e4b6ed6
Author: Andrey Vagin <avagin@openvz.org>
Date:   Mon Apr 21 18:23:14 2014 +0400

   restore: add mount id-s in the ns_ids list (v4)
   
   Currently ns_ids list is filled only on dump. Soon we'll need this
   list for mount namespaces on restore, e.g. to know which tasks share
   the namespaces.
   
   v2: merge the patch "namespace: add a function to search an ns_id
   item by id" into this one.
   v3: add prefix rst_ to add_ns_id
   v4: look up namespace by two values -- type AND ID
   
   Signed-off-by: Andrey Vagin <avagin@openvz.org>
   Signed-off-by: Pavel Emelyanov <xemul@parallels.com>

I just restore the behavior we had before nested user ns.