page-pipe: Don't increase the page_pipe::nr_pipes if we reuse pipes

The page-pipe buffers may be reused once queued pages are
dumped, but we happen to increase page_pipe::nr_pipes
all the timer, regardless the fact where page buffer
came from.

In worst scenario this may lead to incorrect -EAGAIN returned
from page_pipe_grow forcing calling code to create new
pipes. This is not critical but should be fixed.

In other words page_pipe::nr_pipes must track _really_
created pipes.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
util: use glibc macros to generate device numbers in the dev_t format

Our version of macroses are worng.

Our macros:
#define MINOR(dev)           ((dev) & 0xff)

Glibc function:
return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff);

Reported-by: Amey Deshpande <ameyd@google.com>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mem: add a guard page only if here is enough space for it

Currently we don't add a guard page to a second consecutive growsdonw vma,
even if here is enough space for it. It's wrong. Look at the following test
output:

Execute zdtm/live/static/grow_map03
./grow_map03 --pidfile=grow_map03.pid --outfile=grow_map03.out
Dump 3888
Restore
Test: zdtm/live/static/grow_map03, Result: FAIL
==================================== ERROR ====================================
Test: zdtm/live/static/grow_map03, Namespace:
Dump log   : /root/git/criu/test/dump/grow_map03/3888/1/dump.log
--------------------------------- grep Error ---------------------------------
------------------------------------- END -------------------------------------
Restore log: /root/git/criu/test/dump/grow_map03/3888/1/restore.log
--------------------------------- grep Error ---------------------------------
pie: Error (pie/restorer.c:465): Unable to remap 0x7f0da2c99000 -> 0x7f46425fc000
pie: Error (pie/restorer.c:969): Restorer fail 3888
(00.035621) Error (cr-restore.c:1590): Restoring FAILED.
------------------------------------- END -------------------------------------
================================= ERROR OVER =================================

strace:
mremap(0x7fc3de5b6000, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, 0x7f38dd4e0000) = -1 EINVAL (Invalid argument)

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: add a new test case for growdown vma-s

This test case creates two consecutive grows down vmas with a hole
between them.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>