Commit graph

375 commits

Author SHA1 Message Date
Andrew Vagin
41a0035dd4 mount: don't take into acount the root master_id
It's an external one and it's already created and we don't have proper
shared mount.

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-16 18:11:06 +03:00
Andrew Vagin
db91c9a934 mount: don't remount a slave mount as private when it isn't required
We don't need to remount a mount as private, when a source mount and
a new mount has the same master_id and shared_id

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-16 18:11:01 +03:00
Stanislav Kinsburskiy
8e863a94c7 fstype: "mount" callback introduced
It will be used to mount AutoFS, because context creation is required in
addition to actual mount operation.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-14 14:04:32 +03:00
Andrew Vagin
af55c059fb mount: fix a race between restoring namespaces and file mappings (v2)
Currently we wait when a namespace will be restored to get its root.
We need to open a namespace root to open a file to restore a memory mapping.

A process restores mappings and only then forks children. So we can have
a situation, when we need to open a file from a namespace, which will be
"restored" by one of our children.

The root task restores all mount namespaces and opens a file descriptor
for each of them. In this patch we open root for each mntns in the root
task.

If we neeed to get root of a namespace which isn't populated, we can get
it from the root task. After the CR_STATE_FORKING stage, the root task
closes all namespace descriptors ane we know that all namespaces are
populated at this moment.

v2: don't close root_fd for root ns, because it was not opened
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-10 14:58:59 +03:00
Andrew Vagin
a9be7621b7 mount: pick out a function to set ROOT_FD_OFF
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-10 14:58:18 +03:00
Andrew Vagin
7094e110a3 mount: stop doing anything if populate_mnt_ns() failed
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-09 14:28:46 +03:00
Andrew Vagin
96a12d4755 mount: don't worry if a binfmt_misc image is empty
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-09 14:27:58 +03:00
Andrew Vagin
2c747325f4 mount: don't add dot to a path
It isn't required and it doesn't work in a case when
we want to bind-mount a file.

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-08 17:19:51 +03:00
Andrew Vagin
93e996d8ed mount: umount a temporary mount with MTN_DETACH
If a temporary mount is a shared one, a new mount can be
propagated into it.

Fixes: 0e9736ab68 ("mount: fix restoring a bind-mount when its root is overmounted)")

Reported-by: Mr Jenkins
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-08 16:33:58 +03:00
Andrew Vagin
e7e63a0de1 mount: don't rewrite root for external mounts
It's used to restore bind-mounts. For example, we cat the common
part of bind-mounts:

