2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-29 13:28:27 +00:00

40 Commits

Author SHA1 Message Date
Pavel Emelyanov
164ccc095f crtools: R/W API rewrite
Kill all the macros for reading/writing image parts. New API looks like

* write_img_buf/write_img
  Write an object into an image. Reports 0 for OK, -1 for error. The _buf
  version accepts object size as an argument, the other one uses sizeof()

* read_img_buf/read_img
  Reads an object from image. Reports 0 for OK, -1 for error or EOF.

* read_img_buf_eof/read_img
  Reads an object from image. Reports 1 for OK, 0 for EOF and -1 for error.
  This is not symmetrical with the previous one, but it was done deliberately
  to make it possible to write code like

  ret = read_img_bug_eof();
  if (ret <= 0)
	return ret; /* 0 means OK, all is done, -1 means error was met */.

  ... /* 1 means object was read, can proceed */

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-23 01:43:10 +04:00
Cyrill Gorcunov
4184d2f6a6 sockets: Rename struct inet_diag_req to inet_diag_req_v2
There was API change in linux kernel 3.2 -> 3.3 transition

 | commit c8991362a0d3cf317dfbfb6cb946607870654e6d

Reported-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-01-20 16:40:56 +04:00
Pavel Emelyanov
2a76c6409c socket: Don't request extensions from inet diag
This eats response skb mem, but we don't need it.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-19 22:41:24 +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
Pavel Emelyanov
a722abce77 socket: Use read_ptr_safe_eof
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-18 18:32:20 +04:00
Pavel Emelyanov
379dde63f5 sockets: Clean usk_img dereference
There's no need in img fd pointer in opening functions.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-18 18:31:42 +04:00
Stanislav Kinsbursky
dd0f72f220 restore: IPv4 listening sockets restore support
This patch adds support for restoring IPv4 listening sockets.
Based on unix sockets restore.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-18 12:39:08 +04:00
Stanislav Kinsbursky
7fc6561c0c show: inet sockets dump parsing support added
Nothing to comment there.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-18 12:39:04 +04:00
Stanislav Kinsbursky
f3253a40d2 checkpoint: IPv4 listening sockets dumping support 2012-01-18 12:38:58 +04:00
Stanislav Kinsbursky
654216c1df checkpoint: generalize netlink requests code
This is a precursor patch. Netlink request code is mostly the same for any
kind of sockets. Only 2 places differs: request creation and callback address.
This patch parametrizes netlink call function with a pointer to a request
structure, request size and receive callback, which replaces hard-coded unix
sockets parts.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-18 12:38:54 +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
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
Stanislav Kinsbursky
7eec5a9e0c Sockets: replace macroses concatenation with single one for netlink requests
NLM_F_DUMP is already defined as (NLM_F_ROOT|NLM_F_MATCH)

Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-13 16:38:10 +04:00
Cyrill Gorcunov
3bba868e92 sockets: Allow to reuse fd in run_accept_jobs
Sockets are special and we reuse fds in accept jobs.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-01-13 13:26:39 +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
Cyrill Gorcunov
6030463122 sockets: Fix memory leak on relative bind path
In case if relative bind path found we skip such
socket but forget to free previously allocated
memory.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-12 19:28:46 +04:00
Andrey Vagin
49074a98c4 socket: skipe unsupported sockets (v2)
We collect all unix sockets in the current net namespace, but
a target process uses a few of them, so we may skip unsupported sockets
and if it is used by a target process, lookup_socket returns error.

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-12 19:04:56 +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
Pavel Emelyanov
e710c5c5ef crtools: anitize showing funtions
Remove unneeded path argument (we do know the file data is read from) and
actually bogus show_header boolean.

Also introduce two helpers for showing header and tail.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-12 18:50:59 +04:00
Cyrill Gorcunov
dffaab578d sockets: Restore dgram sockets
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-01-10 17:38:55 +04:00
Cyrill Gorcunov
930432f161 sockets: Make socket name printing similar to vmas
Use same format as we do for VMA names.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-10 17:26:51 +04:00
Cyrill Gorcunov
1a1979cc88 sockets: Show backlog length in "show" procedure
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-10 17:26:51 +04:00
Cyrill Gorcunov
196ce521a8 sockets: unix -- Retrieve backlog length for stream sockets
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-10 17:26:51 +04:00
Cyrill Gorcunov
942355c166 sockets: Nitpick for dgram dumping
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-10 17:26:50 +04:00
Cyrill Gorcunov
054bf4ada2 sockets: Allow to dump dgram sockets
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-10 17:26:50 +04:00
Cyrill Gorcunov
04ec43a5d5 sockets: Split open_unix_sk to stream and dgram versions
And add some comments.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-10 17:26:50 +04:00
Cyrill Gorcunov
f3ed69a339 sockets: Print socket id as well
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>
2011-12-30 18:24:55 +04:00
Cyrill Gorcunov
2967bb9c37 sockets: Use reopen_fd_as helper
It also tests for possible dup() call error.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-30 15:34:05 +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
Cyrill Gorcunov
935c8e75f0 net: sockets -- Use read_ptr_safe for magic number test
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-28 12:17:02 +04:00
Cyrill Gorcunov
4432c6447e net: sockets -- A few style tuneups
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>
2011-12-28 12:16:51 +04:00
Cyrill Gorcunov
bc3370fc47 net: sockets -- Dont use multiline for() without braces
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-28 12:16:36 +04:00
Cyrill Gorcunov
c53408d6b7 net: sockets -- Make sure ue->namelen < UNIX_PATH_MAX
UNIX_PATH_MAX is a size of path, so max length
should never be equal to such size.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-27 23:32:17 +04:00
Cyrill Gorcunov
2ae99d73b9 net: Define named constant for nlmsg_seq
For better readability.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-27 20:13:18 +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
Cyrill Gorcunov
f532e9fed2 net: sockets -- Use dprintk helper
Drop USK_DEBUG, we have dprintk which is active
if compiled with make DEBUG=1

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-27 14:26:02 +04:00
Cyrill Gorcunov
ccd5e2295f net: sockets -- Replace __u32 with u32
We provide such type in types.h.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-27 12:41:42 +04:00
Cyrill Gorcunov
4a015bba33 sockets: Use safe snprintf
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-27 00:17:24 +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