mount: Check for mount postponing with a helper

The expression in if () becomes quite complex and
deserves a helper with proper explanation of what's
going on.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: link remap -- Fix potential buffer overrun

If the former file had a path long enough to be near
PATH_MAX limit, sprintf'ing link_remap.%d here might
overrun the limit. Use snprintf instead.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
net: Move void devices dumping in a separate helper

To make it look symmetrical to over types dumping.
And for simpler further patching.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
net: Factor out empty-kind devices checking

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
net: Factor out unknown devices dumping

For now this "dumping" is just a warning. In the next patches
there will be call to plugins.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
net: Add ability to dump external links with plugins

If we meet a link we cannot dump we call plugin to check
whether it's the link, that should be treated as external.

Note, that on restore we don't call any plugins, but
consider the setup-namespace script to move the respective
link into the namespace. Links are not hierarchical and
can be moved between namespaces easily, so it's OK to
delegate the link creation to the script.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
util: Log scripts running

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: Run setup-ns scripts before restoring them

We should call external scripts when namespaces are created,
but before we try to fill them with data from images.

This is done so e.g. to make it possible to push external net
links to netns.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
net: Don't specify link index when restoring its params

Well, when we create external link with ip utility we cannot
specify its index. Thus we will not be able to move external
device to namespace and ask criu to restore link params.

However, RTM_SETLINK can happily work with the link name only.
And since we do have one in the images, we can omit setting
the index in the requrest.

TODO: Send patch with index specification to iproute2.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: Test and example how to dump namespace with macvlan

One note -- the macvlan's index _does_ change. We should
either patch iproute2 or use raw kernel API to preserve it.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
page-read: Don't check that an image file contains data

Modern tar and rsync can replace zero chunks with holes. So it's valid situation
and shouldn't abort the restore.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
show: Implement simple images filtering

The -F|--fields option specifies which fields (by name, comma
separated) should be printed.

For nested fields all names in path should be specified.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
net: Add comment about not using ifindex for setlink

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Save fstype on fd_parms

We will need to special-care NFS silly-rename files, thus
we need to know which FS a file belongs to.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Pass fs_parms into check_path_remap

To catch NFS silly-rename file we'll need more than just
struct stat there.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Dump NFS silly-rename files as linked-remap always

We cannot distinguish ghost files from linked-remap for NFS.
Link count is never 0 on such files and any positive value of
it doesn't mean, that the file will stay in place after we
terminate all tasks we dump -- they can hold multiple unlinked
links on the same file and they all will be delayed-unlined.

Checkinf file path doesn't work as well -- silly-rename files
remain visible by VFS, though they shouldn't :(

Fortunatelly, NFS allows creation of additional likns on such
files, so we just create linked remap for such files.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: Some updates to treat NFS fds properly

First of all, silly-rename files' names may change, so
kludge the fds comparison properly.

Other than this, allow for linked-remaps on write_read10
test as it effectively generates such on NFS.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mounts: restero slave, shared mounts correctly

If a mount is slave and it has a shared group. crtools must convert it
in slave and only than crtools can make it shared.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test/make: transfer arguments for zdtm.sh

make ZDTM_ARGS="-C -i 2" -C test/ zdtm_ns -j 8

make is able to execute tests concurrently.
Now we can customize execution of tests

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: show logs in case an error (v2)

Makefile is locked, because tests can be executed concurrently.

v2: return non-zero code
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>