service: Helper for sending generic RPC errors

We'll need such further.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
pre-dump: Enforce track-mem and leave-running in cr_pre_dump_tasks

Service will call the pre-dump routine, so this is factoring out
enforcin options for CLI and RPC.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
daemon: Write own daemon routine

RPC will start page-server daemon and needs to get the
controll back to report back to caller, but the glibc's
daemon() does exit() in parent context preventing it.

Thus -- introduce own daemonizing routine.

Strictly speaking, this is not pure daemon() clone, as the
parent process has to exit himself. But this is OK for now.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
page-server: Start using new cr_daemon routine

After this the called of cr_page_server gets controll
back with the server's pid.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rpc: Add more stuff to RPC messages

This includes pre-dump and page-server actions and
arguments for memory tracking and page-server.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rpc: Introduce CLI's --action-script analogue

Service shouldn't call client provided scripts, as it
creates a security issue (client may be unpriviledged,
while the service is).

In order to let caller do what it would normally do with
criu-scripts, make criu notify it about scripts. Caller
then do whatever it needs and responds back.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
service: Start page-server request implementation

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
service: Implement pre-dump request support

This works as multi-req thing -- caller issues the
pre-dump request, criu serves it and sends result back.
Then service waits for the next request on the same
session, client doesn't have to re-connect back.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
proc-parse: Parse pid's fdinfo entries

The existing code opens "self" and parses what's in there,
just twist the code a little to accept generic pid.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
pre-dump: Collect mount info, root and nsmask

Well, we want to pre-dump files (fsnotifies), for that we
will need mountinfo-s and root, and for the latter -- the
current ns mask.

The problem with current ns mask is that its generation is
incorporated into ns IDs generation and dumping. And since
the ids dumping is not performed on pre-dump, let's just
provide a helper for ns-mask generation.

Strictly speaking, the whole ns-mask idea is not great, but
it's to be fixed later.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Pre-dump file descriptors

We will generate some info about file-descriptors at that
stage. For now these pre-dumped ones would be fsnotifies,
so the pre-dump of a single fd is written as simple as
possible, but enough for that type of FDs pre-dump.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
img: Needed declarations for irmap-cache image file

The irmap-cache is PB-file (like the stat-* ones).
See commtns in next patches for more details.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
irmap: Revalidate irmap entries if required

We will load some irmap entries in cache from image file,
thus producing potentially stale data in irmap cache. To
handle this, make it possible to mark the entries with
need-revalidation mark and do fstat + numbers comparison
when meeting the entry in cache.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
irmap: Introduce irmap on-disk cache

When dumping fsnotifies we may go to irmap to get inode->path
mapping. The irmap engine scans FS (in hinted locations) to
get one and it is slow even though we scan only part of the FS.

Since the above scanning is done while tasks are frozen the
freeze time goes up :(

Improve the situation by generating irmap cache in working dir
at pre-dump when tasks get unfrozen.

The on-disk irmap cache is PB file, it sits in -W directory
and can be loaded on dump/pre-dump start in memory. When
resolving the inode->path mapping irmap may meet these entries,
revalidate them and potentially save time.

After pre-dump the (re-)collected irmap data is written back
to irmap cache image. Typically entries written back are the
same read in on cache load.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
stats: Add irmap resolve time

It's useful to know this value.

W/o cache (first pre-dump) on minimal container the irmap
resolve time is ~0.2 sec. With cache (next pre-dumps or
final dump) on the same container the irmap resolve time
is 10 times less.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
irmap: Try to load irmap cache from parent as well

If we make workdir coincide with images dir, the irmap
cache will be put in parent images for subsequent dump-s.
Try to load it from there.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
pagemap: Factor out pfn retrieving for vdso and zero page

Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mem: Fix zero_page_pfn type

It is compared to u64, so should be such as well

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
util: apply PME_PFRAME_MASK to get pfn

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
vma: Don't close socket's inode as fd

The vm_socket_id is union with vm_file_fd and calling
close on it is wrong.

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