2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-24 10:58:36 +00:00

129 Commits

Author SHA1 Message Date
Cyrill Gorcunov
a90172df43 reg-files: Don't mangle ghost directories
Because directories are opened via direct mkdir
call with name taken from ghost path don't postfix
it with cr.%x.ghost, otherwise that's the name
directory will have after restore complete causing
cwd01 test to fail.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-23 20:27:38 +04:00
Cyrill Gorcunov
8644d2ba83 files-reg: Add try_collect_special_file
The idea is to be able to lookup for special id
which might be not present and we should not
yield the error.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-23 17:51:49 +04:00
Cyrill Gorcunov
cb546f8448 files-reg: Don't generate ghost files for hanged out slave pty peers
We will use reg-files engine for tty c/r so lets prepare scaffolds
here preventing the engine to generate ghost files for PTY peers
(mostly because one can't create slave peers without opening
 master peers first which is a sole part of tty engine itself).

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-23 17:51:37 +04:00
Cyrill Gorcunov
4b9406eae2 files-reg: Strip off "(deleted)" postfix on ghost files
Otherwise this postfix will be accumulated on
subsequent checkpoints.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-23 17:51:35 +04:00
Cyrill Gorcunov
a944a78ce9 files-reg: Export do_open_reg_noseek_flags
We will need it for tty restore.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-23 17:51:33 +04:00
Pavel Emelyanov
198c93656c pstree: Add helper for adding helpers to pstree
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-14 18:02:36 +04:00
Pavel Emelyanov
295090c1ea img: Introduce the struct cr_img
We want to have buffered images to speed up dump and,
slightly, restore. Right now we use plan file descriptors
to write and read images to/from. Making them buffered
cannot be gracefully done on plain fds, so introduce
a new class.

This will also help if (when?) we will want to do more
complex changes with images, e.g. store them all in one
file or send them directly to the network.

For now the cr_img just contains one int _fd variable.

This patch chages the prototype of open_image() to
return struct cr_img *, pb_(read|write)* to accept one
and fixes the compilation of the rest of the code :)

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
2014-09-30 21:48:13 +04:00
Pavel Emelyanov
5f2a7ac27b img: Rename fdset -> imgset
Since we're going to switch from int-fd-s to class-image
soon the fdset name will not fit into the new terminology.

This patch is

 sed -e 's/fdset/imgset/g' -i *
 sed -e 's/imgset_fd/img_from_set/g' -i *
 git mv include/fdset.h include/imgset.h

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
2014-09-30 21:48:10 +04:00
Cyrill Gorcunov
78bbb0a161 files-reg: Simplify have_seen_dead_pid
We've a special helper xrealloc_safe for reallocs.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-09-30 17:50:53 +04:00
Pavel Emelyanov
cf8c9ae870 vma: Reshuffle the struct vma_area
We have some fields, that are dump-only and some that
are restore only (quite a lot of them actually).

Reshuffle them on the vma_area to explicitly show which
one is which. And rename some of them for easier grep.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-09-29 13:19:55 +04:00
Tycho Andersen
bbe3f941db remap: don't add remaps for a dead pid more than once
Unless we seek and re-read the PB images, the only way I can see to do this is
to keep a list of the previously seen dead pids and check if a new remap is in
that list.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-09-23 20:39:28 +04:00
Tycho Andersen
80c4e86e87 remap: don't try to remap other files in /proc
We can't remap these files correctly anyway, so we should just return success
if we find one of these files to remap.

v2: don't try to remap accessible files in /proc

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-09-23 20:38:38 +04:00
Tycho Andersen
f020bef776 remap: add a dead pid /proc remap
If a file like /proc/20/mountinfo is open, but 20 is a zombie (or doesn't exist
any more), we can't read this file at all, so a link remap won't work. Instead,
we add a new remap, called the dead process remap, which forks a TASK_HELPER as
that dead pid so that the restore task can open the new /proc/20/mountinfo
instead.

This commit also adds a new stage CR_STATE_RESTORE_SHARED. Since new
TASK_HELPERS are added when loading the shared resource images, we need to wait
to start forking tasks until after these resources are loaded.

v2: fix a mutex bug

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-09-19 17:42:48 +04:00
Tycho Andersen
6b70e4ad81 remap: add remap_type field and use it
Maintain backwards compatibility for old images, but don't set the REMAP_GHOST
bit going forward, only use the remap_type field.

v2: * preserve remap_id in GHOST_REMAP case
    * protobuf field is remap_type enum not u32

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-09-18 20:24:48 +04:00
Andrey Vagin
c049d8452d files: don't check uninitialized memory in create_link_remap()
Look at this strace output:
107   linkat(45, "", 1017, "./root/git/orig/criu/test/zdtm/live/static/unlink_fstat03.test (deleted)/link_remap.4", AT_EMPTY_PATH) = -1 ENOENT (No such file or director

It's obvious, that we didn't cat the file name.

Here is an error in calculation of offset for the last symbol.
The current version of code sets this offset in strlen(),
but it's actually strlen() - 1.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-20 14:02:43 +04:00
Andrey Vagin
339f456af3 link-remap: open link-remap files from correct mountpoints (v3)
Here is a problem with ghost files. Links are created on restore, but
they can't be created on any mount point, because a mount point can be
non-root bind-mount of another one. So we need to find the root mount
and create all links there.

v2: clean up
v3: add optimization for the case when both links on the same mount
point.
v4: don't look up mount points by mnt_id in a second time.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-06 19:14:16 +04:00
Pavel Emelyanov
9fd793e565 stat: Pass namespace into phys_stat_resolve_dev, not mnt tree
This makes the API simpler.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-06 10:57:27 +04:00
Pavel Emelyanov
394096b17c files-reg: Sanitize rlb and rlb->path malloc/rollback code flow
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-06 09:37:27 +04:00
Pavel Emelyanov
5552f9e727 files-reg: Don't dereference pointer before its NULL check
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-06 09:37:21 +04:00
Andrey Vagin
b8c93feb1e file: use ralative path for retoring files
openat() is used to open files, so absolute pathes can't be used

v2: change the comment
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-05 16:40:17 +04:00
Andrey Vagin
85b3d86e5b ghost: create ghost devices and directories in a specified ns
Here is a bug now. A path for devices and directories should be
generated with a specified root.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-05 16:38:40 +04:00
Andrey Vagin
967dba606a mount: add helper mntns_get_root_by_mnt_id
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-05 16:38:19 +04:00
Pavel Emelyanov
9c0c23c067 files: Don't unlink ghost directory
It will be rmdir-ed a bit later.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-07-04 15:55:52 +04:00
Pavel Emelyanov
e2ab347415 files: Initialize remap->is_dir for linked remap (to false)
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-07-04 15:52:09 +04:00
Pavel Emelyanov
ba8671b4c1 files: Split open_reg_by_id into two parts
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-07-04 15:09:04 +04:00
Pavel Emelyanov
d0097b2db0 files: Support ghost directories restore
If we have opened and rmdir-ed directory, the dump works OK
creating the ghost file and remap, but restore creates _file_
instead of directory.

Fix this.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-07-04 15:08:59 +04:00
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