2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 05:48:05 +00:00

417 Commits

Author SHA1 Message Date
Cyrill Gorcunov
a9969dcf72 restore: Format printing in restore_pipe_data
To align data with previous callers.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-15 22:36:52 +04:00
Pavel Emelyanov
3302183c05 restore: Pass self-vma file descriptor directly
Instead of passing self-vma file path to restorer
code simply open it before restore_task call and
pass descriptor instead. This saves some memory.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-14 14:38:53 +04:00
Pavel Emelyanov
12d4c85410 crtools: Move proc parsing routines to one file
Start with /proc/pid/maps parser

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-14 02:00:26 +04:00
Cyrill Gorcunov
995ef5eca3 Use openat() helper intensively when opening /proc/pid/X files
This allows us to get rid of open-coded "/proc/pid/X".

Based-on-patch-from: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-01-13 18:29:18 +04:00
Cyrill Gorcunov
7a11cfc0b3 restore: No need to track pid of main shmems, open map_files/ via /proc/self
It basically reverts e189efc1763d9cae55e1cafd7aff7ffef6e47303
which was overdone one.

Reported-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-01-13 17:09:08 +04:00
Andrey Vagin
14e42bb704 pipe: fix error code and message
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-11 18:24:40 +04:00
Andrey Vagin
d6a1cd0fbc restore: Learn to work with shared struct file-s
Some process can share one struct file-s, we may find them by "object IDs".
A file descriptor is opened in one process and send to other via unix socket.

The procedure of restoring files contains four stages.
* Collect data about all file's descriptors
  On this stage we find process which will restore a file descriptor and
  create a list of processes, who should get this descriptor.

* Create datagrams unix sockets
  If a file descriptor should be received, a unix socket is created
  instead of it.

* Open file descriptors
  A process with the least pid opens a file and sends this file
  descriptors to all one who wait it.

* Receive file descriptors.

When we were thinking up this algoritm, we wanted to minimize a number
of context switches. A number of context switches is proportional of a
number of processes.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-11 16:01:44 +04:00
Andrey Vagin
7fde5f061b restore: move file-related stuff to a separate file
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-10 18:39:39 +04:00
Cyrill Gorcunov
5d5e8b801c retore: Fix up shared anonymous memory restore procedure
Restorer does really restore shared memory (including page
contents restore) only on master process, while all other
processes do open such memory area via map_files/ procfs entry
so that we might have a situation when shared VMA is present
in some particular core-%d.img file but it's not listed in
collected shmems array and find_shmem_by_pid will return NULL.
This is perfectly fine, be ready for that.

Another issue is that shared memory might look like

CR_FD_SHMEM: /home/cyrill/projects/kernel/crtools/shmem-2641.img
----------------------------------------
0x7f2200775000-0x7f2200776000 id 19664
0x7f2200776000-0x7f2200777000 id 19663
----------------------------------------

So vma area is [x;y) range and we should distinguish two
shmem lookup cases

 - one when we search for page in shmem area
 - second when we lookup shmem area in collected ranges

They both have a different lookup conditions so single
find_shmem splitted into two helpers find_shmem and
find_shmem_page as appropriate.

This patch finally fixes the three process asynchronious
shared memory updates test-case.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 18:31:48 +04:00
Cyrill Gorcunov
1b21a27b0c restore: Simplify shmem_wait_and_open
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:41:05 +04:00
Cyrill Gorcunov
d0a6e9a101 restore: Pass shmems_fd as argument as well
We might be needing to close the shmems file descriptor.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:40:54 +04:00
Cyrill Gorcunov
e0e934aa4b restore: shmems -- Use cr_wait_init helper
Just in a sake of consistency

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:40:24 +04:00
Cyrill Gorcunov
793f3aa947 restore: shmem_remap arguments resort
Style tuning, no func change

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:39:58 +04:00
Cyrill Gorcunov
e189efc176 restore: shmems -- Fix /proc path
The remapping of /proc path to shmem should be
done with pid of process which did mmap() call
initially.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:39:08 +04:00
Cyrill Gorcunov
58ad088870 restore: Fix typo in shmem_wait_and_open
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:38:44 +04:00
Cyrill Gorcunov
80492c78e6 restore: More detailed log on shmem restore
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:38:18 +04:00
Cyrill Gorcunov
a03e3622f2 restore: Add log message that restore via sigreturn is started
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:38:04 +04:00
Cyrill Gorcunov
3afb83299c restore: Gather setting agrument for sigreturn code in one place
Also add a few more comments.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:37:41 +04:00
Cyrill Gorcunov
ee0f17b0a7 restore: Fix typo in shmem size assignment
And use SHMEMS_SIZE constant as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:37:12 +04:00
Pavel Emelyanov
96f92ee612 crtools: Cleanup open_image_ro
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-29 19:56:34 +04:00
Pavel Emelyanov
7b0b203b34 crtools: Use open_image_ro where appropriate
Several places just need to open an image, thus the helper is OK to use.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-28 21:38:00 +04:00
Andrey Vagin
aeb638f845 restore: shmem -- Don't poll, use wait helpers instead
Signed-off-by: Andrey Vagin <avagin@openvz.org>
[gorcunov: A few tuneups]
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-26 23:54:18 +04:00
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