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

295 Commits

Author SHA1 Message Date
Andrey Vagin
bd8b2b0f11 restore: shmems -- Remap shmems to use in restorer
Signed-off-by: Andrey Vagin <avagin@openvz.org>
[gorcunov: log error in restorer.c]
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-26 23:54:18 +04:00
Andrey Vagin
99eb3d09c5 restore: shmem - Add self-contained shem's memory region
The next patch will remap shmems region and will use it in restorer.
Actually this patch moves shmem_nr to struct shmems.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
[gorcunov: Various tuneups]
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-26 23:54:18 +04:00
Andrey Vagin
74a56b8c5a restore: pipes -- Don't poll, use wait-helpers instead
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-26 23:54:18 +04:00
Cyrill Gorcunov
fd7543e6e5 Gather futex helpers into lock.h
Based-on-patch-from: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrey Vagin <avagin@openvz.org>
2011-12-26 23:54:18 +04:00
Pavel Emelyanov
c5eb61e866 Unix sockets initial support
Currently it can only work with stream sockets, which have no skbs in queues
(listening or established -- both work OK).

The cpt part uses the sock_diag engine that was merged to Dave recently to
collect sockets. Then it dumps sockets by checking the filesystem ID of a
failed-to-open through /proc/pid/fd descriptors (sockets do not allow for
such tricks with opens through proc) against SOCKFS_TYPE.

The rst part is more tricky. Listen sockets are just restored, this is simple.
Connected sockets are restored like this:

1. One end establishes a listening anon socket at the desired descriptor;
2. The other end just creates a socket at the desired descriptor;
3. All sockets, that are to be connect()-ed call connect. Unix sockets
   do not block connect() till the accept() time and thus we continue with...
4. ... all listening sockets call accept() and ... dup2 the new fd into the
   accepting end.

There's a problem with this approach -- socket names are not preserved, but
looking into our OpenVZ implementation I think this is OK for existing apps.

What should be done next is:

1. Need to merge the file IDs patches in our tree and make Andrey to
   support files sharing. This will solve the

	sk = socket();
	fork();

   case. Currently it simply doesn't work :(

2. Need to add support for DGRAM sockets -- I wrote comment how to do it
   in the can_dump_unix_sk()

3. Need to add support for in-flight connections

4. Implement support for UDP sockets (quite simple)

5. Implement support for listening TCP sockets (also not very complex)

6. Implement support for connected TCP scokets (hard one, Tejun's patches are not
   very good for this from my POV)

Cyrill, plz, apply this patch and put the above descriptions onto wiki docs (do we
have the plans page yet?).

Andrey, plz, take care of unix sockets tests in zdtm. Most likely it won't work till
you do the shared files support for sockets.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-26 23:25:04 +04:00
Pavel Emelyanov
bf7a74d47e Helper for moving image fd
When opening an fd at a position where the current image fd sits
the latter one should be moved.

Introduce a helper for this.

Signed-off-by; Pavel Emelyanov <xemul@parallels.com>

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-26 21:53:44 +04:00
Pavel Emelyanov
99cc87949f reopn_fd_as return code fixlet and cleanup
Nobody cares the returned fd, so just make it 0/-1 and clean up the callers.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-26 21:53:36 +04:00
Cyrill Gorcunov
d6eab944e3 Move logging functions to log.c
Instead of keeping all unrelated to
C/R procedure helpers in util.c move
logging related helpers to log.c.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-19 18:52:50 +04:00
Cyrill Gorcunov
12ea815642 restore: We should check for error returned in get_image_path
This as well implies we change paths to PATH_MAX size.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelianov <xemul@parallels.com>
2011-12-19 15:32:27 +04:00
Andrey Vagin
4ba93d0806 pipe: initialize fields in pipe_info properly.
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-16 16:26:42 +04:00
Cyrill Gorcunov
c1350f9ab1 Make error codes returned being a negative value
We have a mess in our return codes:
some functions return negative values,
while others -- positive.

Sanitize the return codes and make error
condition to return negative values.

