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

103 Commits

Author SHA1 Message Date
Pavel Emelyanov
a9f765894e files: Support ghost devices
When we have opened and unlinked chr or blk device, we
shouls also take care of their rdev value. Thus -- new
field in image and some new steps on dump and restore.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-07-03 13:28:56 +04:00
Pavel Emelyanov
8e21401aa2 files: Split ghost collecting routine
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-07-03 13:28:41 +04:00
Andrew Vagin
8b58c98086 files: Fix compilation on PI (a2)
Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-25 16:08:06 +04:00
Andrey Vagin
f5b67f5148 files: Fix compilation on PI
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-25 14:13:00 +04:00
Pavel Emelyanov
fac7befa6b files: Sanity check for reg file on restore is not corrupted
When opening a reg file on restore -- check that the file size we
opened matches the on we saw on dump. This is not bullet-proof protection,
but is helpful to protect against FS updates between dump/restore.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-24 23:38:48 +04:00
Pavel Emelyanov
8a07349388 files: Fix open_path() to provide mntns root fd to callbacks
This fixes the support for fifo-s in mount namespaces and
makes it easier to control the correct open_path() usage in
the future.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-06 12:20:02 +04:00
Pavel Emelyanov
f22591c99a files: Check for for mount to exist only once
The nsid lookup will search for mount in case mnt_id
is given. No need to do it twice (the 2nd time for
sanity check).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-23 03:01:21 +04:00
Pavel Emelyanov
68e2841a9b mnt: Turn mntns_get_root_fd into accepting mnt ns_id
The only exception (for now) is the irmap -- it should
operate on ns as well.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-23 02:31:16 +04:00
Pavel Emelyanov
1c4f8fdcc2 remap: Keep nsid on remap rollback, not the ns' pid
This is more logical -- we should remap file in namespace,
not in pid. Also this would help to clean the code further.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-23 02:23:46 +04:00
Pavel Emelyanov
1435617c40 mnt: Rename _collect_root into _get_root_fd
Nowadays this routine is mainly used for getting an
fd, rather than keeping one for future reference.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-23 01:38:58 +04:00
Andrey Vagin
2f4be997b6 mount: use per-namespace mntinfo_tree (v2)
This patch removes the global mntinfo_tree and collect_mount_info where
it was constructed. The mntinfo list is filled from dump_mnt_ns,
rst_collect_local_mntns, collect_mnt_namespaces and read_mnt_ns_img.

A mountinfo entry contains a reference on a proper ns_id entry, so
we cau use mnt_id to look up a proper mount namespace.

v2: remove trash after rebasing.
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-21 22:40:19 +04:00
Andrey Vagin
6639464503 files: save mnt_id for reg files
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-21 22:39:25 +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
Jamie Liu
963f8a062c files-reg: fix "criu: fix filemap open permissions"
Fixes two issues with efe594f8f421 "criu: fix filemap open permissions":

- Permissions on files with both open file descriptors and mappings.

- Restore compatibility with dumps created by previous versions of criu.

Signed-off-by: Jamie Liu <jamieliu@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-07 13:20:19 +04:00
Jamie Liu
efe594f8f4 criu: fix filemap open permissions
An mmaped file is opened O_RDONLY or O_RDWR depending on the permissions
on the first vma dump_task_mm() encounters mapping that file. This
causes two problems:

1. If a file has multiple MAP_SHARED mappings, some of which are
   read-only and some of which are read-write, and the first encountered
   mapping happens to be read-only, the file will be opened O_RDONLY
   during restore, and mmap(PROT_WRITE) will fail with EACCES, causing
   the restore to fail.

2. If a file is opened read-write and mapped read-only, it will be
   opened O_RDONLY during restore, so restore will succeed, but
   mprotect(PROT_WRITE) on the read-only mapping after restore will
   fail.

To fix both of these, record open flags per-vma based on the presence of
VM_MAYWRITE in smaps.

Signed-off-by: Jamie Liu <jamieliu@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-04 20:35:48 +04:00
Cyrill Gorcunov
204599aa65 headers: Use fs-magic.h
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-28 13:08:00 +04:00
Pavel Emelyanov
756229bb11 files: Create fake name for remapped file if original name is busy
When live-migrating a container on NFS the link-remap cannot
create original file on target machine, since the file name
is still visible -- source CT is alive. The proper fix would
be to move file aside, then create link, then move original
file back, but since NFS changes file name anyway, we just
do the same -- generate another name for link.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-10 15:45:21 +04:00
Pavel Emelyanov
3bf2d6d9e9 files: Fix link vs target names when creating file remaps
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-07 20:49:23 +04:00
Pavel Emelyanov
72a035d7ea files: Add comment to open_path routine
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-07 14:23:38 +04:00
Pavel Emelyanov
109f426ccc files-reg: Sanitize open_xxx routines a bit
After previous fixes we can merge and move a couple
of them for easier reading.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-07 13:59:10 +04:00
Pavel Emelyanov
b0c0933744 fifo: Don't lookup reg path twice
Same for previous patch with vmas -- we do it on collect and
on real open. Just put the pointer on fifo_info structure.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-07 13:55:27 +04:00
Pavel Emelyanov
dc7abdfb92 vma: Don't lookup file_desc for vma twice
We do it first -- on collect, second -- on restore. The
2nd lookup is excessive, we can put fd pointer on vm_area
at lookup and reuse one later.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-07 13:51:29 +04:00
Pavel Emelyanov
4dbc5f11e5 files: Don't call lseek on some restored files
Those opened for cwd, root, exe link and vma-s do not
care about the pos value.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-07 13:31:31 +04:00
Pavel Emelyanov
5e5783b4e4 remap: Initialize linked remaps to 0
With new remap refcount users will get the counter
eventually as they appear.

