[RFC,v2,3/5] zdtm: add reset_pid() function

Submitted by Adrian Reber on March 23, 2017, 7:59 p.m.

Details

Message ID 1490299158-12933-4-git-send-email-adrian@lisas.de
State Accepted
Series "zdtm: also dump and restore tests with --check-only"
Commit f915df11ca5e502836d9a4ee4df30b604cc5e180
Headers show

Commit Message

Adrian Reber March 23, 2017, 7:59 p.m.
From: Adrian Reber <areber@redhat.com>

In preparation for the zdtm option '--check-only' a new helper function
reset_pid() is added which writes to ns_last_pid to avoid PID collisions
during check-only restore and the real restore.

Signed-off-by: Adrian Reber <areber@redhat.com>
---
 test/zdtm.py | 7 +++++++
 1 file changed, 7 insertions(+)

Patch hide | download patch | download mbox

diff --git a/test/zdtm.py b/test/zdtm.py
index 57e2ab0..8d38e05 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -329,6 +329,13 @@  def wait_pid_die(pid, who, tmo = 30):
 def test_flag(tdesc, flag):
 	return flag in tdesc.get('flags', '').split()
 
+
+def reset_pid(pid = 1):
+	fd = open('/proc/sys/kernel/ns_last_pid', 'w')
+	fd.write('%s' % pid)
+	fd.close()
+
+
 #
 # Exception thrown when something inside the test goes wrong,
 # e.g. test doesn't start, criu returns with non zero code or

Comments

Andrey Vagin March 24, 2017, 12:10 a.m.
On Thu, Mar 23, 2017 at 07:59:16PM +0000, Adrian Reber wrote:
> From: Adrian Reber <areber@redhat.com>
> 
> In preparation for the zdtm option '--check-only' a new helper function
> reset_pid() is added which writes to ns_last_pid to avoid PID collisions
> during check-only restore and the real restore.
> 
> Signed-off-by: Adrian Reber <areber@redhat.com>
> ---
>  test/zdtm.py | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/test/zdtm.py b/test/zdtm.py
> index 57e2ab0..8d38e05 100755
> --- a/test/zdtm.py
> +++ b/test/zdtm.py
> @@ -329,6 +329,13 @@ def wait_pid_die(pid, who, tmo = 30):
>  def test_flag(tdesc, flag):
>  	return flag in tdesc.get('flags', '').split()
>  
> +
> +def reset_pid(pid = 1):

I don't understand how pid = 1 helps to avoid collisions. We create a
new pid namespace for each test (test/zdtm_ct) and we know that pids are
allocated sequentialy, so test process uses
"small" pids. In this case setting 1 into ns_last_pid has to increate
probability of collisions...


> +	fd = open('/proc/sys/kernel/ns_last_pid', 'w')
> +	fd.write('%s' % pid)
> +	fd.close()
> +
> +
>  #
>  # Exception thrown when something inside the test goes wrong,
>  # e.g. test doesn't start, criu returns with non zero code or
> -- 
> 1.8.3.1
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
Adrian Reber April 4, 2017, 9:23 a.m.
On Thu, Mar 23, 2017 at 05:10:12PM -0700, Andrei Vagin wrote:
> On Thu, Mar 23, 2017 at 07:59:16PM +0000, Adrian Reber wrote:
> > From: Adrian Reber <areber@redhat.com>
> > 
> > In preparation for the zdtm option '--check-only' a new helper function
> > reset_pid() is added which writes to ns_last_pid to avoid PID collisions
> > during check-only restore and the real restore.
> > 
> > Signed-off-by: Adrian Reber <areber@redhat.com>
> > ---
> >  test/zdtm.py | 7 +++++++
> >  1 file changed, 7 insertions(+)
> > 
> > diff --git a/test/zdtm.py b/test/zdtm.py
> > index 57e2ab0..8d38e05 100755
> > --- a/test/zdtm.py
> > +++ b/test/zdtm.py
> > @@ -329,6 +329,13 @@ def wait_pid_die(pid, who, tmo = 30):
> >  def test_flag(tdesc, flag):
> >  	return flag in tdesc.get('flags', '').split()
> >  
> > +
> > +def reset_pid(pid = 1):
> 
> I don't understand how pid = 1 helps to avoid collisions. We create a
> new pid namespace for each test (test/zdtm_ct) and we know that pids are
> allocated sequentialy, so test process uses
> "small" pids. In this case setting 1 into ns_last_pid has to increate
> probability of collisions...

The following tests fail in --check-only mode if I do not reset the PID
back to 1:

 * zdtm/static/zombie00(h)
 * zdtm/static/sched_prio00(h)
 * zdtm/static/pthread00(h)
 * zdtm/static/sigpending(h)
 * zdtm/static/fdt_shared(h)
 * zdtm/transition/epoll(h)
 * zdtm/transition/fork(h)
 * zdtm/transition/fork2(h)
 * zdtm/transition/maps008(h)
 * zdtm/transition/pipe_loop00(h)
 * zdtm/transition/socket_loop00(h)
 * zdtm/transition/unix_sock(h)
 * zdtm/transition/fifo_loop(h)
 * zdtm/transition/pipe_shared00(h)
 * zdtm/transition/file_read(h)

The test restore and the real restore are running in the same PID
namespace. For those testcases the real restore fails with a PID
collision:

(00.004419) Error (criu/cr-restore.c:1353): Pid 25 do not match expected 24

Resetting it to '1' helps.

		Adrian