Reported-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-13 15:03:33 +04:00
Andrey Vagin
57e8e3e8b2 restore: A child should not return to parent code.
Otherwise it may begin to restore a parent objects...

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-09 20:37:41 +04:00
Andrey Vagin
85b991c251 pipe: Don't redefine the variable ret
For this reason a function may return success in case of error.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-09 20:37:32 +04:00
Andrey Vagin
92a694cf14 pipe: re-execute splice if not all data have been transferred.
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-09 20:37:11 +04:00
Andrey Vagin
dd444aac9b pipe: avoid intersection of pipe descriptors.
1. pipe() returns two descriptors with numbers (r: x, w: y).
We may want to restore it as (r: y, w: x).
2. Close a extra end, before try to restore a target end.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-09 20:36:51 +04:00
Cyrill Gorcunov
6840bcc4d4 restore: Move struct pipe_list_entry at top of file
Stage structures in one place.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-09 15:39:08 +04:00
Cyrill Gorcunov
bf9a873866 restore: Drop bogus comment
Even u64 address might consume not greater
than 20 bytes of string so 128 is enough and
safe here.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-09 15:14:16 +04:00
Cyrill Gorcunov
870803fb5f image: Shrink signal entry structure
Since we use pure syscalls there is no
need to keep intermediate layer for signals.

Moreover mask entry moved at the end of the structure
so we will easily expand it if it'll be ever needed.

Note it breaks backward compatibility with older image
but since it's development stage it should be safe.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
2011-12-08 19:36:26 +04:00
Andrey Vagin
ecc2776fc9 pipe: fix deadlock
Probably all of you know about "lock inversion". There was a similar
problem on restoring pipes.

One process try to restore pipe1 and waits when another process attached
to it.  In this time another process restores pipe2 and waits too.

I know two solves.
1. Open all pipes -> attach to them -> close unnecessary ends.
This method has a problem, if only one end belongs to the process.  In
this cases another end occupies a descriptor, which may be needed to
another pipe.

2. Restore pipes in the same order. This patch does that.
A sorted list of pipe entries are constructed.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelianov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-08 17:17:04 +04:00
Andrey Vagin
c53972cdc0 pipe: change calculation of pipes users
This patch removed stange logic about minusers.
Now we calculate foreign users only.

The main idea of this patch, that we bind a pipe ends to correct
descriptos immediately.

When a process X creates a pipe, we have two cases:
1. Both ends belongs to this process. It's simple, we bind both ends
   to their descriptors and we go further.
2. Only one end of a pipe belongs to this process. In this case we are
   waiting all foreign users and we go futher.
In second case we should wait, because a end which doesn't belong to
this process occupies a file descriptor, which may be used by another
pipe.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelianov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-08 17:17:00 +04:00
Andrey Vagin
4c479da259 Dump and restore current work directory (v2)
CWD is saved as file descriptor with number -1.

v2: use dump_regular_file

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-07 17:16:41 +04:00
Andrey Vagin
d261cf7958 Use absolute path for image files
Now I try to restore CWD and a relative path will be invalid.

Add new options -D to set image files directory.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-07 17:16:37 +04:00
Andrey Vagin
2c237b6973 Don't use standard descriptors for logging
The standard descriptors may be redirected.

crtool dumplicates stderr in rlimit.maxfileno-1 and this descriptor
is inherited by all children and will be closed before sigreturn.

Known issues:

 - The logging descriptor may be used by a target process and
   a resume will fail.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-05 12:07:52 +04:00
Cyrill Gorcunov
53c611b630 dump,restore: Use rt_sigaction_t for sys_sigaction
Since we operate with syscalls directly we are
to convert signal's structures between image and
kernel formats, without intermediate glibc layer.

