rpc: Add link-remap option

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Fix link vs target names when creating file remaps

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
proc-parse: Fix 32-bit printing of vma addresses

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
show: protobuf -- Fix rendering of repeated messages

Repeated custom entries are presented as an array
of pointers in the memory, so once we fetch the
first entry we are to continue iterating pointers
instead.

Before

	| vmas: {
	|         start: 0x00000000400000
	|         end: 0x00000000406000
	|         pgoff: 0000000000000000
	|         shmid: 0x0000000000000b
	|         prot: 0x5
	|         flags: 0x2
	|         status: 0x41
	|         fd: 0xffffffffffffffff
	| }
	| :{
	|         start: 0x00000000462d00
	|         end: 0000000000000000
	|         pgoff: 0000000000000000
	|         shmid: 0x00000000605000
	|         prot: 0x606000
	|         flags: 0
	|         status: 0x5000
	|         fd: 0x0000000000000b
	|         madv: 0x00000000000041
	| }

After

	| vmas: {
	|         start: 0x00000000400000
	|         end: 0x00000000406000
	|         pgoff: 0000000000000000
	|         shmid: 0x0000000000000b
	|         prot: 0x5
	|         flags: 0x2
	|         status: 0x41
	|         fd: 0xffffffffffffffff
	| }
	| :{
	|         start: 0x00000000605000
	|         end: 0x00000000606000
	|         pgoff: 0x00000000005000
	|         shmid: 0x0000000000000b
	|         prot: 0x1
	|         flags: 0x2
	|         status: 0x41
	|         fd: 0xffffffffffffffff
	| }

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Read aux vector in one pass

No need to read it in cycle.

Repored-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Makefile: fix libcriu.so links and man page installation

The links to the versioned libcriu.so.* included $(DESTDIR) and
$(LIBDIR) which will generate wrong links if building criu packages.
Now the links points to the correct file without any path.

For some reason criu.8 was installed with executable permission. Use
'install' with '-m 644' to make sure this does not happen.

Signed-off-by: Adrian Reber <adrian@lisas.de>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Make tpacket_req3 definition conditional

The makefile includes need to be moved for everything to be
defined properly when the configure tests run.

The Ubuntu 12.04 x86_64 GCC and Linaro's 13.08 and newer AArch64
GCC's have the if_packet.h kernel header, but as of 13.12,
the Linaro AArch32 GCC does not.

Change-Id: I363c43fdb81b028f99aac77e15bff9462c87af4b

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

A user may have necessary linker directories specified in CFLAGS.
Make sure to include them.

Change-Id: I76c2a7bd6e34cc282bfcd5f83cc69ae7fa2c8cc2

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

The top-level makefile defines an ARCH_DIR variable. Always use
it rather than referencing ARCH directly, since ARCH may be set
by the user on the command line and that raw input may not be
what needs to be used internally.

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

ARCH is a user-facing variable and setting it on the command line
clobbers any manipulation attempted in the makefile. Following
the example of the Linux kernel makefiles, use a SRCARCH variable
instead for the internal, potentially fixed-up, architecture name.
This fixes the following error.

make ARCH=x86_64
Makefile:69: *** "The architecture x86_64 isn't supported".  Stop.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Complain about missing CONFIG_ARMV*

Without this a user may encounter the following error.

arch/arm/include/asm/atomic.h:38:2: error: implicit declaration of function ‘smp_mb’

With the #error pragma a user is a least pointed to the specific
section in the file that's causing the problem

arch/arm/include/asm/atomic.h:21:2: error: #error ARM architecture version (CONFIG_ARMV*) not set or unsupported.

Acked-by: Alexander Kartashov <alekskartashov@parallels.com>

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

The current mechanism for determining ARM architecture version
breaks down when cross-compiling. Default to ARMv7 if the user
specifies ARCH=arm. Users wishing to cross-compile for ARMv6
platforms such as the Raspberry Pi should use ARCH=armv6 as
previously required.

Acked-by: Alexander Kartashov <alekskartashov@parallels.com>

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Remove ARM AT_VECTOR_SIZE from x86 header

Perhaps left over from when a single types.h was being used for
multiple architectures, remove the ARM definition of
AT_VECTOR_SIZE from the x86 types.h header. Also remove the
CONFIG_ARM definition since it unused.

Acked-by: Alexander Kartashov <alekskartashov@parallels.com>

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Allow for user CFLAGS

Ideally, a user could set CFLAGS on the command line to contain
compilation options and include and library paths (or maybe set
those last two with CPPFLAGS and LDFLAGS). Unfortunately, setting
CFLAGS on the command line currently short-circuits essential
logic in the makefile and breaks the build. After a first failed
attempt it appears that a monolithic overhaul or "flag day" to
fix this is a substantial undertaking, so for now just provide a
workaround in the form of a USERCFLAGS variable.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Make -march settings part of USERCFLAGS

The current -march settings will cause an error if the user a
conflicting flags such as -mcpu=cortex-a15. Use USERCFLAGS instead
of CFLAGS so that a default is provided but can be overridden.

Change-Id: I8ffecd6bfd7ad5794486a5d14d27bce3170898d3

Acked-by: Alexander Kartashov <alekskartashov@parallels.com>

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Make sure sed fixups are carried out

The following issue is possibly caused by using busybox make.

protobuf/packet-sock.pb-c.c: In function 'packet_sock_entry__init':
protobuf/packet-sock.pb-c.c:98:3: error: this decimal constant is unsigned only in ISO C90 [-Werror]

Use a belt-and-suspenders approach to ensure it doesn't happen.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
page-pipe: split dumping memory on chunks (v3)

The problem is that vmsplice() to a big pipe fails very often.

The kernel allocates a linear chunk of memory for pipe buffer
descriptos, but a big allocation in kernel can fail.

So we need to restrict maximal capacity of pipes. But the number of
pipes is restricted too, so we need to split dumping memory on chunks.

In this patch we calculates the pipe size for which vmsplice() will not
fail.

v2: s/batch/chunk and a few other small fixes
v3: Remove callbacks from page_pipes and reuse pipes
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mem: move code to splice memory into pipes in a separate function

It's preparation to dump memory by chunks.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mem: use chunk mode for dumping anonymous memory

Before this patch, criu splices all data in pipes and then saves these
data in a image file. Here is a problem, becase creating pipes with big
buffers fails too often, because a kernel tries to allocate a big linear
chunks of memory. Now memory are dumped for a few iterations, where the
size of pipe buffers is restricted.

TODO: need to rework pre-dump, because currently dumping data from
      pipes are postponed. We are going to use sys_process_vm_readv for
      this.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Create fake name for remapped file if original name is busy

When live-migrating a container on NFS the link-remap cannot
create original file on target machine, since the file name
is still visible -- source CT is alive. The proper fix would
be to move file aside, then create link, then move original
file back, but since NFS changes file name anyway, we just
do the same -- generate another name for link.

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