2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 22:05:36 +00:00
Commit Graph

142 Commits

Author SHA1 Message Date
Andrey Vagin
1edfe53b71 mounts: Connect sub-root to the main root as children
Each sub-namespace is restored as sub-tree of the root mntns, so
the parent of sub-mntns root is the root of the root mntns.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-21 22:38:03 +04:00
Andrey Vagin
84c48e6244 mounts: Mark ns' roots in the list of mount points (v2)
When we'll restore nested mount namespaces, all but root ones (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/
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-21 22:37:57 +04:00
Andrey Vagin
0989d3fdf9 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
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-21 22:37:49 +04:00
Andrey Vagin
d738cf3e0f 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.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-21 22:37:45 +04:00
Andrey Vagin
67456e90ac mount: Close old service descriptor in mntns_collect_root
We're about to collect root several times in a row, so keeping
the old one isn't required.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-21 22:36:53 +04:00
Andrew Vagin
ee9258e80f mount: take into account btrfs workaround for converting st_dev to phys_dev
BTRFS returns subvolume dev-id instead of superblock dev-id

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-18 15:02:04 +04:00
Andrew Vagin
b664bb142b mount: fill fstypes for btrfs mounts on restore
BTRFS returns subvolume dev-id instead of superblock dev-id,
so we need to know which mounts are btrfs.

The mi->fstype->name is "unsuppoerted" here, because the fstype->code
is saved in an image

{
.name = "unsupported",
.code = FSTYPE__UNSUPPORTED,
},
{
.name = "btrfs",
.code = FSTYPE__UNSUPPORTED,
}

An a second reason is that pocesses can be migrated from smth to btrfs.
This all can happen _only_ for the root mount and for bind mounts of
the root mount...

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-18 15:01:57 +04:00
Andrey Vagin
8df879941d 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>
2014-04-17 12:05:58 +04:00
Andrey Vagin
946eadd598 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>
2014-04-17 12:03:15 +04:00
Andrey Vagin
d07ed2049e 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>
2014-04-17 12:03:13 +04:00
Andrey Vagin
81999b709c 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>
2014-04-17 12:03:12 +04:00
Andrey Vagin
87a49bdfaf 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>
2014-04-17 12:03:11 +04:00
Andrey Vagin
387161959a mount: dump and restore bind-mounts of the root mount
The root mount is an external mount and its source can be not '/'.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-11 16:04:30 +04:00
Andrey Vagin
a19643e643 mount: cut a common part of sources for bind-mounts
The source of the root mount may be not equal to "/" and we need to take
this fact into account, when we bind-mount it to somewhere.

For example:

11877 ?        Ss     0:00 ./bind-mount --pidfile=bind-mount.pid --outfile=bind-mount.out --dirname=bind-mount.test
11880 ?        Ss     0:00  \_ ./bind-mount --pidfile=bind-mount.pid --outfile=bind-mount.out --dirname=bind-mount.test
[root@avagin-fc19-cr crtools]# cat /proc/11880/mountinfo
68 42 8:3 /root/git/crtools/test / rw,relatime - ext4 /dev/sda3 rw,data=ordered
43 68 0:33 / /proc rw,relatime - proc proc rw
44 68 0:34 / /dev/pts rw,relatime - devpts pts rw,mode=666,ptmxmode=666
45 68 8:3 /root/git/crtools/test/zdtm/live/static/bind-mount.test/test /zdtm/live/static/bind-mount.test/bind rw,relatime - ext4 /dev/sda3 rw,data=ordered

The 45 mount is bind-mount of the 68 mount.
mi(45)->root = /root/git/crtools/test/zdtm/live/static/bind-mount.test/test
mi(68)->root = /root/git/crtools/test

so the comman part is "/root/git/crtools/test" and the command is
mount --bind /zdtm/live/static/bind-mount.test/test /zdtm/live/static/bind-mount.test/bind

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-11 16:04:08 +04:00
Andrey Vagin
33a50cfdc8 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
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-08 15:32:35 +04:00
Andrey Vagin
c5afed0685 mount: don't clean up propogation options for the root mount (v2)
Currently we marks all mounts as private before restoring mntns. We do
these to avoid problem with pivot_root.
It's wrong, because the root mount can be slave for an external shared
group. The root mount is not mounted by CRIU, so here is nothing wrong.