Note this involves chaging sa_entry::flags to u64
(since it's long int value in kernel).

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-03 17:24:05 +04:00
Cyrill Gorcunov
8a647a582e dump/restore: signals -- Use struct sa_entry for managing the signals
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2011-12-02 23:17:30 +04:00
Andrey Vagin
315b798182 Block all signals before sigreturn
sigactions are restored before memory and if a parent get a signal
which has a handler, it will get segmentation fault.

This problem will disappear, when we add a freezer, because
all processes will be resumed after restoring.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-02 16:11:41 +04:00
Cyrill Gorcunov
fa28f40aaa restore: Tune up the resident code to restore threads via last-pid concept
v2:
 - Pavel reported there is no need to lock/unlock
   last-pid file in cycle, just lock it once before
   threads creation and unlock at the end.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2011-12-02 13:41:34 +04:00
Cyrill Gorcunov
8d36f08765 restore: Switch to the new ns_last_pid kernel facility while forking children
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2011-12-01 18:53:20 +04:00
Andrey Vagin
baf69d6757 Don't overwrite sigaction magic
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2011-12-01 18:26:35 +04:00
Andrey Vagin
c04cffb7ce Restore pipe flags
pipe_loop00 passed with this patch.

When we restore a regular fd (not pipe) we do use flags
directly in open() call.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-11-30 22:04:20 +04:00
Andrey Vagin
25434884e1 Dump and restore sigactions (v2)
A parasite code dumps all sigactions in sigact.pid.

v2: remove hard code for sizeof(sigset_t)

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-11-30 22:04:09 +04:00
Cyrill Gorcunov
9eeb003766 util: Add K/M/G bytes helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-24 15:07:03 +04:00
Cyrill Gorcunov
f139959ead restore: Don't use +x permission for .out files
We don't execute them anymore.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-23 01:22:37 +04:00
Cyrill Gorcunov
7ce2761007 restore: Check for incomplete reading of vma-entry
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-23 01:18:01 +04:00
Cyrill Gorcunov
2beec2268b restore: Update error messages
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-23 01:12:38 +04:00
Cyrill Gorcunov
7b8dee7275 restore: Use pr_perror instead of plain perror
This prints line number as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-23 00:56:58 +04:00
Cyrill Gorcunov
46083e9e00 restore: Don't forget to skip data on attached pipes
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-22 13:12:30 +04:00
Cyrill Gorcunov
6357ad403f restore: Fix up message on fixing maps
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-21 20:38:35 +04:00
Cyrill Gorcunov
d0eec0e271 restore: Drop self-vmas file once it's not needed
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-18 22:30:32 +04:00
Cyrill Gorcunov
d9aa7f021c restore: Add mutexes via futex syscall and order threads creation
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-18 16:09:01 +04:00
Cyrill Gorcunov
01f8f8f4d1 restore: Bring trivial locker back
Threads are better to be restored in serialized
way otherwise if some error happened an error
message will be screwed.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-17 00:59:08 +04:00
Cyrill Gorcunov
a095617253 restore: Simplify sigreturn code
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-16 18:19:24 +04:00
Cyrill Gorcunov
b712182308 Gather file names formats in one place
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-15 18:35:55 +04:00
Cyrill Gorcunov
0fd17a08cb Bring some order in usage of VMA entries helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-15 17:12:29 +04:00
Cyrill Gorcunov
ce40f5d96f restore: Fix restoration of anonymous shared vmas
And rename prepare_and_execute_image to
prepare_and_sigreturn which is more appropriate
name here.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-14 17:23:23 +04:00
Cyrill Gorcunov
6a26e75aba cleanup: Drop elf references
We dont use Elf restore anymore, drop it.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-13 13:07:00 +04:00
Cyrill Gorcunov
3e72543422 restore: Handle process tree correctly
pstree file is a single one for all processes and
threads so skip non-matched entries correctly.

This brings testee test back to life.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-13 12:57:16 +04:00
Cyrill Gorcunov
1e7bbd35de restore: Add threads restoration
Now threads restortion (and TLS as well) works.
Threads test reports the following

    2775 (main): Counter value:    3 tls_data =    1
    2775 (main): ( 0) fsgs_base 7f9597aa46f0
    2775 (main): ( 0) fsgs_base        0
    2775 (thr3): Counter value:    4 tls_data =    4
    2775 (thr3): ( 0) fsgs_base 42c57940
    2775 (thr3): ( 0) fsgs_base        0
    2775 (thr2): Counter value:    3 tls_data =    2
    2775 (thr2): ( 0) fsgs_base 42456940
    2775 (thr2): ( 0) fsgs_base        0
    2775 (thr1): Counter value:    4 tls_data =    3
    2775 (thr1): ( 0) fsgs_base 40c62940
    2775 (thr1): ( 0) fsgs_base        0
    2775 (main): Counter value:    4 tls_data =    1
    2775 (main): ( 0) fsgs_base 7f9597aa46f0
    2775 (main): ( 0) fsgs_base        0
    2775 (thr1): Counter value:    5 tls_data =    3
    2775 (thr1): ( 0) fsgs_base 40c62940
    2775 (thr1): ( 0) fsgs_base        0

as expected.

This commits merges all preliminary commits into
the final one (sigreturn branch was always experimental
and forced update).

Still some problems remain:

1) While creating threads with clone() the
   flags are to be revisited. We use some predefined
   set here but it's not really correct.

2) No setup of pids in PCB thread zone.

3) No restore of FPU.

But at least on some basic tasks restore works well.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-12 19:26:40 +04:00
Cyrill Gorcunov
20c3bf1033 restore: 32k of stack memory is enough
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-08 01:44:40 +04:00
Cyrill Gorcunov
275e97c77d restore: Increase the stack size for cloned processes
Wasted a couple of hours trying to resolve this non-obvious
issue. It's because bootstrapping the restorer code might
requre more memory than 16K on stack. Strictly speaking
we need a compile time constant here and BUG_ON.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-07 22:58:18 +04:00