kerndat: Transform kerndat_get_devpts_stat into general form

We will need devtmpfs as well so make it general.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: Dump/restore devtmpfs if it's virtualized

In case if we meet virtualized devtmpfs on dump
(which means its s_dev is different from one obtained
 during mountpoints dump procedure) we should dump it
with tar help. Thus on restore it get filled from the
image.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
bfd: print errno if data can not be flushed

Mr Jenkins reports errors like this:
(02.423007) Error (bfd.c:118): Error flushing image

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
namespaces: user open_proc() in switch_ns()

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: improve checking file descriptors and memory regions (v2)

Now we check them for all test processes

v2: Busybox doesn't have truncate
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Reviewed-by: Christopher Covington <cov@codeaurora.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tty: don't crash if restoring a non-pty

The pty field here is only present with certain tty types, so we shouldn't
unconditionally dereference it, or criu will hang.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mnt: Don't validate mounts on pre-dump

This is for two reasons. First, validation can meet external mount
and will call plugins, which is not correct on pre-dump and actually
crashes on uninitilized plugins lists. Second, even if on pre-dump
mount tree is not "supported" this can be a temporary situation (yes,
yes, unlikely, but still).

On the other hand, it's better to fail earlier, but that's another
story.

Reported-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
pstree: Update max_pid with thread ids

When creating helpers, we need to make sure their
PIDs do not intersect with threads' IDs.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
locks: print a lock before reporting an error about it

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
namespace: don't fail if a namespace isn't supported by kernel

CRIU reads /proc/pid/ns/[NS] and fails of a link is not exist.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
namespace: append a null byte after readlink

readlink() does not append a null byte to buf.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
namespaces: take into account USERNS id

and return an error, if a proccess live in another userns,
because criu doesn't support it.

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

 | tty.c: In function ‘tty_restore_ctl_terminal’:
 | include/criu-log.h:42:16: error: ‘index’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

Same time assign CONSOLE_INDEX for debug info.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: Defer new net-namespace creation until forked

Some kernel modules such as pktgen runs kthred upon
new-net creation taking last_pid we were requested.
Lets workaround this problem using clone + unshare
bundle.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
bfd: Check images got flushed at the end

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
bfd: Don't flush read-only images

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: Invert check for shared mounts check

Introduced by eb214be2, the empty mnt_share list cannot
produce the list_first_entry element :)

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
mnt: Helper and comment for bind mount validation

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
cr-dump: fix out-of-bounds write (OVERRUN)

CID 73381 (#1 of 1): Out-of-bounds write (OVERRUN)
15. overrun-local: Overrunning array loc_buf of 4096 bytes at byte offset 4096 using index len (which evaluates to 4096).

CID 73355 (#1 of 1): Out-of-bounds write (OVERRUN)
6. overrun-local: Overrunning array loc_buf of 4096 bytes at byte offset 4096 using index ret (which evaluates to 4096)

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
page-xfer: write pidfile from a process which starts a service

When a process, which starts a service, exits, we know that we can
connect to the page server and we expect to find pidfile.

If we create pidfile from a page server process, we have a race window.

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