Core was generated by `criu restore -vvvv --file-locks --tcp-established --evasive-devices --manage-cg'.
Program terminated with signal 11, Segmentation fault.
741                     BUG_ON(target_root[tok] == '\0');
(gdb) bt

https://jira.sw.ru/browse/PSBM-41932

Reported-by: Virtuozzo QA Team
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-08 15:05:12 +03:00
Andrew Vagin
0e9736ab68 mount: fix restoring a bind-mount when its root is overmounted
In this case we mount source mount in a temporary place and use it to
create the bind-mount.

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-08 15:00:03 +03:00
Andrew Vagin
9102b08ceb mount: refactor do_bind_mount()
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-08 14:59:41 +03:00
Andrew Vagin
d6d6af9a5a mount: pick out a function to bind mount a point in a tmp place
This is used to get a mount without over-mounted parts.

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-08 14:59:25 +03:00
Cyrill Gorcunov
6217a84ae3 mnt: Carry run-time device ID in mount_info
When we're restoring fsnotify watchees we need to resolve
path to a handle at some mountpoint referred by @s_dev
member (device ID) which is saved inside image. This
ID actually may be changed at the every mount (say
one restores container after machine reboot) or in
case of container's migration.

Thus the test for overmounting in __open_mountpoint
will fail and we get an error.

Lets do a trick: introduce @s_dev_rt member which
is supposed to carry run-time device ID. When dumping
this member simply equal to traditional @s_dev fetched
from the procfs, but when restoring we fetch it from
stat call once mountpoint become alive.

https://jira.sw.ru/browse/PSBM-41610

v2:
 - predefine MOUNT_INVALID_DEV
 - use fetch_rt_stat instead of assigning device in restore_shared_options
 - copy @s_dev_rt in propagate_siblings and propagate_mount

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-08 14:58:32 +03:00
Kirill Tkhai
de8fd000d0 fs: Add binfmt_misc support
This patch implements checkpoint/restore functionality
for binfmt_misc mounts. Both magic and extension types
and "disabled" state are supported.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-08 14:52:26 +03:00
Andrew Vagin
c1404f6671 mount: restore cwd after creating a roots yard (v2)
Currently we see that a cgroup yard are not umounted
with the ENOENT error, because cwd was changed.

v2: construct a path to remove a roots yard
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-04 15:22:58 +03:00
Andrew Vagin
b352659ca2 criu: don't trigger a bug if a task wants to restore a root mntns
It's possiable, if a parent task lives in a sub-mntns and
its child lives in the root mntns. A mount namespace is
restored before forking children, so all children are created
in parent's mount namespace. If a child lives in another
mount namespace, we need to move it into the required mntns.

Reported-by: Mr Jenkins
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-30 11:49:15 +03:00
Andrew Vagin
af956f45ac mount: close mnt.ns_fd only for sub-namespaces (v3)
nsid->mnt.ns_fd is initialized into 0, so currently
fini_restore_mntns() closes the 0 descriptor if processes
lives in a current mount namespace (NS_CRIU).

Without this patch I get the following error:
(00.166444)   4109: Inherit fd tty:[8800:d] -> 0 has been closed

v2: typo fix
v3: do nothing when processes are restored in the local mntns
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-27 15:50:09 +03:00
Andrew Vagin
49448676ac util: don't leak cr-img objects (v2)
We need to call close_image() for "empty" images.

v2: don't touch generic functiuons
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-26 17:04:37 +03:00
Andrew Vagin
b78af1923b mount: wait when mntns will be created to get its root (v2)
v2: add comments and rename ns_created to ns_populated.

Reported-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-17 10:46:00 +03:00
Andrew Vagin
7017181849 mount: don't inherit mount namespace descriptors to each process
close_olds_fds() knows nothing about more than one set of service file
descriptros, so it's better to call it before forking children as it was
bedore 9d60724eca ("restore: restore mntns before creating private vma-s")

The root task restores all processes and pin them with file descriptors,
then a task restores a mount namespace by opening the file descriptor of
the root task via /proc/pid/fd/X.

Reported-by: Mr Jenkins
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-17 10:45:09 +03:00
Andrew Vagin
9d60724eca restore: restore mntns before creating private vma-s (v3)
We need to open a file to restore a file mapping and this file
can be from a current mntns.

v2: All namespaces are resotred from the root task and then
other tasks calls setns() to set a proper mntns.

v3: fix comments from Pavel
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-14 09:53:47 +03:00
Andrey Ryabinin
947dcc736f mount: use correct mount namespace in open_mountpoint
open_mountpoint() have to operate in target's mount namespace,
which may differ from root's namespace - root_item->pid.real.

So obtain the correct mount namespace from mount_info and use
it in switch_ns().

Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Acked-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-13 19:52:08 +03:00
Pavel Emelyanov
18d9170858 util: Add flags to cr_system
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-12 16:31:19 +03:00
Tycho Andersen
8a95be0679 net: allow c/r of empty bridges in the container
Implementing c/r of bridges with slaves shouldn't be too hard (viz. the
comment), but this is all I need to for right now.

v2: remove extra debug statement
v3: * remember to close fd in dump_bridge
    * use "known" buffer length and snprintf for spath in dump_bridge
    * change brace style

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-12 10:31:58 +03:00
Tycho Andersen
b6cdc5e9bd mnt: don't dump external mounts
These are going to be bind mounted from the outside world after all, so
there is no use in dumping them.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-09 11:57:32 +03:00
Tycho Andersen
b6a355c33c mnt: always_fail should report an error
Otherwise, you just see an anonymous failure in the logs, like:

(00.244773) mnt: Dumping mountpoints
(00.244781) mnt:        253: 42:/ @ ./dev/.lxc
(00.244793) mnt: Path `/dev/.lxc' resolved to `./dev/.lxc' mountpoint
(00.249039) mnt:        133: 41:/ @ ./dev/hugepages
(00.249052) mnt:        116: 40:/ @ ./run/lock
(00.249064) mnt: Path `/run/lock' resolved to `./run/lock' mountpoint
(00.251948) mnt:        115: 3f:/ @ ./run
(00.251970) mnt: Something is mounted on top of ./run
(00.264803) mnt: Path `/run' resolved to `./run' mountpoint
tar: ./uuidd/request: socket ignored
tar: ./dbus/system_bus_socket: socket ignored
tar: ./acpid.socket: socket ignored
tar: ./systemd/journal/syslog: socket ignored
tar: ./systemd/journal/dev-log: socket ignored
tar: ./systemd/journal/socket: socket ignored
tar: ./systemd/journal/stdout: socket ignored
tar: ./systemd/private: socket ignored
tar: ./systemd/notify: socket ignored
(00.368950) mnt:        113: 3e:/ @ ./dev/shm
(00.368978) mnt: Path `/dev/shm' resolved to `./dev/shm' mountpoint
(00.371551) mnt:        112: 3d:/ @ ./dev/pts
(00.371566) mnt:        249: 28:/ @ ./var/lib/lxcfs
(00.371749) Unlock network
(00.371762) Running network-unlock scripts
(00.371766) Unfreezing tasks into 1
(00.371770)     Unseizing 13683 into 1
(00.371784)     Unseizing 14839 into 1
(00.371794)     Unseizing 15678 into 1
(00.371800)     Unseizing 16126 into 1
(00.371805)     Unseizing 16177 into 1
(00.371814)     Unseizing 16301 into 1
(00.371843)     Unseizing 16323 into 1
(00.371854)     Unseizing 16414 into 1
(00.371900)     Unseizing 16595 into 1
(00.371911)     Unseizing 16695 into 1
(00.371942)     Unseizing 16744 into 1
(00.371964)     Unseizing 16904 into 1
(00.372103)     Unseizing 16944 into 1
(00.372140)     Unseizing 17558 into 1
(00.372196) Error (cr-dump.c:1631): Dumping FAILED.

