2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00
Commit Graph

1948 Commits

Author SHA1 Message Date
Andrey Vagin
8e90ed8c4d util: add a function for running scripts
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-17 20:05:39 +04:00
Andrey Vagin
45fa18487d tcp: split the list tcp_repair_sockets on rst and cpt parts
because here are two types of entries

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-17 20:05:32 +04:00
Andrey Vagin
4c2a226458 crtools: add ability to execute external scripts (v2)
Scripts are executed when external actions required.
CRTOOLS_SCRIPT_ACTION contains a required action.
If a script doesn't know a current action, it should exit with 0.

The first usecase will be lock/unlock network.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-17 20:05:23 +04:00
Andrey Vagin
c27ff2baac tcp: unset TCP_REPAIR at the last moment after unlocking network (v2)
TCP_REPAIR should be droppet when a network is unlocked.
A network should be unlocked at the last moment, because
after this moment restore must not failed, otherwise a state of
a tcp connection can be changed and a state of one side in our image
will be invalid.

v2: use xremalloc instead of mmap and remmap

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-17 20:02:57 +04:00
Andrey Vagin
7e22e60f83 net: add ability to use tcp_repair_off from a restorer code
Use sys_setsockopt and declare a function in a header as "static inline"

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-17 20:02:39 +04:00
Andrey Vagin
1da4441598 zdtm: add a stream test case for TCP connections
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-17 18:23:46 +04:00
Andrey Vagin
06282f407c zdtm: handle a partial read/write in socket-tcp
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-17 18:23:35 +04:00
Cyrill Gorcunov
a2b215a19b pstree: Use max() helper in max_pid assignment
It shrinks code a bit.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-17 18:22:13 +04:00
Pavel Emelyanov
8fc6dbfadd files: Formalize fd restore priorities
There are places when we have to select which fd to ->open
and which to ->receive. To avoid deadlocks we sort them in
an ascending order on { pid, fd } pair.

Make this idea more formal by introducing an explicit function
doing this check and call it where appropriate (pipe.c master
selection is also simplified to fit new ... API).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 22:09:22 +04:00
Pavel Emelyanov
a0560c4298 pipes: Fix wrong pipe info check on master selection
The currently observed list entry should be examined, not
the original one.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 22:02:21 +04:00
Pavel Emelyanov
62cf23b93a files: Hide pslist selection logic into file desc handlers
Don't do explicit switch by file type in files.c and don't export
intimate knowledge of pty being master/slave. Use a file desc op
for that.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 21:53:51 +04:00
Cyrill Gorcunov
e0b39c5fd9 zdtm: Make pty tests being non-ns
Until I figure out how to make them work in ns.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 20:47:12 +04:00
Pavel Emelyanov
1d3e1ae6df tty: Remove no longer relevant TODO comment
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 18:26:37 +04:00
Pavel Emelyanov
cc87632f16 tty: Handle tty collecting error
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 18:24:43 +04:00
Pavel Emelyanov
990f80dd0f tty: Sanitize slavery and ctl tty setups
We need to do two non-trivial things with ttys -- interconnect
slaves to masters (or to each other) and setup ctl-tty restoring
task.

Now this is done in subsequently depending on each other steps:

1. collect ttys
2. interconnect slaves and mark ctl-tty tasks
3. collect fake fds for tty-ctl tasks
4. setup orphaned slaves

We can relax this logic in two ways:

1. don't split marking ctl-tty tasks and then creating fds for them
   do it in one step at the end
2. don't interconnect slaves with masters and orphaned slaves in
   two steps -- do it in one place after fds are collected

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 18:12:59 +04:00
Pavel Emelyanov
ff875dc494 tty: Cleanup tty mutex preparation
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 17:58:46 +04:00
Cyrill Gorcunov
aa247d8631 zdtm: Enable pty tests
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 17:50:47 +04:00
Cyrill Gorcunov
4ae20428c0 tty: Restore orphan slavery peers
In case if there is no master peer associated
with a slave peer we have two cases

 - the master peer was closed before slave
 - we just have no master peer at all, but
   only slave one

This patch addresses only first case -- we open
fake master and hook slaves on it, then close it
immediately.