Now look at the pivot_root code in kernel
if (IS_MNT_SHARED(old_mnt) ||
	IS_MNT_SHARED(new_mnt->mnt_parent) ||
	IS_MNT_SHARED(root_mnt->mnt_parent))
	goto out4;

So we don't need to change options for all mounts. We need to remount
/ and the parent of the new root. It's safe, because we already in another
mntns.

v2: simplify code

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-03-22 09:47:56 +04:00
Andrey Vagin
f621023210 mount: execute propagation logic for the root mount (v4)
The root mount isn't always private. For example it is mounted
as a slave in LXC 1.0 containers. So we need to execute logic
about propogation for the root mount too.

v2: move all logic about the root mount in a separate function
v3: make code more readable
v4: do_mount_root() looks like other do_*_root() functions

Reported-by: David Shwatrz <dshwatrz@gmail.com>
Cc: David Shwatrz <dshwatrz@gmail.com>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-03-22 09:47:35 +04:00
Andrey Vagin
3844cb9bee mount: check bondaries in mount_resolve_path
The current code think that /vz/lxc/centos-6-x86_64-root is
in /vz/lxc/centos-6-x86_64.

If the path is not equal to mountpoint, we need to check, that
path contains a slash after mountpoint.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-03-20 13:23:13 +04:00
Andrey Vagin
e61259a82f mount: mark all mounts as private in one place
This should be done before restoring a mount tree. This patch is a part
of the series about moving pivot_root, which has been committed.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-03-04 22:01:17 +04:00
Andrey Vagin
226945460f mounts: make pivot_root after restoring mount points
We are using tar for resting tmpfs. Currently we execute tar from a
restored root, but nobody guarantees that it is there and that it's
really tar.

We don't have reason to change root too early. Lets live in a source
root as long as we can, because we can be sure that it's consistent.

https://bugzilla.openvz.org/show_bug.cgi?id=2870

v2: remove redundant chdir()
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-28 20:32:43 +04:00
Andrey Vagin
31f2f79519 mounts: use relative paths for mountpoints (v2)
We are going to restore mounts before changing root. For that the
current dir is changed in a new root and mounts will be restored by
relative paths.

v2: don't use snprintf
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-28 20:30:49 +04:00
Andrey Vagin
245fa6ea56 mount: change cwd on the root before restoring mntns (v2)
We are going to make pivot_root after restoring mount name-space,
so relative paths will be used for mountpoints.

v2: print correct root in a error message
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-28 20:30:44 +04:00
Andrey Vagin
06662f9f13 mount: rename TMPFS_MAGIC into TMPFS_IMG_MAGIC
TMPFS_MAGIC is already used in linux/magic.h

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-28 13:26:48 +04:00
Andrey Vagin
bcd36c6e26 mount: Don't use /proc/self to access mount points
If a process is in another pidns than /proc, the link /proc/self doesn't
work.

(00.061569) Error (mount.c:558): Can't bind-mount
46:/zdtm/live/static/tempfs.test to /tmp/cr-tmpfs.gBVwTb: No such file
or directory

But since we've switched to the mount namespace (with setns) we
can just go an open the path by its name.

Reported-by: Urgen Sherpa <urgen.sherpa@nepallink.net>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-22 12:38:44 +04:00
Pavel Emelyanov
3a86ee3688 fsnotify: Check on dump that file handle can be opened
Some filesystems do not provide open-by-handle functionality. For those,
we should abort fsnotifies dumping, not restoring.