Reported-by: Andrew Vagin <avagin@parallels.com> via Jenkins
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-05 17:55:22 +04:00
Pavel Emelyanov
490efb4695 files: Properlu count number of users for mmaped/exe-d ghost files
If a file mmaped or pointed by exe link is unlinked, we will
generate a ghost file for it. On restore the ghost file will
be created with the users counter 1 and the very first open
(e.g. for mmap) will unlink the file.

Handle this by bumping up user counter for every mapping
pointing on the file.

This appeared after previous patches that packed the reg-files
image. Before it each vma and exe link created separate entry
in the reg-files image.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-05 16:18:21 +04:00
Pavel Emelyanov
8a827ba403 files: Make fd_id_generate_special return ID into pointer
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-05 16:17:49 +04:00
Pavel Emelyanov
8b611770aa files: Pass stat information into fd_id_generate_special
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-05 16:17:18 +04:00
Pavel Emelyanov
d47d93b2cf files: Dump NFS silly-rename files as linked-remap always
We cannot distinguish ghost files from linked-remap for NFS.
Link count is never 0 on such files and any positive value of
it doesn't mean, that the file will stay in place after we
terminate all tasks we dump -- they can hold multiple unlinked
links on the same file and they all will be delayed-unlined.

Checkinf file path doesn't work as well -- silly-rename files
remain visible by VFS, though they shouldn't :(

Fortunatelly, NFS allows creation of additional likns on such
files, so we just create linked remap for such files.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-27 21:16:33 +04:00
Pavel Emelyanov
dc48dd74f7 files: Pass fs_parms into check_path_remap
To catch NFS silly-rename file we'll need more than just
struct stat there.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-27 21:15:16 +04:00
Cyrill Gorcunov
c1fd865645 files: link remap -- Fix potential buffer overrun
If the former file had a path long enough to be near
PATH_MAX limit, sprintf'ing link_remap.%d here might
overrun the limit. Use snprintf instead.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-26 12:56:31 +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
Andrey Vagin
6bbdec26f3 files: add ability to set callbacks for files (v7)
Here is nothing interecting. If a file can't be dumped by criu,
plugins are called. If one of plugins knows how to dump the file,
the file entry is marked as need_callback. On restore if we see
this mark, we execute plugins for restoring the file.

v2: Callbacks are called for all files, which are not supported by CRIU.
v3: Call plugins for a file instead of file descriptor. A few file
descriptors can be associated with one file.
v4: A file descriptor is opened in a callback. It's required for
    restoring anon vmas.
v5: Add a separate type for unsupported files
v6: define FD_TYPES__UNSUPP
v7: s/unsupp/ext (external)

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-20 16:07:38 +04:00
Kir Kolyshkin
26fda7a319 space-before-tab whitespace cleanup
Remove space before tab characters.

Found by git grep ' 	' (Space, Ctrl-V, Tab in shell).

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-12 10:00:53 +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
Pavel Emelyanov
0efaf212b2 mount: Clean code a bit
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-11 17:19:40 +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
a5785c94bc files-reg: Don't fail matching if ghost file is on BTRFS subvolume
In case if ghost file is on BTRFS subvolume we should not fail
but test if there is a match.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-04 19:23:34 +04:00
Pavel Emelyanov
e42a486f39 files: Extend comment about "overlinked" files dump and restore
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-15 00:26:54 +04:00
Andrey Vagin
4850fd94a8 crtools: move cr_options in a separate header
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-06 18:17:52 +04:00
Andrey Vagin
1300cf4915 crtools: move all stuff about fdset in a separate header
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-06 15:24:48 +04:00
Cyrill Gorcunov
fcfa58026c dump: Don't forget to cleanup link remap if needed
In case if checkpoint is failed or -R option passed
we need to remove link remap files created during
dump procedure.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-01 13:36:07 +04:00
Pavel Emelyanov
b978c6f873 util: Introduce buffer size for carrying /proc/self/fd/N path
There's ... a number of places where we want to do something
with /proc/self/fd/%d path. Each time we guess buffer size
that is enough for this. Make standard constant for this and
save some space on stack and drop args for some functions.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-10-15 13:59:59 +04:00
Pavel Emelyanov
baa2583a1d files-reg: Sanitize ghost files re-opening for read
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-10-15 13:51:35 +04:00
Pavel Emelyanov
b8a85cf57d files: Remove FIXME from comment
Linked remap is implemented already.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-29 10:13:55 +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
Pavel Emelyanov
821621cdb7 files: Don't restore pos when file doesn't support one
It's not quite clean, but on dump non-seekable files dump 0xff...ff into
64-bit pos field of the image. Thus on restore we'd face an error in the
do_open_reg. In order not to have separate helper for non-seekable files
just skip the position restore for such.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-23 16:18:18 +04:00
Pavel Emelyanov
60e6d38868 collect: Shorten common images collecting code
Now we have a set of cinfo-s, it's possible to collect all
this stuff in a plan for-loop.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-21 03:52:18 +04:00
Pavel Emelyanov
64e7d2435a collect: Reduce amount of args to collect_image call
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-21 03:27:06 +04:00
Pavel Emelyanov
9917c4fe34 rst: Compact file-descs collects a bit
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-21 01:06:58 +04:00
Pavel Emelyanov
e03ab6b409 rst: Rework remaps collection on generic collect routine
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-21 00:55:26 +04:00