The second case will be addressed later.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 17:50:46 +04:00
Cyrill Gorcunov
da762de63f tty: Rework tty entry verification
tty entries might have no parameters assigned if they
are hanging on closed master, we should take into
account when we do verify them.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 17:50:45 +04:00
Cyrill Gorcunov
0105e543a7 tty: Dump a hanging up terminal
If we've met a hanging up terminal we can escape
lot of work but dump a minimum information needed
for restore.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 17:50:44 +04:00
Cyrill Gorcunov
07aa668282 tty: Squash tty_get_sid, tty_get_pgrp into tty_get_sid_pgrp
This patch squashes tty_get_sid, tty_get_pgrp into
one tty_get_sid_pgrp helper (which allows to detect
if dumping terminal is hanging up, the real use of
this ability will be addressed in next patch).

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 17:50:42 +04:00
Cyrill Gorcunov
978cecd629 tty: Make termios and winsize being optional params
The dangling slave peers might have no data associate
with them if master peer is closed and link is hanging
up. Thus make this parameters optional to not blow the
image with data which never will be used.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 17:50:41 +04:00
Andrey Vagin
52a2c9fd77 restorer: unify log functions
Add ability to use the same macros in restorer code.
In the future we will add ability to show arguments like printf.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 15:14:11 +04:00
Pavel Emelyanov
667953c00f restorer: Don't memcpy restorer blob in each task on restore
Instead -- mmap it once in root task and then mremap it later.
No mremap of original restorer can be done, since in that case
the restorer vma would be tied to crtools binary which in turn
will make set-exe-file prctl to fail with EBUSY.

Note -- after mremap the original vmas list becomes non relevant,
but it's OK. Only new holes appear inside which is OK for munmap.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 14:51:40 +04:00
Pavel Emelyanov
80d5fb285f restorer: Mmap restorer blob separately from the rest
This will avoid exec bit on restorer args and will make
it possible for shared restorer eventually.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 04:10:48 +04:00
Pavel Emelyanov
63ce82e7f6 restore: Sanitize restorer code + args layout
There was a strange thing -- task args size is aligned, but when
threads args ptr is get this alignment was lost. Fix this and make
all the bufs page-aligned.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 03:01:48 +04:00
Pavel Emelyanov
5a469e1894 restorer: Lost tgt vmas lenght in restorer memory blob hinting
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 02:56:14 +04:00
Pavel Emelyanov
845f3ee973 fd: Indirect fd opening states engine
Put the states into in one place.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 00:34:37 +04:00
Pavel Emelyanov
1ea03bf80c fd: Relax file master checking in open and post_open
pid == pid && fd == fd equals fle == fle :)

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 00:21:14 +04:00
Pavel Emelyanov
cc41192f10 fd: Standartize arguments for fd opening stages handlers
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 00:17:57 +04:00
Pavel Emelyanov
b0502e4fe8 fd: Split fd opening and serving out routines
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 00:08:39 +04:00
Konstantin Khlebnikov
ae4796d025 zdtm: new testcase for unhashed proc entries
Testcase: fork child, chdir into /proc/$pid and kill child.

test for http://bugzilla.openvz.org/show_bug.cgi?id=2315

Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Acked-by: Andrey Wagin <avagin@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 16:09:40 +04:00
Andrey Vagin
e628b63b17 zdtm: close an external tty
Redirect standard descriptors of a test init process in to the log file.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 16:09:13 +04:00
Andrey Vagin
499e4486f5 zdtm: run test in a new session
It was lost for tests which executed in a new namespaces.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 16:08:39 +04:00
Andrey Vagin
0e4ec77612 zdtm: check restore of TCP connections (v2)
The test creates two processes.
A first process creates a tcp server, a second one connects to it.
The first process is dumped and restored.
Then the test checks that the TCP connection is alive.

v2: fix compilation :)

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 14:56:30 +04:00
Andrey Vagin
689317bf4e zdtm: add a set of function for creating a tcp connection
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 14:55:08 +04:00
Cyrill Gorcunov
0910b72b3d tty: Use is_service_fd where appropriate
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 14:45:14 +04:00
Cyrill Gorcunov
45cc85eea4 Speed up service-fd retrieval
We're using get_service_fd in file engine,
better to make it fast. This patch caches
the limits system provides us, instead of
calling getrlimit() every time.

