files: print a correct minor numbers for unsupported character devices

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: predump_one_fd -- Use direct read of pid's fd link

Using O_PATH known to be buggy on 3.11 kernel so use
direct link reading procedure here.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: mutate tgt_addr in map_private_vma

prepare_mappings() uses the return value of map_private_vma() for the
size of the mapped vma. Unfortunately the return value of
map_private_vma() is an int, resulting in breakage when the size exceeds
31 bits. Change map_private_vma() to return only an error code, and
mutate addr in-place.

Signed-off-by: Jamie Liu <jamieliu@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
criu: fix filemap open permissions

An mmaped file is opened O_RDONLY or O_RDWR depending on the permissions
on the first vma dump_task_mm() encounters mapping that file. This
causes two problems:

1. If a file has multiple MAP_SHARED mappings, some of which are
   read-only and some of which are read-write, and the first encountered
   mapping happens to be read-only, the file will be opened O_RDONLY
   during restore, and mmap(PROT_WRITE) will fail with EACCES, causing
   the restore to fail.

2. If a file is opened read-write and mapped read-only, it will be
   opened O_RDONLY during restore, so restore will succeed, but
   mprotect(PROT_WRITE) on the read-only mapping after restore will
   fail.

To fix both of these, record open flags per-vma based on the presence of
VM_MAYWRITE in smaps.

Signed-off-by: Jamie Liu <jamieliu@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: add maps_file_prot

Tests for the bugs fixed by "criu: fix filemap open permissions".

Signed-off-by: Jamie Liu <jamieliu@google.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: fix integer literal type bug in maps03

maps03 should have caught the bug fixed by 288cf5174165 "restore: mutate
tgt_addr in map_private_vma", but didn't because integer literals
(defaulting to 32-bit ints) were shifted out of range.

Signed-off-by: Jamie Liu <jamieliu@google.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files-reg: fix "criu: fix filemap open permissions"

Fixes two issues with efe594f8f421 "criu: fix filemap open permissions":

- Permissions on files with both open file descriptors and mappings.

- Restore compatibility with dumps created by previous versions of criu.

Signed-off-by: Jamie Liu <jamieliu@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test
mount: detect the newinstance option for devpts (v2)

The devpts instance was mounted w/o the newinstance option if,
the device number is equal to the root /dev/pts.

I think this condition is strong enough to not mount devpts in a
temporary place.

v2: move the host.bla-bla-bla in kerndat.c
devpts: open the ptmx device from the pts mount

Actually we need to open a ptmx device from a proper mount of devpts.
But currently we hard code the path to ptmx as /dev/ptmx. This patch
changes it on /dev/pts/ptmx.
zdtm: mount devpts with the newinstance flag
zdtm.sh: don't check path to ptmx

CRIU use a predefined path to open ptmx

-101 -> /dev/ptmx
+101 -> /dev/pts/ptmx
zdtm: add test cases on TCP_FIN_WAIT* states

TCP_FIN_WAIT1 our side has shutdown, waiting to complete
              transmission of remaining buffered data

TCP_FIN_WAIT2 all buffered data sent, waiting for remote
              to shutdown
zdtm: add test cases on TCP_CLOSE_WAIT and TCP_LAST_ACK states

TCP_CLOSE_WAIT remote side has shutdown and is waiting for
               us to finish writing our data and to shutdown
               (we have to close() to move on to LAST_ACK)

TCP_LAST_ACK   out side has shutdown after remote has
               shutdown.  There may still be data in our
               buffer that we have to finish sending
zdtm: check sockets in the TCP_CLOSING state

TCP_CLOSING both sides have shutdown but we still have
            data we have to finish sending
jenkins: add script for checking pre-dump
crtools: close all desriptors only for the root task

For all other tasks only unsed service descriptors will be closed.

This change allows to have file descriptors, which may be used for
restoring namespaces. All non-server descriptors must be closed before
restoring files.
mounts: initialize root before dumping mount namespace

Currently it's initialized for the root mount namespace, but we are
going to dump nested mount namespaces.

It's used in open_mountpoint(), which is used in dump_tmpfs() and in
other callbacks.
mounts: allow to customize root path for cr_pivot_root

We are going to restore nested mount namespaces and we will need to
change root for each of them.
restore: add mount id-s in the ns_ids list (v3)

Currently ns_ids is filled only on dump. Now we are going to restore
nested mount namespaces, so we need to know who share name spaces.

v2: merge the patch "namespace: add a function to search an ns_id
item by id" into this one.
v3: add prefix rst_ to add_ns_id