...which is hard to debug.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-09 11:57:25 +03:00
Cyrill Gorcunov
7a99e699ce mnt: Export __open_mountpoint
We gonna need it for inotify handle testing.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-21 15:08:03 +03:00
Andrew Vagin
9f631ad5c9 mnt: Use ns_mountpoint to open a mount point
open_mountpoint helper is called when mount namespace are
already restored so we have to use local paths.

This is a continuation to patch a082f27b -- we keep mount
point id in fsnotify, thus we should use the namespace's
path for open.

https://jira.sw.ru/browse/PSBM-39957

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-14 15:51:05 +03:00
Andrew Vagin
addbc25550 mnt: Fix slave mounts order estimation in can_mount_now
For slave mount we need to make sure that all childrent
mountpoints of the master peer is mounted before we can
proceed otherwise there gonna be duplicated mountpoints
after the restore.

https://jira.sw.ru/browse/PSBM-39957

Signed-off-by: Andrew Vagin <avagin@odin.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-12 13:08:32 +03:00
Kir Kolyshkin
15f914f20a pr_perror(): don't supply \n
pr_perror() is special, it adds \n at the end so there is
no need to supply one.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Acked-by: Andrew Vagin <avagin@odin.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-09 18:29:55 +03:00
Kir Kolyshkin
17b92fa542 Append newline when using pr_err()
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Acked-by: Andrew Vagin <avagin@odin.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-09 18:28:00 +03:00
Cyrill Gorcunov
002c81c3ce mnt: Don't treat ns roots as special when restoring
Namespace roots might be slave ones from another
namespace roots, so we should not treat them as
"always ready" for mounting but rely on general
logic in can_mount_now which tests slaves relations.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-08 13:18:47 +03:00
Cyrill Gorcunov
5b203c1e1b mnt: Make sure we don't hit nil dereference on nested mount
Such case is actually a BUG but while we can resolve
the situation without real bug-on call lets walk in
a gentle way.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-07 15:18:47 +03:00
Cyrill Gorcunov
09d97050aa mnt: Add info about mnt image we're reading
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-07 15:17:26 +03:00
Cyrill Gorcunov
9e1da526e6 mnt: Add more details in pr_debug for shared, slaves binds
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-07 15:17:21 +03:00
Andrey Vagin
e23299b45a mount: use absolute paths for pivot_root
When we initialize a sub-mount namespace, we need to use absolute paths.
For example we change cwd in prep_unix_sk_cwd()

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-07 14:49:31 +03:00
Pavel Emelyanov
80b66ee15d mnt: Don't include fake root entry in every mnt tree
This entry is only required if we have it, i.e. -- at restore stage
in the tree we _built_. All other cases, in particular, local tree
collection on restore, do not need such.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@odin.com>
2015-09-30 12:31:32 +03:00
Pavel Emelyanov
a7c9f3011d mnt: Read mount images early
Mappings from mount id to namespace will be required to
remove ghosts on restore failure.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-28 22:00:36 +03:00
Pavel Emelyanov
152222a6b7 remap: Sanitize ghost file path printing
First -- avoid two memory copies by printing ns root directly, and
second -- remove extra argument from create_ghost, the mnt_id value
we need there can be found on the ghost_file object.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-28 21:59:45 +03:00
Pavel Emelyanov
7ca6cc1eb2 mnt: Clean roots yard from criu process
So here it is. If root task dies on restore the roots yard
dir remains unrmdired :( Since we already know its name, we
can remove one from criu. By the time we get to this place
the sub mount namespace(s) are already dead and yard dir
is empty. But umounting should be done by tasks after
successfull restore, so keep depopulation there.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-28 21:57:35 +03:00
Pavel Emelyanov
3e7c92ed02 mnt: Renames around roots yard
Same thing as in previous patch -- we have too many generic
clean_ and fini_ prefixes over the code. And we need more (see
next patch), so let's specify what exactly we clean or fini.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-28 21:57:21 +03:00
Pavel Emelyanov
a180a75c7a mnt: Uninline clean_mnt_ns
Just to get rid of clean_something name. We have too
many cleaners out there already :\

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-28 21:57:06 +03:00
Pavel Emelyanov
c5c65fe17a mnt: Create roots in criu context
In case root task restore failure we'll have to remove the
roots yard dir from criu, so we have to create one by
criu to at least have the dit name.

It's OK to do it in criu, since the yards is created in
the opts.root which is the same for any mnt ns we deal
with on restore.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-28 21:56:51 +03:00
Pavel Emelyanov
9b3189fed1 util: Add make_yard helper
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-28 11:32:18 +03:00
Pavel Emelyanov
c5054f959d mnt: Factor out external check in validate_mounts
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-28 11:32:10 +03:00
Pavel Emelyanov
4e0276340a mnt: Rename collect_shared and remove unused for_dump argument
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-28 11:32:02 +03:00
Andrew Vagin
84cc1e12ac mount: don't merge mnt and sb flags if only one contains MS_RDONLY
Reported-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Andrew Vagin <avagin@openvz.org>
Tested-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-23 15:34:38 +03:00
Pavel Emelyanov
9353051ba7 ns: Check ns type with type field
Actually make use of the ns->type field and remove all getpid()'s
and other strange/inconsistent checks.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-21 12:15:28 +03:00
Pavel Emelyanov
1c34b284f3 mnt: Move read_mntns_img into populate routine
We don't need the read tree earlier.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-21 12:13:48 +03:00