This patch introduces is_service_fd helper
which will be used instead of get_service_fd
where it make sense.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 14:45:06 +04:00
Pavel Emelyanov
b354a09cd7 rst: Brush up shared resources collection
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:11:33 +04:00
Pavel Emelyanov
ccce9fed2a tty: Brush up ctl tty preparation
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:09:05 +04:00
Pavel Emelyanov
1838bee1be tty: Remove unused constants from header
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:07:34 +04:00
Cyrill Gorcunov
682b9d672c app-test: check screen application
Add test for screen c/r.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:03:01 +04:00
Cyrill Gorcunov
8895729906 zdtm: Add pty04 test
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:02:53 +04:00
Cyrill Gorcunov
1603f88836 zdtm: Add pty03 test
Non-opened control terminal

* Set a control terminal
* Close a file descriptor on it
* Dump/restore
* Open the control terminal (/dev/tty)
* Check, that it connected to the master end

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:02:46 +04:00
Cyrill Gorcunov
bc962a28d2 zdtm: Add pty02 test
The test is tricky -- it opens master in task 1
and dup it in task 2, then close in task 1 and
do C/R.

Thus we need to setup SID of master terminal
somehow in children, which usually fails in
currnt tty restore implementation.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:02:39 +04:00
Cyrill Gorcunov
1a41fcfc21 zdtm: Add pty01 test
Two slaves on same pty.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:02:32 +04:00
Cyrill Gorcunov
20d6762d93 tty: Add restoration of controlling terminal v4
The idea behind is pretty simple -- once we find
that there is a controlling terminal present we
do call ioctl on appropriate /dev/pts/N.

This is done in a bit unusuall manner. When we
find that there is a controling terminal present
we do create an additional FdinfoEntry for it
with object id taken from existing master peer.

The file engine stack this new FdinfoEntry on
fd_info_head head list. Thus we will have at
least two entries on this list. One for real
Fdinfo associated with master peer and one for
our new generated Fdfinfo entry, it depends on
pid which one become a file master.

Finally we do use post_open_fd hook in our
tty code which allows us to open controlling
terminal and yield proper ioctl on it.

v2:
 - restore control terminals via service fd,
   still need to speedup service fd retrieval.

v3:
 - use prepare_ctl_tty() helper to generate
   control terminal fdinfo entry

v4:
 - use post_open_fd

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:00:58 +04:00
Cyrill Gorcunov
d5dfab7745 check: Add check_tty
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:00:56 +04:00
Cyrill Gorcunov
a365befaea tty: Add show method
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:00:55 +04:00
Cyrill Gorcunov
89a7a45d37 tty: Add checkpoint/restore for unix terminals v6
Usually the PTYs represent a pair of links -- master peer and slave
peer. Master peer must be opened before slave. Internally, when kernel
creates master peer it also generates a slave interface in a form of
/dev/pts/N, where N is that named pty "index". Master/slave connection
unambiguously identified by this index.

Still, one master can carry multiple slaves -- for example a user opens
one master via /dev/ptmx and appropriate /dev/pts/N in sequence.
The result will be the following

master
`- slave 1
`- slave 2

both slave will have same master index but different file descriptors.
Still inside the kernel pty parameters are same for both slaves. Thus
only one slave parameters should be restored, there is no need to carry
all parameters for every slave peer we've found.

Not yet addressed problems:

- At moment of restore the master peer might be already closed for
  any reason so to resolve such problem we need to open a fake master
  peer with proper index and hook a slave on it, then we close
  master peer.

- Need to figure out how to deal with ttys which have some
  data in buffers not yet flushed, at moment this data will
  be simply lost during c/r

- Need to restore control terminals

- Need to fetch tty flags such as exclusive/packet-mode,
  this can't be done without kernel patching

[ avagin@:
   - ideas on contol terminals restore
   - overall code redesign and simplification
]

v4:
 - drop redundant pid from dump_chrdev
 - make sure optional fown is passed on regular ptys
 - add a comments about zeroifying termios
 - get rid of redundant empty line in files.c

v5 (by avagin@):
 - complete rework of tty image format, now we have
   two files -- tty.img and tty-info.img. The idea
   behind to reduce data being stored.

v6 (by xemul@):
 - packet mode should be set to true in image,
   until properly fetched from the kernel
 - verify image data on retrieval

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
CC: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:00:54 +04:00