test: Add tar + bzip2 testsuite

Generate a pseudorandom tree of files, run tar cjf on it
to create referenced tarball, then run the same again on
the background, wait for a while, then checkpoint and restore
it and compare that two tarballs do not differ.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Add missing new lines

Otherwise output looks like

Dumping core (pid: 16953)
----------------------------------------
Dumping GP/FPU registers ... OK
Obtainting personality ... OK
Obtainting task auvx ... Dumping path for 1 fd via self 19 [/home/crtools/test/legacy/test-inotify]
Dumping header ... ----------------------------------------

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sockets: Mark open_unix_sk static

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
show: Move extern print_data declaration from sockets.c to header

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: Remove unused struct shmem_id and variables

Most likely they left from Andrey's shmem rework.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sockets: Fix potential NULL dereference

In case if unix socket was not found don't call for container_of.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sock: Add udp-lite sockets support

This is trivial. Just copy-n-paste pieces from the udp dumping
and restoring code. The zdtm test is also a compy of the _udp
test with respecitve changes.

Reuired for httpd, this one uses udplite sockets.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
util: Add fn for copying file from one fd to another

Will be required to dump completely unlinked files.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Support dumping/restoring of completely unlinked files

Completely unlinked file is the one with n_link count being zero.
Such files only allow to read their contents and carry with us.

In order to dump this thing I introduce the "path remap" technology.
For reg file a remapping entry is dumped which describes, that at
restore stage before opening a regfile->path this path should be
linked to some other name and then (after open) unlinked.

For completely unlinked files the remap path would be a path to
a "ghost" file, i.e. a file which is created only at the time of
restore and which is removed completely at the end of it.

Partially unlinked files (i.e. those having n_link != 0, but a
path by which we see them in someone's fd is not accessible) should
be handled in another way.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: Tests for testing completely unlinked files

This includes existing test and a new one, checking that
unlinked hardlinks are handled properly.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sockets: Print sockets ino and peer with %x format

Some ino/peers are printed with %d, some with %x,
get rid of it and print all in %x.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
magics: Move them one tab right

To line the constants up.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: Temporary comment out exit's on sid/pgid mismatch

Util we have kernel support.
[ xemul: MySQL uses runaway pgid and sid and we cannot restore it
  gracefully with exiting API :( Byt MySQL seem not to care about
  pgid and sid change after restore, so ignore this for a while ]

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restorer: Make sure the protection on code/data mm areas do fit the kernel requirements

When set up mm::code/data addresses the kernel expects
the correspond VMAs to have predefined protection, but
task might have dropped or mprotected those VMAs at moment
of checkpoint. So just setup fake VMAs, call prctl and
munmap them immediately.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sockets: Drop one-line alignment block

Make sense in multiline cases only.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
output: add "0x" to hex prints using sed

Command below was executed several times:

sed 's/\(pr_.*[^%,x,X]\)\(\%[0-9,l,L]*x\)/\10x\2/g' -i *.c

Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
output: add "0x" to hex prints manually

Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
util: Extend reopen_fd_as_safe

Our loggin engine prints file:line only at invoke point,
so it's unable to see where exactly reopen_fd_as_safe is
failed.

With this patch the output is more human readable

 | Error (util.c:96): fd 7 already in use (called at files.c:359)

Ideally we need full backtrace here, but it's different task.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Sanitize message on fd restoring

The message "Got fd for %d" is non-informative,
change it to "Restoring fd %d" since that is
what function does.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
crtools: Rewrite options parsing via while

This avoids two duplicate lines.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>