Commit graph

348 commits

Author SHA1 Message Date
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
Pavel Emelyanov
2847089378 mnt: Reshuffle MntEntries reading code
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-21 12:13:25 +03:00
Pavel Emelyanov
c1a25fc1bd mnt: Add mi->root resolving helper
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-21 12:13:21 +03:00
Pavel Emelyanov
259374f6b1 mnt: Add mi->mountpoint resolving helper
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-21 12:13:09 +03:00
Andrey Vagin
5cff834ae7 mount: handle old images where sb and mnt options were not separated (v3)
Currently we have only one common flag. It is MS_READONLY and it's
interpreted as a super block flag to not change old behaviour.

v2: add a comment
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-21 11:55:36 +03:00
Andrey Vagin
1174a2ad0f mount: handle mnt_flags and sb_flags separatly (v4)
They both can container the MS_READONLY flag. And in one case it will be
read-only bind-mount and in another case it will be read-only
super-block.

v2: set mnt and sb for one call of mount() when it's posiable
v3: return a comment which was deleted by mistake
v4: Fix the sentense about restoring mnt flags
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-21 11:55:17 +03:00
Cyrill Gorcunov
5db3f4c337 mount: Add LOG_PREFIX
It's very convenient to grep the log for mount related operations only.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-16 15:41:20 +03:00
Cyrill Gorcunov
64cf10f88e mount: mnt_depth -- make it unsigned
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-10 14:02:04 +03:00
Cyrill Gorcunov
f21dfadfe4 mount: mnt_build_ids_tree -- Rework messages
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-10 14:00:22 +03:00
Cyrill Gorcunov
795267940c mount: mnt_build_ids_tree -- Rename @p to @parent
The function is too big and @p is too short.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-10 13:59:42 +03:00
Cyrill Gorcunov
675a84fbc9 mount: Rename get_widest_peer to find_widest_shared
It lookups over shared entries and finds widest.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-04 18:23:41 +03:00
Cyrill Gorcunov
f7d550323b mount: Fix comment style
We don't use C99 comments.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-04 18:20:52 +03:00
Cyrill Gorcunov
eb6dcc4070 mount: Fix restore deleted bindmounts for regfiles
- make sure it doesn't exist using O_EXCL
 - don't forget to close it

Reported-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-02 18:51:01 +03:00
Cyrill Gorcunov
d27f5391d5 mount: Handle deleted bindmounts for regular files
1) Deleted bindmount for files should be restored
   by creating temp file. The kernel doesn't permit
   to mix bindmount in terms of file/dir relationship:
   either both source and target should be files or
   directories.

   Thus we can call stat on the target and figure out
   what kind of source we had.

2) Even for deleted entries better to use permissions
   from the target's stat call, this makes result close
   to how would it look if program hadn't been checkpointed.

Reported-by: Andrey Wagin <avagin@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-02 15:33:46 +03:00
Cyrill Gorcunov
80ef8fd2fb mount: Handle deleted bindmounts
To handle deleted bindmounts we simply create
the former directory bindmount lived at, mount
the target and remove the directory back.

For this sake we add @deleted entry into the image.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-08-21 21:26:17 +03:00
Cyrill Gorcunov
db70a415ed mount: propagate_mount -- Add braces
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-08-18 18:15:50 +03:00
Cyrill Gorcunov
8c9e15560a mount: Shrink lookup_nsid_by_mnt_id
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-08-13 17:18:09 +03:00
Cyrill Gorcunov
69657701c4 mount: overlayfs -- Shift code left in __lookup_overlayfs
Also use is_root_mount() helper instead of opencoded
strcmp("./", m->mountpoint) and -Ex error codes in
ERR_PTR.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-08-13 17:17:54 +03:00
Cyrill Gorcunov
8603ae77f8 mount: Shrink mnt_entry_free a bit
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-08-13 17:17:02 +03:00
Cyrill Gorcunov
3ae67d7b3a mount: Move mount_info and ext_mount to mount.h
It's quite unclean while this structure lives
in proc_parse.h, which only have to fill this
structure on procfs read, but real handling
is inside mount.c. Move it as appropriate.

Same time ext_mount structure should be moved
into a header as well with sane @list name
used instead of @l.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-08-13 17:16:47 +03:00
Andrey Vagin
8fd50f35b9 dump: dump tmpfs from a target userns
It's required to dump uid-s and gid-s from this userns.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-08-07 14:42:02 +03:00
Gabriel Guimaraes
dbaab31f31 Workaround for the OverlayFS bug present before Kernel 4.2
This is here only to support the Linux Kernel between versions
3.18 and 4.2. After that, this workaround is not needed anymore,
but it will work properly on both a kernel with and without the bug.

The bug is that when a process has a file open in an OverlayFS directory,
the information in /proc/<pid>/fd/<fd> and /proc/<pid>/fdinfo/<fd>
is wrong, so we grab that information from the mountinfo table instead.

This is done every time fill_fdlink is called.
We first check to see if the mnt_id and st_dev numbers currently match
some entry in the mountinfo table. If so, we already have the correct mnt_id
and no fixup is needed.

Then we proceed to see if there are any overlayFS mounted directories
in the mountinfo table. If so, we concatenate the mountpoint with the
name of the file, and stat the resulting path to check if we found the
correct device id and node number. If that is the case, we update the
mount id and link variables with the correct values.

Signed-off-by: Gabriel Guimaraes <gabriellimaguimaraes@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-08-07 14:30:41 +03:00
Andrey Vagin
8360d9aa9a tar: use no-unquote and --no-wildcards
to be able to use any symbols in paths

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-07-21 16:45:33 +03:00
Andrey Vagin
a26f1cd39b mnt: tune the root mount before mounting a root yard
Otherwise the root yard can be propagated into the host mount namespace
and remain there and criu will fail, because it will not be able to
remove the roots yard.

It occures if we give a shared mount as root to "criu restore" and
criu converts it into a slave mount.

Reported-by: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-06-11 19:48:42 +03:00
Cyrill Gorcunov
d9fb201175 mount: Add ability to restore ro tmpfs
In case if we've dumped read only tmpfs we fail restoring it
because it's mounted with ro flags. Lets mount it with rw,
restore content and then remount as ro.

upd (by xemul@): any fs with restore method likely to
need rw permission on restore.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-05-29 01:01:31 +03:00
Kir Kolyshkin
8ac865f3ee Fix check for open_image() ret
When open_image() was modified to return a pointer rather than an int
in commit 295090c1, these two checks were overlooked and never fixed.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Acked-by: Andrew Vagin <avagin@odin.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-05-05 13:37:16 +03:00
Kir Kolyshkin
b17962ad8d Fix pr_perror() usage
When using pr_perror(), format string should not end with \n,
as it is added by the macro itself.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Acked-by: Andrew Vagin <avagin@odin.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-05-05 13:36:29 +03:00
Oleg Nesterov
497b79d4ba simplify the asprintf() failure handling in add_fsname_auto()
Contrary to what I naively thought, the contents of fsauto_names
is undefined if asprintf(&fsauto_names) and this was fixed by
a052e0b60a "check return code of asprintf".

But we can simplify this code a bit. If we rely on return value from
asprintf(), we can simply nullify fsauto_names on failure and avoid
the assymetrical "return false".

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-24 14:33:55 +03:00