2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-23 02:17:22 +00:00

241 Commits

Author SHA1 Message Date
Pavel Emelyanov
827a86287c files: Print file type for BUG
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-05-29 13:57:18 +03:00
Kir Kolyshkin
4f9e509c15 restore_fs(): don't leak fds on error
First, if we can't open dd_cwd, we leak opened dd_root.

Second, if chroot(dd_root) fails, we leak opened dd_cwd.

Instead of adding more close() statements in place, let's
change the code to close both fds on exit path.

Reported by Coverity, CID 51639, CID 51631.

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-08 15:32:09 +03:00
Kir Kolyshkin
8d11952f6b serve_out_fd(): don't leak fd on error
Reported by Coverity, CID 51629.

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-08 15:32:00 +03:00
Andrey Vagin
25267e5b30 lock: parse the lock field in fdinfo if it's avaliable (v2)
/proc/locks can contain a wrong pid for a lock and we always need to
check this fact.  Starting with the 4.1 kernel, locks are reported
in fdinfo.

v2: rebase to the curret master
    skip note_file_lock()

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-27 14:53:24 +03:00
Pavel Emelyanov
eff166e98c fdinfo: Don't hide fdinfos' restore errors
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-09 23:14:11 +03:00
Cyrill Gorcunov
243e58f0e3 tty: Implement support of current tty
Opening current tty is tricky: first slave peer should
be opened and session restored, and only then we can
open /dev/tty. So that I made rst_info to carry
additional list @tty_ctty where all current ttys
get gathered and opened after slave peers were
brought to live.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-02 20:20:08 +03:00
Andrey Vagin
b23268e492 service: add ability to set inherit file descriptors (v3)
This is required to use criu swrk in libcontainer.

v2: remove useless function declaration
    allow to set inherit_fd only for swrk
v3: check swrk out of loop

Cc: Saied Kazemi <saied@google.com>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-30 13:09:25 +03:00
Pavel Emelyanov
f7f76d6ba6 img: Introduce empty images
When an image of a certian type is not found, CRIU sometimes
fails, sometimes ignores this fact. I propose to ignore this
fact always and treat absent images and those containing no
objects inside (i.e. -- empty). If the latter code flow will
_need_ objects, then criu will fail later.

Why object will be explicitly required? For example, due to
restoring code reading the image with pb_read_one, w/o the
_eof suffix thus required the object to be in the image.

Another example is objects dependencies. E.g. fdinfo objects
require various files objects. So missing image files will
result in non-resolved searches later.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-13 14:42:54 +03:00
Pavel Emelyanov
e29c9daec2 img: Remove O_OPT and COLLECT_OPTIONAL
Current code doesn't make any difference between OPT and no-OPT
except for the message is printed or not in the open_image().
So this particular change changes nothing but the availability of
this message.

In the next patches I wil introduce "empty images" to deal with
the ENOENT situation in a more graceful manner.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-13 14:42:01 +03:00
Andrey Vagin
aa2d920824 files: use PROC_SELF when a process accesses its /proc/PID
If a process is executed in another pidns, a /proc/PID doesn't link with
the proper process.

This patch fixes a problem like this:
   1: Error (util.c:106): Unable to close fd 33: Bad file descriptor

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-02-09 14:06:13 +03:00
Pavel Emelyanov
455f9b564e fd: Factor out inheriting FDs code
We have two places where we lookup the inherited-fd list
by name and dup() the descriptor found. I propose to factor
out this piece in a single inherited_fd() call. When
we will want to support inheritance for sockets or any
other files we'll simply add the inherited_fd() call
there.

I'm also thinking about moving the call to inherited_fd
into generic level, but the open_path() routine doesn't
allow to do it in a simple manner.

Also we have not yet finished issue with files-vs-inodes
mapping. Keeping all the logic in one function should
make the solution simpler.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-12 14:46:51 +03:00
Pavel Emelyanov
8f691c40d5 fd: Mark inherit_fd_lookup_fd static
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-12 14:46:42 +03:00
Saied Kazemi
b2e6690409 Explain how an inherit fd can be reused.
Add comment to inherit_fd_reused() explaining how an inherit fd may be
closed or reused outside the inherit fd logic.

Signed-off-by: Saied Kazemi <saied@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-12-19 18:50:39 +03:00
Saied Kazemi
0412152fc5 Add inherit fd support
There are cases where a process's file descriptor cannot be restored
from the checkpoint images.  For example, a pipe file descriptor with
one end in the checkpointed process and the other end in a separate
process (that was not part of the checkpointed process tree) cannot be
restored because after checkpoint the pipe will be broken.

There are also cases where the user wants to use a new file during
restore instead of the original file at checkpoint time.  For example,
the user wants to change the log file of a process from /path/to/oldlog
to /path/to/newlog.

