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

289 Commits

Author SHA1 Message Date
Pavel Emelyanov
11b7e14a6b dump: Fix task freezing process
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>
2012-01-19 22:42:01 +04:00
Pavel Emelyanov
42cbb5bafc dump: Remove dead code from collect_mappings
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-19 22:41:42 +04:00
Pavel Emelyanov
381559a7f6 socket: Ignore collection errors for now
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>
2012-01-19 22:41:15 +04:00
Stanislav Kinsbursky
7f2cd4b18a cr-dump: remove unnessesary parasite header
Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-17 20:12:36 +04:00
Pavel Emelyanov
e2d8aec7f5 files: Named constant for cwd fdinfo
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-16 23:50:50 +04:00
Pavel Emelyanov
f899d0407a files: Handle the absence of ID in proc fdinfo
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>
2012-01-15 22:37:39 +04:00
Cyrill Gorcunov
f80694deed proc_pase: Make sure we may scan up to 15 symbols in name
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>
2012-01-15 22:37:17 +04:00
Pavel Emelyanov
3202d72f85 crtools: Parse /proc/pid/stat in a more readable way
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>
2012-01-14 02:00:38 +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
9792a860b3 dump: Fix arguments types in printing
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-13 23:04:20 +04:00
Cyrill Gorcunov
08569cbc5f dump: Use proper format for int printing
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-13 22:43:58 +04:00
Cyrill Gorcunov
1c96c5cff0 Merge branch '@xemul' into dev
* @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>
2012-01-13 21:39:14 +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
d7121ede0d Merge branch '@xemul-mails' into @xemul
* @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>
2012-01-12 22:16:54 +04:00
Pavel Emelyanov
a9fdf3865e crtools: Collect dumping fd parameters into one place
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>
2012-01-12 22:09:59 +04:00
Pavel Emelyanov
1b247eb6b4 crtools: Toss dump_one_fd args around
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>
2012-01-12 22:09:59 +04:00
Pavel Emelyanov
fbafe2db15 crtools: Rename fd to lfd in dump_one_fd
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>
2012-01-12 22:09:59 +04:00
Pavel Emelyanov
02dbadb46f crtools: Sanitize pstree construction
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>
2012-01-12 22:09:58 +04:00
Cyrill Gorcunov
9360a73cad crtools: Make close_cr_fdset being safe to be called with closed fd-set
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>
2012-01-12 21:25:19 +04:00
Cyrill Gorcunov
e4d21f5a38 dump: Drop appending thread data to a main core file
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>
2012-01-12 20:00:01 +04:00
Pavel Emelyanov
6b83aef6a1 crtools: Merge fdset free into close
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>
2012-01-12 18:51:21 +04:00
Pavel Emelyanov
871b73674d crtools: Merge fdset allocation into prep
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>
2012-01-12 18:51:13 +04:00
Pavel Emelyanov
15209d3fe9 crtools: Make fdset be an array of file descriptors
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>
2012-01-12 18:51:06 +04:00
Cyrill Gorcunov
76ef79a081 dump: Fix stack data written to image
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>
2012-01-12 14:09:54 +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
Pavel Emelyanov
b5cc5fc3e1 crtools: Sanitize parasite_ctl pass to parasite_cure_seized
Remove excessive checks and keep it a pointer.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-11 14:00:06 +04:00
Pavel Emelyanov
a49e30722a crtools: Kill constant arg from parasite_infect_seized
The mmap hint is always NULL.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-11 13:59:54 +04:00
Pavel Emelyanov
73633d5505 crtools: Kill constant arg from parasite_dump_pages_seized
The last one is always CR_FD_PAGES.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-11 13:59:41 +04:00
Pavel Emelyanov
0ca9ccc3e4 crtools: Sanitize the tasklist states switch
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>
2012-01-11 13:59:15 +04:00
Cyrill Gorcunov
843747de55 net: A few changes in headres to follow c99
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>
2011-12-27 14:26:13 +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
Cyrill Gorcunov
3c929e540c dump: Adopt dumping children for new format
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>
2011-12-26 02:24:46 +04:00
Cyrill Gorcunov
894a626a52 dump: parse_threads - Pass single struct pstree_item instead of a few parameters
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>
2011-12-26 02:24:37 +04:00
Cyrill Gorcunov
ff954f655f dump: Drop unneeded #includes
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>
2011-12-19 23:18:17 +04:00
Cyrill Gorcunov
2e3c4e3692 Move everything related to ptrace into ptrace.[ch]
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-19 21:57:59 +04:00
Cyrill Gorcunov
32ac78a499 util: Drop ptrace seize helpers declaration from the header
Already defined in seize.h

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-19 21:19:28 +04:00
Cyrill Gorcunov
8a90464cc9 Drop some duplicated #include
And rearrange the rest.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-19 21:05:37 +04:00
Cyrill Gorcunov
950e788b1c Dump: Add missing ending new lines to pr_perror
pr_perror is not the same as perror and requires
new line at then end.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-10 12:49:55 +04:00
Cyrill Gorcunov
6701296f5a dump: Be ready for absence of output from /proc/pid/children
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-09 11:45:55 +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
Cyrill Gorcunov
d924a240ff make: Drop redundand dependency on parasite.h
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>
2011-12-05 20:36:57 +04:00
Cyrill Gorcunov
485c4b50d1 show: Rework show procedure
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>
2011-12-05 15:59:01 +04:00
Cyrill Gorcunov
da61f73263 dump: Test errors on xrealloc result
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2011-12-05 13:36:08 +04:00
Cyrill Gorcunov
29e66613cb dump: Drop redundant pr_debug
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-05 13:21:43 +04:00
Pavel Emelyanov
ec8cdcd7cf crtools: Cleanup pstree entry code
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>
2011-12-02 18:39:35 +04:00
Pavel Emelyanov
8340bff864 crtools: Cleanup children stuff parsing
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>
2011-12-02 18:39:22 +04:00
Pavel Emelyanov
5e47e233df crtools: Cleanup threads stuff parsing
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>
2011-12-02 18:37:59 +04:00
Andrey Vagin
04f36aed0a Set descriptors to restart a current syscall
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>
2011-12-02 17:50:55 +04:00
Cyrill Gorcunov
63fea93076 dump: Switch to /proc/$pid/children parsing to obtain children set
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>
2011-12-01 18:51:40 +04:00
Cyrill Gorcunov
6661b555b9 dump: Don't forget to close opened file on error path
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-11-30 22:30:53 +04:00