2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 14:25:49 +00:00
Commit Graph

281 Commits

Author SHA1 Message Date
Tycho Andersen
fcae4f3954 mnt: add --enable-external-masters option
This option enables external (slave) bind mounts to be resolved.

v2: don't always assume that when the master id matches, the mounts match

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-10 17:54:51 +03:00
Tycho Andersen
0afffc9dc1 mnt: add --enable-external-sharing flag
With this flag, external shared bind mounts are attempted to be resolved
automatically.

v2: don't always assume when the sharing matches that the mount matches

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-10 17:54:12 +03:00
Tycho Andersen
aebfabb5ad mnt: add --ext-mount-map auto option
When this option is specified, if an external (private) bind mount is not
specified by --ext-mount-map KEY:VAL then it is attempted to be resolved
automatically.

v2: introduce find_best_external_match, which looks for the best match based on
    sharing/slave ids; don't try to resolve fsroot_mounted() mountpoints
v3: get rid of really_collect_self_mounts
v4: get rid of fsroot_mounted() check when autodetecting external mounts

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-10 17:52:14 +03:00
Oleg Nesterov
e2c38245c6 introduce --enable-fs cli option
Finally add --enable-fs option to specify the comma separated list of
filesystem names which should be treated as FSTYPE_AUTO.

Note: obviously this option is not safe, use at your own risk. "dump"
will always succeed if the mntpoint is auto, but "restore" can fail or
do something wrong if mount(src, mountpoint, flags, options) can not
actually "just work" as FSTYPE_AUTO logic expects.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-10 17:35:43 +03:00
Oleg Nesterov
eaf3a03ced dump/restore fstype->name if FSTYPE__AUTO
Add the new mnt_entry->fsname member and change dump_one_mountpoint()
to save pm->fstype->name if fstype == FSTYPE__AUTO.

Change collect_mnt_from_image() to pass this ->fsname to decode_fstype()
which falls back to __find_fstype_by_name(fsname, true) if FSTYPE__AUTO.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-10 17:35:26 +03:00
Oleg Nesterov
039cf95d59 introduce __fsname_is_auto(name, force_auto)
Simple preparation to simplify the review of the next patch. Turn
find_fstype_by_name(name) into __find_fstype_by_name(name, force_auto)
and reimplement find_fstype_by_name() as a trivial wrapper on top.

This allows "restore" to specify that this particular fsname was treated
as FSTYPE__AUTO by "dump".

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-10 17:35:21 +03:00
Oleg Nesterov
38e148e502 introduce fsname_is_auto(name) and FSTYPE__AUTO
The comment in find_fstype_by_name() says:

	just mounting anything is wrong

and this is true in general, but:

	almost every fs has its own features

this is not true in a sense that a lot of supported filesystems do not
need any special processing: FSTYPE__PROC, FSTYPE__SYSFS, and more. More
importantly, this logic does not allow to spicify from the command line
that (say) currently unsupported hugetlbfs can "just work", do_new_mount()
should only pass the right name/options.

This patch adds the new FSTYPE__AUTO code, find_fstype_by_name(name) adds
the new entry if fsname_is_auto(name) returns true. We do not care that
different fstype's can have the same FSTYPE__AUTO code, fstype->code has
no meaning unless we need to do something special with this fs, but in
this case it should not be FSTYPE__AUTO by definition.

Note: currently find_fstype_by_name() just returns true, it is obviously
pointless to "dump" until we teach "restore" to handle FSTYPE__AUTO.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-10 17:35:05 +03:00
Oleg Nesterov
1f9798a6ae reserve the extra room in fstypes[]
Preparation. Enlarge fstypes[] to make it possible to add the new
fstype's dynamically.

This means ths find_fstype_by_name() and decode_fstype() need the
additional ->name == NULL check to terminate the search.

Also change them to start with "i == 1", we rely on the fact that
fstypes[0] is FSTYPE__UNSUPPORTED anyway.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-10 17:34:31 +03:00
Pavel Emelyanov
7e657d042d mount: Rename find_fstype_by_name's vars to simplify further patching
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-10 17:33:13 +03:00
Tycho Andersen
f9f99573d7 mnt: relax constraints on fuse mounts
1. If a fuse connection is present, but there are no fuse mounts of that type
   in the mount namespace, don't refuse to dump.
2. If there are mounts of that type in the container but they are external,
   we're going to bind them anyway, so there's no fuse-specific things that
   need to be done, so it is safe to dump.

