2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-29 13:28:27 +00:00

79 Commits

Author SHA1 Message Date
Pavel Emelyanov
d135ad3538 mnt: Collect mntns root from criu, in case we don't dump mount namespace
In case criu and dumpee live in the same mount namespace there's no
need in getting ns' root from init task. We can get it from criu and
(!) void the root == "/" check, required for namespace case.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-09-27 21:20:41 +04:00
Andrey Vagin
a46248c80b mount: don't close a namespace descriptor two times
CID null (#1 of 1): Double close (USE_AFTER_FREE)
10. double_close: Calling "restore_ns(int, struct ns_desc *)" closes
handle "ns_old" which has already been closed.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-09-03 13:59:01 +04:00
Andrey Vagin
37ffc41863 mount: prevent dumping mounts, if they can't be restored (v2)
Currently we check that all shared mounts have identical set of
children and that Each non-root mount has a proper root mount.

v2: check that nobody is overmounted
    check a tree before trying to restore it.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-30 15:02:24 +04:00
Andrey Vagin
6244f943bf mounts: handle non-root bind-mounts
A non-root mount is bind-mounted from a proper root mount.

Non-root mount without root mount is not supported yet

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-30 15:01:33 +04:00
Andrey Vagin
f05beddca3 mounts: handle shared and slave mounts (v3)
The idea is simple. If a mount can't be mounted now, we will try to
mount it later.

v2: don't wait slaves, they are unmounted anyway
v3: add a comment in do_bind_mount to explain restoring of shared groups
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-30 15:01:32 +04:00
Andrey Vagin
2eedcaabe5 mount: restore shared, slave, private properties.
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-30 15:01:31 +04:00
Andrey Vagin
02d8a72bb5 mounts: find mounts, which are propagated from a current one (v2)
A few sentences, which are required for understanging this patch

2a) A shared mount can be replicated to as many mountpoints and all the
replicas continue to be exactly same.
2b) A slave mount is like a shared mount except that mount and umount
events only propagate towards it.
2c) A private mount does not forward or receive propagation.

All rules is there Documentation/filesystems/sharedsubtree.txt

If it's a first mount in a group, all group members should be
bind-mounted from this one.

Each mount propagates to all members of parent's group. The group can
contains a few slaves.

Mounts, which have propagated to slaves, are unmounted, because we can't
be sure, that they propagated in real life. For example:

mount --bind --make-slave /share /slave1
mount --bind --make-slave /share /slave2
mount /share/test
umount /slave2/test
mount --make-share /slave1/test
mount --bind --make-share /slave1/test /slave2/test

41 40 0:33 / /share rw,relatime shared:28 - tmpfs xxx rw
42 40 0:33 / /slave1 rw,relatime master:28 - tmpfs xxx rw
43 40 0:33 / /slave2 rw,relatime master:28 - tmpfs xxx rw
44 41 0:34 / /share/test rw,relatime shared:29 - tmpfs xxx rw
46 42 0:34 / /slave1/test rw,relatime shared:30 master:29 - tmpfs xxx rw
45 43 0:34 / /slave2/test rw,relatime shared:30 master:29 - tmpfs xxx rw

/slave1/test and /slave2/test depend on each other and minimum one of them
doesn't propagate from /share/test

v2: use false and true for bool

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-30 15:01:30 +04:00
Andrey Vagin
e01072c05a mounts: if a mount can't be mounted, it is queued in postpone list (v4)
Try to restore mounts while a postpone list isn't empty and check
that each iteration has some progress, otherwice it will fails for
preventing infinite loops

v2: rework logic about postpone list
    add more comments

v3: one more attempt to make it more readable
v4: Here is a master class from Pavel how to write self-documented code.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-30 15:01:28 +04:00
Andrey Vagin
2b4a8d29d6 mount: save group and master in image file (v2)
They are required for restoring shared and slave mounts

v2: use the same names of variables in image and in code
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-30 15:01:27 +04:00
Andrey Vagin
d00e7c6f88 mount: link dependent mounts (v3)
All shared mounts from one group are connected to circular list.
All slave are added into the proper master list.

v2: change variable name and fix a bug about adding shared mounts in a
circular list.
v3: handle errors of collect_shared

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-30 15:01:26 +04:00
Pavel Emelyanov
b18fb09eb9 show: Replace one-line show_foo calls with args array
We have generic do_pb_show() call and tons of show_foo
routines, that just call one with proper args. Compact
the code by putting the args into array and calling
the do_pb_show() in one place.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-24 04:00:32 +04:00
Pavel Emelyanov
84737e2796 build: Generate most of the pb-desc automatically
These contain linkage between number, data type and routines
for pb messages we write/read to/from image files. Most of them
have simple number-type-routines mapping, so introduce a generating
script for that.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-23 21:47:31 +04:00
Andrey Vagin
3ea73d7f9b mount: move is_root, is_root, fsroot_mounted to the top of the file
They are trivial and these functions will be used in many places

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-09 15:44:35 +04:00
Andrey Vagin
b2504e0763 mounts: enumirate mounts bellow specified element
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-09 15:43:54 +04:00
Pavel Emelyanov
9cef1a00ce mount: Factor out detached mountpoint opening
The difficulty is that this code is required in both -- pie
and non-pie contexts.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-29 13:12:00 +04:00
Andrey Vagin
65d3545945 mount: allow to dump content even if a part of fs is overmounted (v3)
for that the mount point is bind-mounted in a temporary place.

