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>
Remove excessive checks and keep it a pointer.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Introduce a helper for walking the list and sending signals.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
To include dgram bound && connected sockets, for example
CR_FD_UNIXSK: /home/cyrill/crtools/unixsk-2813.img
----------------------------------------
fd 3 type 1 state 1 namelen 0 backlog 0 id 19505 peer 19506
fd 4 type 1 state 1 namelen 0 backlog 0 id 19506 peer 19505
fd 5 type 2 state 7 namelen 0 backlog 0 id 19507 peer 0
fd 6 type 2 state 7 namelen 18 backlog 18 id 19508 peer 0 --> test-socket-bound
fd 7 type 2 state 7 namelen 0 backlog 0 id 19509 peer 19510
fd 8 type 2 state 7 namelen 17 backlog 17 id 19510 peer 0 --> test-socket-conn
fd 9 type 2 state 7 namelen 23 backlog 23 id 19511 peer 19511 --> test-socket-bound-conn
----------------------------------------
The last one is bound and connected.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This code opens a log file and duplicates the descriptor to logfd,
but forgets to close the first one.
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
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>
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>
In commit 99eb3d09c5c42200b230783e793b778882ce8dd6
we started to use self-contained shared memory
region but it revealed the problem that anonymous
sgared mappings might be parsed by parse_maps incorrectly,
so fix it and be ready to get anon-shared mappings.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Also make output a bit more fancy, as
CR_FD_UNIXSK: unixsk-2440.img
----------------------------------------
fd 3 type 1 state 1 namelen 0 id 19406 peer 19407
fd 4 type 1 state 1 namelen 0 id 19407 peer 19406
fd 5 type 2 state 7 namelen 7 id 19408 peer 0 ---> [tst-sk]
fd 6 type 2 state 7 namelen 0 id 19409 peer 0
fd 7 type 2 state 7 namelen 0 id 19410 peer 19411
fd 8 type 2 state 7 namelen 8 id 19411 peer 0 ---> [tst-sk1]
----------------------------------------
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
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>
To follow rest of code
- use !x for xalloc result tests
- structure members are tab aligned
- multiline assignments over structure members are aligned as well
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>