libcriu: Add criu_set_root to header

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libcriu: Add simple missing criu_set_ calls

These are just copy the value on RPC message and
do nothing more.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libcriu: Add add_ext_mount_map call

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libcriu: Add add_veth_pair call

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
crtools: Add internal "swrk" action

To help restoring tasks from images as kids to the caller, we can
do the trick.

1. Caller sets himself as child reaper with PR_SET_CHILD_SUBREAPER prctl
2. Caller makes sure criu binary is suid-ed and owned by root
3. Caller forks and calls execv() on criu asking it to restore
4. Criu finishes restore and exits. All its kids get reparented to the
   criu's parent, i.e. -- to the library caller.
5. Caller stops being subreaper

In order to make the execv() and arguments passing simpler I propose
to execv() the service worker function, that accepts options via socket.

This is good for two reasons.

1. We don't have to construct CLI options in libcriu
2. We reuse other service's facilities, such as security checks,
   ability to dump, pre-dump and other stuff

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
lib: Tossing bits around

This is to prepare a send-and-recv routine that works on existing socket.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
lib: Implement the criu_restore_child() call v2

It fully uses the swrk action of criu. The problems, that caller may
have is that the restored tasks die _before_ libcriu's call returns.

v2:
* rename _sub to _child
* unblock sigchild before execl-ing criu

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: A simple test for criu_restore_sub call v2

Which is at the same time the demonstration of how to do the trick.
v2:
* remove stupid sleep 1 synchronization
* run internal version of child, not the external script

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
test: Add test for self dump

It's derived from test.c, but is more self-contained
and explicitly checks for both C and R results.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: Helper for checking child exit status

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: Tune libcriu tests launcher (v2)

v2:
* introduce the run_test helper
* fix overall result detection

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: Clean old libcriu tests

New ones cover more and can be used in Jenkins

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: Rename libcriu run_sub.sh -> run.sh

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: Add lib.c to libcriu tests

Just some common stuff.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libcriu: Add ability to request for notifications from service

This is achieved by supplying the callback. Every time a notification
arrives the callback is called. Return value of 0 means continue,
any other value aborst the request and the value is reported back
to the caller (from criu_dump/criu_restore calls).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: Add test for notifications via libcriu

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libcriu: Ability to fetch arguments from notifications

After a bit more thinking I found a way to fetch arguments
from notifications -- pass opaque value into callback and
provide a set of calls for exploring one.

With this we can

a) provide more data if service supplies additional fields
   in the future
b) not check the action name to decide whether or not the
   requested argument is available

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: Cleanup libcriu tests makefile

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libcriu: Introduce the criu_dump_iters() call

Perform dumping but with preliminary iterations. Each
time an iteration ends the ->more callback is called.
The callback's return value is
	- positive -- one more iteration starts
	- zero     -- final dump is performed and call exits
	- negative -- dump is aborted, the value is returned
back from criu_dump_iters

Inside callback one may (well, should) call criu_set_
function to alter the details of next iterations. In
particluar, then prev and next images directories should
be changed.

The @pi argument is an opaque value that caller may
use to request pre-dump statistics (not yet implemented).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: Test how criu_dump_iters from library works

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