pstree: Do not populate zero levels of task's pid

Submitted by Kirill Tkhai on June 29, 2017, 11:55 a.m.

Details

Message ID 149873734265.22842.9578888968613871382.stgit@localhost.localdomain
State Accepted
Series "pstree: Do not populate zero levels of task's pid"
Commit d7e14b4bee0b581532d103896dd8fb90483e6b9c
Headers show

Commit Message

Kirill Tkhai June 29, 2017, 11:55 a.m.
If task's pid were hashed before the task itself
(this may happen, when another task has sid or pgid
equal to this pid), the pid mustn't contain zero
levels. So, if pgid or sid has zero levels, we should
not add them.

Otherwise, session04 --iter 3 fails with:

=[log]=> dump/zdtm/static/session04/30/2/restore.log
------------------------ grep Error ------------------------
(01.858187)      6: Restoring children in our session:
(01.858206)      6: Forking task with 303 pid (flags 0x600)
(01.869893)      1: PID: real 145 virt 15
(01.870247)      1: Forking task with 20 pid (flags 0x0)
(01.872948) Error (criu/cr-restore.c:381): 0: Write -1 to sys/kernel/ns_last_pid: Invalid argument
(01.873030) Error (criu/namespaces.c:2664): Can't set next pid
(01.873103)      1: Error (criu/ns-common.c:46): Error answer
(01.873123)      1: Error (criu/cr-restore.c:404): Can't request next pid
(01.873135)      1: Error (criu/cr-restore.c:1321): Can't set next pid
(01.873310)      1: Error (criu/cr-restore.c:1434): Can't fork for 20: No such file or directory

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/pstree.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/pstree.c b/criu/pstree.c
index 9ae191292..c211c1492 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -533,9 +533,9 @@  static struct pid *find_pid_or_place_in_hier(struct rb_node **root, pid_t pid, i
 static struct pid *lookup_create_pid(pid_t *pid, int level, struct pid *pid_node, int ns_id)
 {
 	struct rb_node **new = NULL, *parent = NULL;
-	int i, orig_level = level;
 	struct pid *found;
 	struct ns_id *ns;
+	int i;
 
 	ns = lookup_ns_by_id(ns_id, &pid_ns_desc);
 
@@ -561,11 +561,11 @@  static struct pid *lookup_create_pid(pid_t *pid, int level, struct pid *pid_node
 	if (!pid_node) {
 		struct pstree_item *item;
 
-		item = __alloc_pstree_item(true, orig_level);
+		item = __alloc_pstree_item(true, level);
 		if (item == NULL)
 			return NULL;
 
-		for (i = 0; i < orig_level; i++)
+		for (i = 0; i < level; i++)
 			item->pid->ns[i].virt = pid[i];
 		pid_node = item->pid;
 	}

Comments

Pavel Tikhomirov June 29, 2017, 12:01 p.m.
On 06/29/2017 02:55 PM, Kirill Tkhai wrote:
> If task's pid were hashed before the task itself
> (this may happen, when another task has sid or pgid
> equal to this pid), the pid mustn't contain zero
> levels. So, if pgid or sid has zero levels, we should
> not add them.
> 
> Otherwise, session04 --iter 3 fails with:
> 
> =[log]=> dump/zdtm/static/session04/30/2/restore.log
> ------------------------ grep Error ------------------------
> (01.858187)      6: Restoring children in our session:
> (01.858206)      6: Forking task with 303 pid (flags 0x600)
> (01.869893)      1: PID: real 145 virt 15
> (01.870247)      1: Forking task with 20 pid (flags 0x0)
> (01.872948) Error (criu/cr-restore.c:381): 0: Write -1 to sys/kernel/ns_last_pid: Invalid argument
> (01.873030) Error (criu/namespaces.c:2664): Can't set next pid
> (01.873103)      1: Error (criu/ns-common.c:46): Error answer
> (01.873123)      1: Error (criu/cr-restore.c:404): Can't request next pid
> (01.873135)      1: Error (criu/cr-restore.c:1321): Can't set next pid
> (01.873310)      1: Error (criu/cr-restore.c:1434): Can't fork for 20: No such file or directory
> 
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>

Acked-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

> ---
>   criu/pstree.c |    6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/criu/pstree.c b/criu/pstree.c
> index 9ae191292..c211c1492 100644
> --- a/criu/pstree.c
> +++ b/criu/pstree.c
> @@ -533,9 +533,9 @@ static struct pid *find_pid_or_place_in_hier(struct rb_node **root, pid_t pid, i
>   static struct pid *lookup_create_pid(pid_t *pid, int level, struct pid *pid_node, int ns_id)
>   {
>   	struct rb_node **new = NULL, *parent = NULL;
> -	int i, orig_level = level;
>   	struct pid *found;
>   	struct ns_id *ns;
> +	int i;
>   
>   	ns = lookup_ns_by_id(ns_id, &pid_ns_desc);
>   
> @@ -561,11 +561,11 @@ static struct pid *lookup_create_pid(pid_t *pid, int level, struct pid *pid_node
>   	if (!pid_node) {
>   		struct pstree_item *item;
>   
> -		item = __alloc_pstree_item(true, orig_level);
> +		item = __alloc_pstree_item(true, level);
>   		if (item == NULL)
>   			return NULL;
>   
> -		for (i = 0; i < orig_level; i++)
> +		for (i = 0; i < level; i++)
>   			item->pid->ns[i].virt = pid[i];
>   		pid_node = item->pid;
>   	}
>
Andrey Vagin June 30, 2017, 12:43 a.m.
Applied, thanks

On Thu, Jun 29, 2017 at 02:55:47PM +0300, Kirill Tkhai wrote:
> If task's pid were hashed before the task itself
> (this may happen, when another task has sid or pgid
> equal to this pid), the pid mustn't contain zero
> levels. So, if pgid or sid has zero levels, we should
> not add them.
> 
> Otherwise, session04 --iter 3 fails with:
> 
> =[log]=> dump/zdtm/static/session04/30/2/restore.log
> ------------------------ grep Error ------------------------
> (01.858187)      6: Restoring children in our session:
> (01.858206)      6: Forking task with 303 pid (flags 0x600)
> (01.869893)      1: PID: real 145 virt 15
> (01.870247)      1: Forking task with 20 pid (flags 0x0)
> (01.872948) Error (criu/cr-restore.c:381): 0: Write -1 to sys/kernel/ns_last_pid: Invalid argument
> (01.873030) Error (criu/namespaces.c:2664): Can't set next pid
> (01.873103)      1: Error (criu/ns-common.c:46): Error answer
> (01.873123)      1: Error (criu/cr-restore.c:404): Can't request next pid
> (01.873135)      1: Error (criu/cr-restore.c:1321): Can't set next pid
> (01.873310)      1: Error (criu/cr-restore.c:1434): Can't fork for 20: No such file or directory
> 
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> ---
>  criu/pstree.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/criu/pstree.c b/criu/pstree.c
> index 9ae191292..c211c1492 100644
> --- a/criu/pstree.c
> +++ b/criu/pstree.c
> @@ -533,9 +533,9 @@ static struct pid *find_pid_or_place_in_hier(struct rb_node **root, pid_t pid, i
>  static struct pid *lookup_create_pid(pid_t *pid, int level, struct pid *pid_node, int ns_id)
>  {
>  	struct rb_node **new = NULL, *parent = NULL;
> -	int i, orig_level = level;
>  	struct pid *found;
>  	struct ns_id *ns;
> +	int i;
>  
>  	ns = lookup_ns_by_id(ns_id, &pid_ns_desc);
>  
> @@ -561,11 +561,11 @@ static struct pid *lookup_create_pid(pid_t *pid, int level, struct pid *pid_node
>  	if (!pid_node) {
>  		struct pstree_item *item;
>  
> -		item = __alloc_pstree_item(true, orig_level);
> +		item = __alloc_pstree_item(true, level);
>  		if (item == NULL)
>  			return NULL;
>  
> -		for (i = 0; i < orig_level; i++)
> +		for (i = 0; i < level; i++)
>  			item->pid->ns[i].virt = pid[i];
>  		pid_node = item->pid;
>  	}
>