shmem: Split shmem dumping code into two

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
shmem: Simplify error paths

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
shmem: Rework dumping code to use page-pipe and -xfer engines

This makes it easier to merge with anon vmas dumping and makes use of
page server for shared memory.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
page-xfer: Simplify one page-pipe dumping

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Fix one-page mapping dump

The iov array for 1-page mapping would be zero. Fix this silly mistake.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: find VMA for each restored page

Otherwise ppage_bitmap and page_bitmap will be updated for wrong VMA

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
crtools: remove declaration of rt_sigset_t

Actually rt_sigset_t and k_rtsigset_t are the same

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files-reg: Use pr_err instead of pr_perror if fd not found

Otherwise

 | (00.002843)      1: Error (files-reg.c:522): Can't find regfile for 0
 | : Success

which is inappropriate here.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
page-pipe: Don't forget to free page pipe buffer itself

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: restore file descriptor flags on the correct fd

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: handle of errors from setting fd flags

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
page-xfer.c: fixed format strings

This patch generalizes format strings in the file page-xfer.c
to prevent format string warnings on ARM.

Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: Add PB entries for FS types

mnt_entry::fstype is a part of image ABI, thus we need
to provide some "common" encoding outside tools would
know about this field encoding.

Thus we instorduce fstype enum in .proto file and use it
in source code as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
pipe: prevent dumping pipes in the packetized mode

This mode was introduced less than year ago:

commit 9883035ae7edef3ec62ad215611cb8e17d6a1a5d
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date:   Sun Apr 29 13:12:42 2012 -0700

    pipes: add a "packetized pipe" mode for writing

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
ids: Make sure root ids is present in image

Here is updated one.

0001-ids-Make-sure-kIDs-is-present-in-image.patch

>From dee67b483f0ed1a6f81ebe95ae9bdf74d3ab2ad7 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov@openvz.org>
Date: Fri, 15 Mar 2013 00:43:30 +0400
Subject: [PATCH 1/2] ids: Make sure kIDs is present in image

Otherwise yield error instead of nil dereference
if we meet a broken image.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
ids: Make sure the kIDs obtained from root_ids are sane

Otherwise we will get nil dereference in shared_fdt_prepare

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: reserve the service descriptor for a control tty

I'm really lucky.

prepare_ctl_tty:
	e->fd           = get_service_fd(CTL_TTY_OFF); // -1 as fd is not set

send_fd_to_self:
if (dup2(fd, dfd) != dfd) { // tries to install sfd, but -1 == -1

tty_restore_ctl_terminal:
	if (!is_service_fd(fd, CTL_TTY_OFF))
		return fd == get_service_fd(type); // -1 = -1

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
cr-restore.c: fixed compilation errors on ARM

Use decode_pointer() to convert a virtual address into a native pointer.

Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
pipe: don't reopen pipes via /proc, if it's not required

The system call open can add O_LARGEFILE.

A point is reopend for unsharing a file descriptor. So here are two
types of points. One is returned by pipe() and all other ones are
got via opening /proc/PID/fd.

Currently I know only one difference between these types, it's
O_LARGEFILE.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Tested-by: Alexander Kartashov <alekskartashov@parallels.com
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: one more test case for controlling terminals

  PID   SID TT       COMMAND
26748 26748 ?        tty03
26749 26749 pts/2     \_ tty03
26750 26750 ?             \_ tty03

The second process has not a file descriptor for the ctl tty,
but this tty is opened in tty03.

Currently CRIU can not restore this test case correctly.

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