The open_mount() changes are about opening mountpoints inside another
mount namespace.

Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-01-29 17:30:03 +04:00
Pavel Emelyanov
91011328fa criu: Several formatting fixes
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-01-14 09:33:19 +04:00
Andrey Vagin
8bd7ac7717 mounts: restero slave, shared mounts correctly
If a mount is slave and it has a shared group. crtools must convert it
in slave and only than crtools can make it shared.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-30 12:30:18 +04:00
Pavel Emelyanov
1c2b1633d9 mount: Check for mount postponing with a helper
The expression in if () becomes quite complex and
deserves a helper with proper explanation of what's
going on.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-26 11:40:31 +04:00
Pavel Emelyanov
08b893fd03 mount: Add comment to is_root_xxx checks
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-26 11:22:01 +04:00
Pavel Emelyanov
c18b30d0a9 mount: Restore external bind-mounts with plugins
All the entries with with_plugin set will be mounted by plugin.
The interesting case is when we do the pivot-root restore. In this
case we call restore callback very early (before we unmount the old
tree) and ask it to create the mountpoint at temporary location.
Later we move the mount to proper place.

The old_root argument of the callback is where it can find files
in the original mount namespace.

The is_file is return-argument. Sine files and directories cannot be
bind-mounted to each-other, the callback should create the mountpoint
itself and report whether it created file or directory.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-26 11:07:41 +04:00
Pavel Emelyanov
d21ff39aab mount: Dump external bind-mounts with plugins
External bind mounts are those with source sitting outside of the
current FS view. Such are detected in validate_mounts(), so we
just go ahead and call plugins.

The plugin is provided with the mountpoint to decide whether it's
his or not (what else does the guy need?) and an ID with this it
can identify the mountpoint in /proc. The same ID will be used at
restore time to find the needed restore info.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-26 11:07:39 +04:00
Pavel Emelyanov
db33a144d2 mount: Fix the mi we print info about
The t and m match there, but strictly speaking we're working on the m.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-26 11:07:38 +04:00
Pavel Emelyanov
dcd680726c mount: Read mount images eary
We'll have to pre-mount some, so move the read_mnt_ns_img
before pivot_root call.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-26 11:07:37 +04:00
Pavel Emelyanov
70eb3cc4f3 mount: Make images reader return the list of mounts
To carry them with us in a local variable (next patches), not
the global mntinfo one.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-26 11:07:35 +04:00
Pavel Emelyanov
cb4e125bd0 mount: Split reading images and populating the ns
We will need images at hands while we do pivot_root (see further patches),
so prepare the images reading routine.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-26 11:07:34 +04:00
Kir Kolyshkin
8692291d42 tab-at-eol cleanup
Remove whitespace at EOL (found by git grep '	$')
(the character before $ is real tab, typed in shell using Ctrl+V Tab)

To people using vim, I'd suggest adding the following code to ~/.vimrc:

let c_space_errors = 1
highlight FormatError ctermbg=darkred guibg=darkred
match FormatError /\s\+$\|\ \+\t\|\%80v.\|\ \{8\}/

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-20 16:09:08 +04:00
Kir Kolyshkin
e2a0be63d4 mnt_tree_for_each_reverse(): init a variable
A warning catched by clang:

> > mount.c:869:71: error: variable 'progress' is uninitialized when used here
> >       [-Werror,-Wuninitialized]
> >   ...prev, MNT_WALK_NONE, fn, (struct list_head *) NULL, progress);
> >                                                          ^~~~~~~~
> > mount.c:802:4: note: expanded from macro 'MNT_TREE_WALK'
> >                         _prgs++;
> > \
> >                         ^
> > mount.c:867:14: note: initialize the variable 'progress' to silence this
> > warning
> >         int progress;
> >                     ^
> >                      = 0
> > 1 error generated.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-20 11:26:12 +04:00
Pavel Emelyanov
ae98ef6ae0 mount: Factor out mount tree build for NEWNS and non-NS cases
We anyway build the tree, in the NS case -- few calls later.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-12 16:19:48 +04:00
Pavel Emelyanov
bd69c6173d mount: Free old mounts for pivot-root case
If we specify a new root for restore old mounts get destroyed
with pivot_root + umount calls, tree umount is omitted. In this
case mi-s are leaked.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-12 16:13:31 +04:00
Pavel Emelyanov
f35d7cd7fe mount: Don't validate mounts read from proc on restore
Validation means -- check chat we can _restore_ this tree.
Those read from proc can be in any state -- we're going to
umount them (can do anything) and do path resolution (work
for any knots as well).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-12 16:01:14 +04:00
Kir Kolyshkin
d64d68d66c whitespace-at-eol cleanup
Remove whitespace at EOL (found by git grep ' $')