v2: * check, that the fs you get access to at the end is _really_ the
      one you wanted to
    * use switch_ns/restore_ns helpers
v3: reuse code of __open_mountpoint and a few small cleanups

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-05 18:06:36 +04:00
Andrey Vagin
2d631b4562 mount: build tree of mounts before dumping them
When CRIU wants to dump content, it checks that nothing is overmounted.
The list of children for such mounts must be empty, but these lists are
filled during constructing a tree of mounts.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-05 18:05:56 +04:00
Andrey Vagin
5eb254b016 tmpfs: use the --one-file-system option for dumping tmpfs with help tar
Actully for dumping tmpfs it should be remounted to somewhere else to
avoid overmounts.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-09 20:33:33 +04:00
Andrey Vagin
7aaef1ee4f mount: don't destruct an external mount-namespace (v2)
If a parent mount point is shared with exteranl mntns, a child will be
umounted from the external mntns too.

For example:
$ mount -t tmpfs xxx /root/tmp/
$ mount --make-shared tmp
$ mkdir tmp/xxx
$ mount -t tmpfs xxx /root/tmp/xxx
$ touch tmp/xxx/a

$ unshare -m umount tmp/xxx
$ ls -l tmp/xxx/a
ls: cannot access tmp/xxx/a: No such file or directory

This patch changes a parent mnt to private for umounting childrens.

v2: exit if a mount point can not be marked ad private

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-08 13:39:16 +04:00
Cyrill Gorcunov
38dd47b524 mount: Verify for external shared mount
If we meet shared mount point without share master belonging
to us -- it means we might fail on restore, thus require both
master/slave mount peers to be collected on dump.

In other words, the output will be like

 | (00.077025) Error (mount.c:421): Mount 49 (master_id: 2 shared_id: 0) has unreachable sharing
 | (00.077123) Error (mount.c:472): Can't proceed 4237's mountinfo
 | (00.077865) Error (namespaces.c:442): Namespaces dumping finished with error 65280

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

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-06-08 00:00:59 +04:00
Cyrill Gorcunov
e9b00f9918 mount: Simplify mnt_entry_alloc
Allocate it with xzalloc instead of massive
NULL assignment. Moreover, don't forget to
initialize @siblings.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-06-08 00:00:27 +04:00
Cyrill Gorcunov
30936058a0 ns: Extend ns_desc to carry the length of the ns name
This will be needed for fast parsing of procfs ns references.

[ xemul: Add user_ns_desc here ]

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-05-18 03:36:56 +04:00
Libo Chen
ad6db8332b mountns: potential fd leak when readlinkat call
when mntns_collect_root->readlinkat call faild, we should close pdf

Signed-off-by: Libo Chen <libo.chen@huawei.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-05-16 17:07:15 +04:00
Pavel Emelyanov
add21b75c9 show: Remove options args from ->show callback
This thing is global, we can address one explicitly.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-05-08 00:23:42 +04:00
Kir Kolyshkin
d90d4b1b88 Fix typos in log messages
Someone has to do it, right?..

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-04-15 12:46:25 +04:00
Andrey Vagin
13a8e60bca cr-dump: collect mount points in the target namespace
Information about mount points is used for dumping fanotify.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-04-11 22:06:48 +04:00
Andrey Vagin
6a49f82fb6 mount: free all parts of mnt entries
mnt_entry contains a few strings and they should be release too