v2: check that the fstype is fuse as well

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-10 13:43:14 +03:00
Tycho Andersen
71398f5cf5 mnt: add matching on fs kernel subtypes
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-10 13:42:15 +03:00
Pavel Emelyanov
15bd7ce29a mount: Fix compilation after previous comment
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-09 13:25:18 +03:00
Tycho Andersen
246367e4e4 add walk_all flag to walk_namespaces
In the rest of this series we need to walk all the namespaces to autodetect
which mounts are master/shared/private bind mounts, so we need the information
from criu's namespace in the case when the namespaces are not the same.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-09 12:53:19 +03:00
Saied Kazemi
f72f3824f4 Do not fail if /tmp does not exist
Currently if /tmp does not exist, CRIU fails because it will not be
able to create a temporary directory there.  But when checkpointing
and restoring containers, we cannot rely on the existence of /tmp.
For such containers, we should use root (/).  The temporary directory
will be removed after CRIU is done.

Signed-off-by: Saied Kazemi <saied@google.com>
Acked-by: Andrew Vagin <avagin@odin.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-07 09:27:16 +03:00
Tycho Andersen
ad03d67a4b Add newline to pr_err output
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-06 18:06:45 +03:00
Andrey Vagin
9083f86a64 mount: restore cwd in open_mountpoint()
setns(fd, CLONE_NEWNS) resets cwd and root, so we need to
restore them back.

Without this patch stats-dump isn't saved in the work dir:
-rw-r--r-- 1 root root 32 Apr  2 14:21 /stats-dump

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-03 18:00:03 +03:00
Oleg Nesterov
9fee3dc817 pass "bool for_dump" argument down to collect_mntinfo() and parse_mountinfo()
Preparation.

1. Add the new "bool for_dump" arg to collect/parse_mntinfo().

2. Introduce "struct collect_mntns_arg" to pass the additional
   "bool for_dump" field to collect_mntinfo() and change it to
   pass this boolean to collect_mntinfo()->parse_mountinfo() path.

3. Change other callers of collect_mntinfo() to pass "false".

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-03 17:55:18 +03:00
Pavel Emelyanov
7263054c3a mnt: Add comment about mntns to tasks assignment
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@odin.com>
2015-04-01 12:37:23 +03:00
Tycho Andersen
1c79933301 remove some double ;;s
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-31 22:09:38 +03:00
Oleg Nesterov
57db932a0a mount: always report ->mnt_id as decimal
validate_mounts() prints ->mnt_id in hex when it reports the failure.
This complicates the understanding because this ->mnt_id is printed as
decimal elsewhere, including /proc/$pid/mountinfo.

parse_mountinfo() adds "0x" at least and this is just pr_info(), but
lets change it too.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Andrew Vagin <avagin@openvz.org>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-27 14:03:04 +03:00
Pavel Emelyanov
f7f76d6ba6 img: Introduce empty images
When an image of a certian type is not found, CRIU sometimes
fails, sometimes ignores this fact. I propose to ignore this
fact always and treat absent images and those containing no
objects inside (i.e. -- empty). If the latter code flow will
_need_ objects, then criu will fail later.

Why object will be explicitly required? For example, due to
restoring code reading the image with pb_read_one, w/o the
_eof suffix thus required the object to be in the image.

Another example is objects dependencies. E.g. fdinfo objects
require various files objects. So missing image files will
result in non-resolved searches later.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-13 14:42:54 +03:00
Pavel Emelyanov
e10b3ef407 mount: Don't ignore validation and shared resolving errors on dump
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-02-25 11:46:26 +03:00
Pavel Emelyanov
199619791d mnt: Factor out find-mount-by-s_dev code
And move the 2nd piece lower to avoid fwd declaration and
keep similar calls close to each other.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-19 13:17:30 +04:00
Andrey Vagin
104d3b84d5 mount: rework can_mount_now() to support bind-mounts of shared mounts
Fedora bind-mounts a part of the root mount to itself. Currently we
don't allow to mount children of a shared mount, if other mount from
this shared group are not mounted.

This patch adds an exclusion for cases, when a child has the same
group. We allow to mount a child, if wider mounts are mounted.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-12 12:54:39 +04:00
Andrey Vagin
beeabc3b2b mount: add the mnt_roots mount in the mount tree on restore
Currently we connect roots of sub-namespaces to the root of the root
mount namespace. And we get problems, if the root of the root mntns is
shared, because all children of a shared mount must be propagated to
other mounts in this group.

Actually we mount tmpfs in mnt_roots and here is nothing wrong to add it
in a tree.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-12 12:54:37 +04:00
Pavel Emelyanov
4e7064cd7e mount: Remove the len variable
And use the expression for it, it's quite short. This
makes the amount of variables in the code fit into brains.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:33 +04:00
Pavel Emelyanov
0fbee68f26 mount: Add helper for searching for shared peer
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:32 +04:00
Pavel Emelyanov
cedd10254c mount: Sanitize the path recalculation between submounts
Do paths conversions and checks step-by-step and add many comments
what we do in each step and why.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:31 +04:00
Pavel Emelyanov
991c02874a mount: Use pre-calculated ct->mountpoint + t_mpnt_l value
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:30 +04:00
Pavel Emelyanov
ffe5f9b422 mount: Use issubpath() when checking for submount visibility
When we check whether a submount of a mount is visible in another
mount (shared peer of the latter), we can and should use the new
issubpath helper.