In these cases, criu's caller should set up a new file descriptor to be
inherited by the restored process and specify the file descriptor with the
--inherit-fd command line option.  The argument of --inherit-fd has the
format fd[%d]:%s, where %d tells criu which of its own file descriptors
to use for restoring the file identified by %s.

As a debugging aid, if the argument has the format debug[%d]:%s, it tells
criu to write out the string after colon to the file descriptor %d.  This
can be used, for example, as an easy way to leave a "restore marker"
in the output stream of the process.

It's important to note that inherit fd support breaks applications
that depend on the state of the file descriptor being inherited.  So,
consider inherit fd only for specific use cases that you know for sure
won't break the application.

For examples please visit http://criu.org/Category:HOWTO.

v2: Added a check in send_fd_to_self() to avoid closing an inherit fd.
    Also, as an extra measure of caution, added checks in the inherit fd
    look up functions to make sure that the inherit fd hasn't been reused.
    The patch also includes minor cosmetic changes.

Signed-off-by: Saied Kazemi <saied@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-12-10 12:48:30 +03:00
Andrey Vagin
a19e945f6e restore: don't leak a transport socket
CID 73354 (#1 of 1): Resource leak (RESOURCE_LEAK)
9. leaked_handle: Handle variable sock going out of scope leaks the handle

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-05 15:45:33 +04:00
Cyrill Gorcunov
81c598cc05 files: Add file_desc_init helper
To use it in tty code even when file
descriptor is not added into files chain.

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:32 +04:00
Cyrill Gorcunov
09aa15c7a3 tty: Parse slave peer index from fd_parms
We will use this path in reg-files engine anyway
so simply switch to this ability now.

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:30 +04:00
Cyrill Gorcunov
bcc1f4eb72 tty: Introduce tty types
Instead of calling case() with majors all over the places lets
introduce own enum for tty types and use it instead.

Because we're using not @major numbers now but taking @minors
into account as well, this brings more strict check of which
kind of terminals we can dump now thus it's potentially should
fix the cases when we're trying to c/r terminals which we don't
understand yet (in particular /dev/console [5:1]).

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:26 +04:00
Tycho Andersen
66d1a60ed4 restore: don't race when closing cg yard
TASK_HELPERs are created with CLONE_FILES, so if we always close the cg yard
here, it will close it for the other helpers and cause problems. Instead, we
close it much later, in code only called by alive tasks, to ensure that there
is no conflict.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-08 19:08:12 +04:00
Pavel Emelyanov
c443b03e10 rst: Rework the rst_info referencing
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-01 13:34:38 +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
42821edccf img: Use errno when checking optional images open fail
There will be no int-fd soon, so one more preparation
to this fact.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
2014-09-30 21:48:11 +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
Pavel Emelyanov
829d433252 fd: Close caches proc-pid stuff before restoring files
We have a bug. If someone opens proc with open_pid_proc or alike
with PROC_SELF of real PID before going to restore fds, then the
fd cached by proc helpers would be cached in fd 0 (we close all
fds beforehead) and it may clash with restored fds.

We don't hit this right now simply due to being too lucky -- we
call open_proc(PROC_GEN) on "locks" which first closes the cached
the per-pid descriptor and then reports back just the /proc one
which sits in service area.

But once we change this (next patch) things would get broken.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-09-29 13:21:31 +04:00
Pavel Emelyanov
53537f52c8 locks: Don't dump locks in per-task manner (v3)
We have a problem with file locks (bug #2512) -- the /proc/locks
file shows the ID of lock creator, not the owner. Thus, if the
creator died, but holder is still alive, criu fails to dump the
lock held by latter task.

The proposal is to find who _might_ hold the lock by checking
for dev:inode pairs on lock vs file descriptors being dumped.
If the creator of the lock is still alive, then he will take
the priority.

One thing to note about flocks -- these belong to file entries,
not to tasks. Thus, when we meet one, we should check whether
the flock is really held by task's FD by trying to set yet
another one. In case of success -- lock really belongs to fd
we dump, in case it doesn't trylock should fail.

At the very end -- walk the list of locks and dump them all at
once, which is possible by merge of per-task file-locks images
into one global one.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-09-02 17:44:46 +04:00
Cyrill Gorcunov
ecd432fe27 timerfd: Implement c/r procedure
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-06 19:20:09 +04:00
Pavel Emelyanov
590765164c files: Don't double-close the image fd on error
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-06 09:37:32 +04:00
Pavel Emelyanov
49f27969f5 files: Don't fail on missing fs.img for zombies
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-07-04 15:52:29 +04:00
Pavel Emelyanov
a919dbc9c6 files: Fix restoration of ghost cwd (and root)
When cwd is removed (it can be) we need to collect the respective
file_desc before starting opening any files to properly handle
ghost refcounts. Otherwise we will miss one refcount from the
cwd's on ghost, which in turn will either BUG inside ghost removal,
or will fail the cwd due to the respective dir being removed too
early.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-07-04 15:09:06 +04:00
Pavel Emelyanov
9b91bf390d files: Split fs restore into prepare and restore
The prepare one will become more complicated soon.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-07-04 15:09:03 +04:00
Pavel Emelyanov
b8d01d1b7a files: Rename prepare_fs into restore_fs
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-07-04 15:09:02 +04:00
Pavel Emelyanov
72a9372aff fs: Opening FE-s after fchdir doesn't work
It uses absolute file names, so any open-s should happen _before_
we change tasks' root.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-06-10 17:47:32 +04:00
Pavel Emelyanov
7aa7e95f7e fs: Don't hide error from prepare_fs
If fchroot() succeeds the further failures don't get
noticed by caller.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-06-10 17:47:31 +04:00
Pavel Emelyanov
701f883765 restore: Do fchroot() via proc helpers
There's no such thing as fchroot() in Linux, but we need to do
chroot() into existing file descriptor. Before this patch we did
this by chroot()-ing into /proc/self/fd/$fd. W/o proc mounted it's
no longer possible, so do this like

fchdir(proc_service_fd);
chroot("./self/fd/$root_fd");
fchdir($cwd_fd);

Thanks to Andrey Vagin for this trick ;)

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-06-09 15:29:50 +04:00
Andrey Vagin
22d384536d files-ids: generate id-s accoding with mnt_id, st->st_dev and st->st_ino
One device can be mounted a few times, so files are identical only,
if they have the same mnt_id.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-21 22:39:28 +04:00
Andrey Vagin
87b1f5408c files: save mnt_id on fd_param
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-21 22:39:18 +04:00
Andrey Vagin
bed13a58ec proc_parse: parse mnt_id from /proc/PID/fdinfo/FD
It will be used for restoring files from proper mounts.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-09 16:43:50 +04:00
Andrey Vagin
8bcffef6b9 proc_parse: parse fdinfo to get pos and flags
We are going to parse fdinfo for getting mnt_id,
so we can take there pos and flags and don't call
fcntl and lseek for that.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-09 16:42:53 +04:00
Cyrill Gorcunov
777255fb2c files: predump_one_fd -- Use direct read of pid's fd link
Using O_PATH known to be buggy on 3.11 kernel so use
direct link reading procedure here.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-02 15:51:37 +04:00
Andrey Vagin
35ed09fe53 files: print a correct minor numbers for unsupported character devices
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-04-02 15:49:27 +04:00
Cyrill Gorcunov
1153f225ff image: Add O_OPT when trying to open optional image files
During the time some files become obsolete and might be missing
in checkpoint image set, but to keep backward compatibility we
still trying to open them, which might print out error like

 | Unable to open 'path-to-file'

and confuse a reader why criu prints error but continue working.

To eliminate this problem O_OPT flag has been introduced in
commit 16b5692061e2, which suppress error message priting
if the flag is set.

Now start using O_OPT in the following functions

 - open_irmap_cache: irmap cache is relatively new optional feature

 - prepare_rlimits, open_signal_image, restore_file_locks,
   prepare_fd_pid, prepare_mm_pid, collect_image: all these
   helpers are trying to open image files which can be missing.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-03-17 14:21:21 +04:00
Andrey Vagin
307a5e1027 pre-dump: avoid sleeping in the open() syscall
For example opening the FIFO blocks until the other end is opened also.

We can use O_PATH to avoid sleeping in the open() call.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-03-13 16:16:43 +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
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
3de41b8070 files: Rework select_ps_list fdsec ops callback
For unlinked opened and mmaped files we'd need to
care about remaps, for this the callback with both
file_desc and fdinfo_list_entry will be required.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-05 16:17:59 +04:00
Pavel Emelyanov
9857acc0a2 files: Pass stat information into fd_id_generate
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-05 16:17:41 +04:00
Pavel Emelyanov
bd7bf7bd39 anon-inode: Don't readlink fd/fd multiple times
The is_foo_link readlinks the lfd to check. This makes
anon-inodes dumping readlink several times to find proper
dump ops. Optimize this thing.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-02 22:14:29 +04:00
Pavel Emelyanov
751856c8b8 files: Pre-dump file descriptors
We will generate some info about file-descriptors at that
stage. For now these pre-dumped ones would be fsnotifies,
so the pre-dump of a single fd is written as simple as
possible, but enough for that type of FDs pre-dump.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-01-30 16:20:15 +04:00
Pavel Emelyanov
839a3c6122 files: Don't call fstatfs twice
When filling fd_parms we do call statfs, no need to call it
again later.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-01-29 20:09:27 +04:00
Pavel Emelyanov
52dec20a17 files: Save fstype on fd_parms
We will need to special-care NFS silly-rename files, thus
we need to know which FS a file belongs to.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-27 21:14:09 +04:00