CID 996198 (#4 of 4): Resource leak (RESOURCE_LEAK)
20. leaked_storage: Variable "pm" going out of scope leaks the storage
it points to.

CID 996190 (#1 of 1): Resource leak (RESOURCE_LEAK)
13. leaked_storage: Variable "new" going out of scope leaks the storage
it points to.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-04-10 01:26:59 +04:00
Pavel Emelyanov
5cae819d8c img: Get rid of open_image_ro helper
O_RSTR flag should be used instead for regular open_image

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-04-09 19:22:21 +04:00
Cyrill Gorcunov
9c3a88c7b1 mnt: Add simfs entry to a list of supported fs
simfs is used in OpenVZ containers, so lets understand it
and don't fail on its meeting.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-04-04 14:08:33 +04:00
Andrey Vagin
c9b9aad265 mount: rollback and return a negative value in case of errors
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-04-04 14:00:23 +04:00
Andrew Vagin
f16d7c64e5 mount: remove root with MS_PRIVATE before cleaning up mntns
Otherwise we will clean up the root mntns too.

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-03-27 17:28:30 +04:00
Andrew Vagin
929a0f24fd mount: remove root with MS_PRIVATE before pivot_root
Otherwise if the root is mounted with MS_SHARED, pivot_root fails with EINVAL.

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-03-27 17:28:27 +04:00
Cyrill Gorcunov
a73259522b mount: Add missing \n in cr_pivot_root message
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-03-26 19:23:17 +04:00
Cyrill Gorcunov
62d532a97f mount: Add PB entries for FS types
mnt_entry::fstype is a part of image ABI, thus we need
to provide some "common" encoding outside tools would
know about this field encoding.

Thus we instorduce fstype enum in .proto file and use it
in source code as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-03-18 22:32:57 +04:00
Pavel Emelyanov
3a1c7d1d76 ns: Introduce ns descriptors
These are structs that (now) tie together ns string
and the CLONE_ flag. It's nice to have one (some code
becomes simpler) and will help us with auto-namespaces
detection.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-15 23:24:01 +04:00
Cyrill Gorcunov
f58ab92cfe mount: Add lookup_mnt_id and lookup_mnt_sdev helpers
We will need to lookup mount points by mount id
and device for fanotify restore.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-15 18:34:28 +04:00
Andrey Vagin
e12dad0ade mntns: close_proc before clean up mounts
Because /proc could not be umounted, if any its file is opened.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-12 00:54:34 +04:00
Alexander Kartashov
6f61488f21 x86: moved x86-specific files into the directory arch/x86.
* The following files goes into the directory arch/x86/include/asm unmodified:
  - include/atomic.h,
  - include/linkage.h,
  - include/memcpy_64.h,
  - include/types.h,
  - include/bitops.h,
  - pie/parasite-head-x86-64.S,
  - include/processor-flags.h,
  - include/syscall-x86-64.def.

* Changed include directives in the source files that include the headers
  listed above.

* Modified build scripts to reflect the source moves.

Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-09 17:02:47 +04:00
Pavel Emelyanov
0026b53678 mnt: Don't allocate PATH_MAX on stack for pivot path
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-12-06 16:20:19 +03:00
Pavel Emelyanov
1a7c7d0404 fd: Consolidate . and .. checks in various readdir callers
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-11-29 21:12:51 +03:00
Huang Qiang
223dce83c2 fix many unclosed file opened by open_image_ro
Many image files opened by open_image_ro weren't closed before return, fix
them all in this patch.

Signed-off-by: Huang Qiang <h.huangqiang@huawei.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-24 16:51:50 +04:00
Andrey Vagin
ea20f5d221 mntns: fix indentions
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-28 14:13:20 +04:00
Andrey Vagin
a2fd8cd0a5 mntns: simplify a case, when a root should be changed
We don't need to clean_mnt_ns(), if we are goning to do pivot_root().

"""
pivot_root moves the root file system of the current process to the
directory put_old and makes new_root the new root file system.
"""

So I suggest to do pivot_root() and then detach the old root, all
other mount points will be unmounted automatically.

This patch fixes a problem, when a new root is mounted above a non-root
mount point. It's a default configuration for OpenVZ.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-28 14:13:18 +04:00
Andrey Vagin
e3fbb63080 crtools: use a special function for executing external utils
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-28 14:09:58 +04:00
Andrey Vagin
e1b02a48c1 cr-restore: block SIGCHLD for restoring namespaces
Restore of namespaces requires executions of external tools
(ip, tar, etc). We want to know return codes, so we should
block a default sigchld handler. Before we did that for each
command, I suggest to block SIGCHLD, then restore namespace and
unblock SIGCHLD.

The default sigchld handler is used for catching target processes,
but all this processes (except a current one ) are started after
restoring namespaces.

Currently we forgot to block SIGCHLD before executing "ip",
and this bug was caught.

Reported-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-25 15:59:13 +04:00
Andrey Vagin
e3afdd0f29 tmpfs: replace all short tar options on long analogs
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 18:34:19 +04:00
Cyrill Gorcunov
f473f4f24d mount: Use BUG() instead of BUG_ON(1)
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-27 23:22:41 +04:00
Pavel Emelyanov
f1b41e0824 code: Replace 0x%x with %#x in messages
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-11 21:55:48 +04:00
Pavel Emelyanov
a1b731dac3 code: Brush up multi-line comments first line
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-11 21:48:17 +04:00
Andrey Vagin
148497e45d mount: add support of devpts
The devpts fs should be mounted and its content is restored,
when crtools restores terminals.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-09 19:59:14 +04:00