Should because the used strncmp may scan beyond ct_mpnt_rpath if
its length is smaller (no checks for this in the code).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:29 +04:00
Pavel Emelyanov
e9512502d1 mount: Move some variables out of search loop
These are constant for given m, so calculate them outside
of the loop. Also rename them to reflect what they are.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:28 +04:00
Pavel Emelyanov
028d6355e6 mount: Rename paths' lengths to reflect whose lengths they are
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:27 +04:00
Pavel Emelyanov
6b0059049d mount: Add helper for path length calculations
The path lenght is zero for the "/" one and strlen(path)
for all the others. This is done so to make it possible
to use this length to get tail-paths: if path_1 starts
with path_2 and both are absolute, then

   path_1 + path_length(path_2)

would give the tail of the tail of path_1 relative to
path_2 even if the path_2 is just "/".

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:26 +04:00
Pavel Emelyanov
64c95bf586 mount: Add helper to search for widest shared peer
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:25 +04:00
Andrey Vagin
1cf5168cab mntns: rework validation to support non-root shared bind-mounts (v2)
A problem which is solved in this path is that some children can be
unaccessiable (unvisiable) for non-root bind-mounts

root	mount point
-------------------
/	/a (shared:1)
/	/a/x
/	/a/x/y
/	/a/z
/x	/b (shared:1)
/	/b/y

/b is a non-root bind-mount of /a
/y is visiable to both mounts
/z is vidiable only for /a

Before this patch we checked that the set of children is the same for
all mount in a shared group. Now we check that a visiable set of mounts
is the same for all mounts in a shared group.

Now we take the next mount in the shared group, which is wider or equal
to current and compare children between them.

Before this patch validate_shared(m) validates the m->parent mount.
Now it validates the "m" mount. So you can find following lines in the
patch:
-               if (m->parent->shared_id && validate_shared(m))
+               if (m->shared_id && validate_shared(m))

We doesn't support shared mounts with different set of children.
Here is an example of such case can be created:
mount tmpfs a /a
mount --make-shared /a
mkdir /a/b
mount tmpfs b /a/b
mount --bind /a /c

In this case /c doesn't have the /b child. To support such cases,
we need to sort all shared mounts accoding with a set of children.

v2: If root is equal to "/", its len should be zero. We expect that the
last symbol in a path is not "/".

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-12 12:54:21 +04:00
Pavel Emelyanov
00770a91c1 kerndat: Handle errors from devtmpfs virtualized checks
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:15:17 +04:00
Pavel Emelyanov
69bffe26d3 kerndat: Make fs-virtualized check report yes/no
Right now it returns the whole struct stat which is excessive.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:15:09 +04:00
Pavel Emelyanov
f33908a897 ns: Rename "created" futex and comment what it is
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:11:58 +04:00
Pavel Emelyanov
32f58742ca mnt: Introduce and use issubpath helper
When we validate the mount tree not to have overmounts we need to
check one path to be the sub-path of another. Here's a helper for
this.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-07 17:39:23 +04:00
Andrey Vagin
4ed63afa00 mount: bind-mount root into itself if processes are restored in userns
When we create a new mntns in a userns, all inhereted mounts are marked
as locked. pivot_root() returns EINVAL if a new root is locked.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-07 17:00:13 +04:00
Pavel Emelyanov
3bb7731c2e mnt: Helper and comment for bind mount validation
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-05 15:41:09 +04:00
Pavel Emelyanov
defdb96b9b 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>
2014-11-05 15:40:41 +04:00
Pavel Emelyanov
b1a8e41dd0 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>
2014-10-30 15:15:30 +04:00
Cyrill Gorcunov
a1d7c7c593 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>
2014-10-30 15:10:32 +04:00
Cyrill Gorcunov
48d81eb48a 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>
2014-10-30 15:10:31 +04:00
Andrey Vagin
eb214be2d0 mount: move code to validate shared mounts in a separate function
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-29 16:19:03 +04:00
Andrey Vagin
ffe7f01d29 mount: don't add extra / between a temporary root and mountpoint
Currenlty a generated path contains two slashes successively.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-29 16:18:52 +04:00
Andrey Vagin
4862246c10 mntns: pivot_root() can move the current root to a non-shared mount
So we need to create a temporary private mount for the old root.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-29 16:18:46 +04:00
Andrey Vagin
41aa981dde mount: don't mark mounts as private twice
We do the same action twice. It's typo.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-29 16:18:17 +04:00
Andrey Vagin
377205c147 Revert "mount: don't create a temporary directory for pivot_root()"
This reverts commit 21d1b2fdb9.

pivot_root() can move the current root to a non-shared mount. So we are
going to create a temporary private mount in put_old.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-29 16:18:16 +04:00