Currently we read the children tree of running processes.
This is deadly wrong. Stop task once we open it's proc dir
before descending to its kids.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
We can do it since we may not want to dump the missed sockets.
But later, when we will start dumping containers, we'll better
fail here, rather than in the dump stage.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This makes crtools correctly abort when working on wrong kernel.
Otherwise all the open files will have the same (garbage) ID and
the subsequent restore will result in broken app.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
And do not use strcpy, better to stick with strncpy.
Moreover, to be on a safe side make proc internal
buffer big enough even for "(%16s)" format, it's
hardly possible that the kernel ever change stat
format but just to be on a safe side.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
We will later need other fields of this file, so let's parse it right
now in a way, that allows to easily get new fields.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
* @xemul:
crtools: Collect dumping fd parameters into one place
crtools: Toss dump_one_fd args around
crtools: Rename fd to lfd in dump_one_fd
crtools: Sanitize pstree construction
crtools: Remove unused printk_registers and co
crtools: Deduplicate file info showing code
crtools: Merge pstree collecting into showing
crtools: Remove unused and wrong arrays from pstree image
crtools: Remove lseeks after prep_cr_ calls
crtools: Cleanup collect_pstree in cr-show
Conflicts:
cr-dump.c
include/sockets.h
sockets.c
The conflicts are mostly because of commit
995ef5eca3b8d74cf192e41c307f5329d93f9795
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
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>
* @xemul-mails:
crtools: Collect dumping fd parameters into one place
crtools: Toss dump_one_fd args around
crtools: Rename fd to lfd in dump_one_fd
crtools: Sanitize pstree construction
crtools: Remove unused printk_registers and co
crtools: Deduplicate file info showing code
crtools: Merge pstree collecting into showing
crtools: Remove unused and wrong arrays from pstree image
crtools: Remove lseeks after prep_cr_ calls
crtools: Cleanup collect_pstree in cr-show
Conflicts:
cr-show.c
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Introduce the fd_parms structure, that contains all we need to describe
open fd during dump -- its name (int), pos, flags and id. The read_fd_parms
routing fills one once and passes along the stack. This reduces the amount
of arguments significantly.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Make the dump_one_fd fn accept local fd and integer target fd values
instead of target fd dir and target fd string name.
This saves couple of atoi-s (done once) and makes the next patch simpler.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This variable is actually a local fd, so reflect this in its name.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Rename find_pstree_entry into add_<one> (since it doesn't find it)
and move list adding into it.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
It was being done intentionally to be able to call close_cr_fdset
several times in a row, bring this ability back. Otherwise I'm
getting glibc complains about attemt to free already freed memory.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
It's a rudiment from Elf-time code.
Not needed anymore.
Reported-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
The same as previous patch -- no need in two separate calls.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
They always go in pairs so there's no need in two calls.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Path is not needed there -- we can call the get_image_path() in prep_cr_fdset_
routines and in parasite-syscall.c when required.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
I case if there is no file id provided we
might be writting stack data to image. Better
put zeros there.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
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>
Since we're not system library
- no underscopes in functions name until really needed
and known to not clash with posix namespace
- empty line between system headers and own headers
for readability
- extern for function prototypes
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>
Kernel has a new format for process children
(ie /proc/<pid>/task/<tid>/children) so adopt
crtools for it.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Parsing children will require to know the number
of threads found so in a sake of consistency pass
single struct pstree_item here as well.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This as well forces to move ptrace
definitions into ptrace.h, otherwise
freshly fetched kernel headers become
conflict with existing ptrace constants.
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>
There is no such file at all and it forced build
process to re-build every make command passed.
Reported-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Added
- ability to parse every single file crtools
understands via magic number
- dumped memory pages can be rendered in two
modes -- as a simple set of pages' virtual addresses
or in hexdummp fashion (via -c command line key).
For example
./crtools -s -c -f pages-2557.img
CR_FD_PAGES: pages-2557.img
----------------------------------------
7fffb44ace20: 00 00 00 00 00 00 00 00 00 00 00 74 65 73 74 2f |. . . . . . . . . . . t e s t / |
7fffb44ace30: 74 65 73 74 2d 73 69 67 61 63 74 69 6f 6e 00 48 |t e s t - s i g a c t i o n . H |
7fffb44ace40: 4f 53 54 4e 41 4d 45 3d 6c 6f 63 61 6c 68 6f 73 |O S T N A M E = l o c a l h o s |
7fffb44ace50: 74 2e 6c 6f 63 61 6c 64 6f 6d 61 69 6e 00 54 45 |t . l o c a l d o m a i n . T E |
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
After all the child/threads stuff is moved to helpers it is
possible to remove some unneeded code paths and local variables.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Move all the parsing of /proc/pid/children into a helper to be symmetrical
with the threads parsing.
Error from xrealloc is ignored as well.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Move the whole code dealing with parsing threads at collect_pstree
stage into one function.
The nr_threads calculation is performed inside it based on the amount
of directories in /proc/pid/task, not the Threads: count in status.
Error from xrealloc is ignored by now.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
If a task is sleep in syscall, it should be restared.
This logic is moved from kernel do_signal().
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This also depends on kernel's inteface being changed,
so kernel/ is updated as well.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>