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

22 Commits

Author SHA1 Message Date
Pavel Emelyanov
33c0add242 tty: Sanitize tty parasite-side dumping
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-15 23:55:34 +04:00
Cyrill Gorcunov
9fb384f926 tty: Make tty_get_sid_pgrp() to use parasite code
We need to use namespace local sid/pgid parameters
assigned on tty link, thus use parasite helper.

Otherwise we might fail on restoring controlling
terminal inside namespace (though everything else
will work even without this patch).

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-15 23:42:54 +04:00
Cyrill Gorcunov
848215b6f1 tty: Drop sid/pgid test from verify_info
Since we've started fetching sid/pgid from the
dumpee context we're allowed to obtain sid/pgid
on a slave peer. This is perfectly valid. So
drop this test.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-15 23:42:52 +04:00
Cyrill Gorcunov
1686669410 tty: Make tty_setup_slavery to return error
In case if here no task found which would restore
controlling terminal -- exit with error instead of
continue with just error message.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-15 20:02:29 +04:00
Cyrill Gorcunov
6a5ac97186 tty: Fix copying of termios character map
The system termios structure and our PB
equivalent defined quite different, while
first defined as plain array we use dynamically
allocated memory. Thus the use of min() macro
is incorrect here and always produce the size of
pointer.

Fix it using the size of array from the system
provided structure. The BUILD_BUG_ON will prevent
from accidental changes.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-02 20:26:11 +04:00
Cyrill Gorcunov
1de8adbf71 tty: Verify active pairs once dump complete
We don't support yet detached terminals migration,
so fail early if we can't proceed.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-20 13:35:39 +04:00
Cyrill Gorcunov
a3c886de62 tty: Mark living peers in tty_active_pairs bitmap
Will need it to verify that live tty pairs exist.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-20 13:35:38 +04:00
Cyrill Gorcunov
dd783030e6 tty: Rename tty_test_and_set_index to tty_test_and_set
To trace paired ttys we will need one more bitmap
so rename tty_test_and_set_index to tty_test_and_set
because we will need this helper in another context.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-20 13:35:37 +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
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
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
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
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
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
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