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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>