core: Introduce task_timers_entry

This one will hold all info about timers in the core_entry.
Since timers are always per-task, this one is on task core
entry.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
core: Move itimers on core

This allows to have one image less per-task, which in turn
reduces live migration time a little bit.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
core: Move posix timers on core entry

This as well gives us minus one image per-task and
allocates more space on core task entry.

One thing to note -- the amount of posix timers is
not easily accessible at the core entry allocation
time, so the respective array is allocated on demand.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
posix-timers: Helper for freeing proc parsed data

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
posix-timers: Clean restore code flow

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
timers: Reshuffle new and legacy restoration code

Make explicit checks and helpers for legacy images.
This should facilitate its removal some day in the
future.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rlimits: Move entries from top-core into task-core

This appeared after latest 1.2, so it's still possible
to do this move.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rlimits: Reshuffle new and legacy restoration code

Do the same as was done with timers.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
servicefd: add a service fd for current root

It's already used for dumping files and it will be used for restoring,
so it should be service fd to avoid intersection with restored
descriptors.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: open_mountpoint returns a file descriptro

Only one function use DIR, so I don't see reason to return it

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: fix comparison of stat.st_dev and mount_info->s_dev (v2)

st_dev and s_dev have different formats.
st_dev is (MAJOR(dev) << 8) | MINOR(dev)
s_dev is (MAJOR(dev) << 20) | MINOR(dev)

so we need to convert one of them

v2: use kdev_to_odev
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: open_mount uses __open_mountpoint instead of own logic

Now we have two funсtions which do mostly the same, so this patch merges
them.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: save relative path in mi->mountpoint

"relative path" is absolute path with dot at the beginning.

We already use relative paths on restore. In this patch we add "."
on dump too. It's convinient, because we needed to add dot each time
when we want to access this mount point.
Before this patch we had to created a temporary copy.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: add EOL to the error message
mount: close old descriptor in mntns_collect_root
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 (v2)

We are going to restore nested mount namespaces and we will need to
change root for each of them.

v2: don't call chdir in a second time, because a path may be relative
restore: add mount id-s in the ns_ids list (v4)

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
v4: look up namespace by two values -- type AND ID
mounts: mark local root-s in the list of mount points (v2)

We are going to dump nested mount namespaces. All sub-namespaces will be
restored as sub-mounts in the root mount namespace. So mi->mountpoint
will be not '/' even if a mount is root for its mntns.

v2: s/is_root/is_ns_root/
mounts: connect sub-root to the main root

A sub-mount namespace is restored as sub-tree of the root mntns, so
the parent of sub-mntns root is the root of the root mntns.