files: Add path len arg to check_path_remap

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
ghostf: Move remap_id ghost bit clear to open_remap_ghost

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rst file: Introduce the file_remap abstraction

For linked remaps we'll use similar technique as for ghost
files, but lighter. For that sake make reg_file_info remap
to file_remap, not to the whole host_file.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Support opened-and-unlinked files with non zero link count

These are not ghost, as they are still on fs, so we cannot take
them with us in the image. Neither we can easily find the other name
of that file. Sad :(

To make it work we linkat() the new name to that file using the
AT_EMPTY_PATH flag to link directly to the opened fd. If we could
openat() the fd's parent we would better do it, but we can't and
thus have to create the link name by explicit absolute path :(

This modifies the fs we're dumping, so I'll introduce one more cmd
line option for that soon.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: Test that opened and unlinked files with non zero link count work

Same as unlink_fstat0x, but leave one link alive.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
remap: Add cmdline option to allow linked remap

By default crtools shouldn't modify the environment, except for
killing the dumped tasks. The link remap does so and should sit
under explicit cmdline option.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
help: Add newline at the end of action scripts help messages

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
pstree: Exit with error instead of BUG if image corrupted

No need to panic if image corrupted and we can exit
out graciously.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sk-queue: recvmsg saves a error code in errno

Probably sys_recvmsg was used earlier, which returns a error code.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sk-queue: don't overwrite a return code

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
util: add a function for executing an extrenal tools (v2)

For executing an external tools we need to block a SIGCHLD
and to juggle file descriptors.

SIGCHLD is blocked for getting an exit code.

A problem with file descriptors can be if we want to set 2 to STDIN,
1 to STDERR, 0 to STDOUT for example.

v2: use helpers reopen_fd_as and move_img_fd

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
crtools: use a special function for executing external utils

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mntns: simplify a case, when a root should be changed

We don't need to clean_mnt_ns(), if we are goning to do pivot_root().

"""
pivot_root moves the root file system of the current process to the
directory put_old and makes new_root the new root file system.
"""

So I suggest to do pivot_root() and then detach the old root, all
other mount points will be unmounted automatically.

This patch fixes a problem, when a new root is mounted above a non-root
mount point. It's a default configuration for OpenVZ.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mntns: fix indentions

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sk-queue: don't block on restore of socket queues

If a socket queue doesn't have a free space, a error should be returned,
because nobody reads this socket.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sk-queue: use write/read instread of sendfile

sendfile uses sendpage() and all data are splitted on pages and
a new skb is allocated for each page. It creates a big overhead on SNDBUF.

sendfile() isn't suatable for DGRAM sockets, because message boundaries
should be saved.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files-reg: don't forgot about mntns_root in linked-remap

All operations with files should be relative to mntns_root

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: add ability to make several iterations of dump/restore

Use the -i <num> option to zdtm.sh

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: rework a function for closing all descriptors (v2)

It reads /proc/PID/fd and close all descriptors except service fds.

v2: s/is_one_of_service_fds/is_any_service_fd

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