To people using vim, I'd suggest adding the following code to ~/.vimrc:

let c_space_errors = 1
highlight FormatError ctermbg=darkred guibg=darkred
match FormatError /\s\+$\|\ \+\t\|\%80v.\|\ \{8\}/

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-12 10:00:45 +04:00
Pavel Emelyanov
873d1dac9d unix: Move odev to kdev conversion into phys_stat_dev_match
This is more correct, as if st_dev == phys_dev check fails
we have to treat phys_dev as kdev for path resolve device
comparison.

Howver, this is not the case for non-btrfs FSs, and for the
latter one doesn't change anything as it uses anon devices
which are equal for kdev and odev cases.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-12 08:44:15 +04:00
Pavel Emelyanov
0d8f688e5c mount: Fixup phys/virt devices dumping for ghost files
When dumping a ghost file we put real device in its header,
not the (btrfs) virtual one. This is done since we put real
devices into fsnotify images (we get them from proc). That
said on fsnotify ghost restore we don't need to do path
resolution, just devices compare.

And one more thing. When dumping device for ghost file for
_non_ btrfs case we have to convert stat dev_t into kernel
dev_t as all the other places in criu manipulate the latter
ones.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-12 08:18:21 +04:00
Andrew Vagin
fe764c2c14 mount: add btrfs into fstypes
It's used by phys_stat_resolve_dev (broken by c5d2386a)

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-12 01:07:12 +04:00
Pavel Emelyanov
976265a078 mount: Add comments about mount list and tree
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-11 17:34:41 +04:00
Pavel Emelyanov
0efaf212b2 mount: Clean code a bit
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-11 17:19:40 +04:00
Pavel Emelyanov
c5d2386a2f btrfs: Remove volume parsing code
Now we have more robust and fs agnostic path-resolution
engine for resolving dev conflicts.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-11 17:18:59 +04:00
Cyrill Gorcunov
1ba08ca664 mount: Extend phys_stat_dev_match to use path resolving instead of btrfs engine
Instead of scanning btrfs subvolumes (which can be even unaccessbile
if mount point lays on directory instead of subvolume itself) we use
path resolving feature here -- once we need to figure out if some
device number need to be altered up to mount point (as we know stat()
called on subvolume returns st_dev for subvolume itself, but not
one that associated with a superblock and shown in /proc/self/mountinfo
output).

This as well implies that we need to check if device number for ghost
files are to be updated to match mountinfo, thus we use phys_stat_resolve_dev
helper here.

After this patch the previously merged btrfs engine is no longer needed
(at least it seems so) and can be dropped.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-11 16:05:22 +04:00
Cyrill Gorcunov
5372e3910c mount: btrfs -- Introduce phys_stat_resolve_dev helper (v2)
This routine is aimed to find a mount point on which
the path passed as argument is laying on. We walk over
all mount points and see which one is matching.

Once found (in worst case it will be a root mount point
so function is never failing) we're checking if this is
btrfs and then return subvolume0 device id.

See commit 921cf873f3
for details what the hell we're doing here.

v2: rewrite mount_resolve_path w/o recursion

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-11 16:05:21 +04:00
Cyrill Gorcunov
cf1ce5f817 mount: Build mount tree on dump restore early, if needed
For paths resolution we will need mount tree to be parsed
and built, but it's not that simple -- the current code
implies that once parsed the tree must not be re-parsed
again, so we pass @parse argument from a caller: if a task
we're restoring do not use mount namespace, we should parse
mount tree early, otherwise defer this action until mount
tree is read from the image.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-11 16:05:19 +04:00