[CRIU] [PATCH 14/14] tty: Add checkpoint/restore for unix terminals
Cyrill Gorcunov
gorcunov at openvz.org
Sun Sep 2 12:33:31 EDT 2012
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.
Control terminals checkpoint and restore procedure deserves a separate
comments section. Control terminal is seting up on a slave peer but the
task which setups it must have same SID as terminal has, otherwise the
procedure will fail. Note that control terminal is restored via ioctl
on /dev/pts/N, where N is the number of the terminal we need. So we
do a trick here
- during checkpoint we generate the control terminal record written
into tty image file with unique id, this guarantee us that noone
else will use this id over all id space
- at restore time we generate a service file desciptor which id get
assigned from dumped control terminal described above. So once
file engine finds this service fd we call ioctl on it and viola
the control terminal is restored.
Not yet addressed problems:
- Also there is a second hardness with slave peers -- at moment of
restore the master end might be already closed for any reason so
to resolve such problem we open a fake master peer with proper index
and hook a slave on it, then we close master peer.
- Find a way to fetch tty flags from the kernel (locked/exclusive)
and save it in tty_flags.
- 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
- We might need an additional option which would try to open
tty with specified index until success instead of exiting
with error if more than 32 attempts were done, patching
kernel is not the option here since we can't break ABI
the kernel provides at moment
[ avagin@:
- contol terminals restoration code complete rework
- overall code redesign and simplification
]
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
Makefile | 1 +
cr-dump.c | 14 +-
cr-restore.c | 12 +-
cr-show.c | 6 +
files.c | 35 +++-
image.c | 1 +
include/crtools.h | 2 +
include/files.h | 2 +-
include/image.h | 1 +
include/protobuf.h | 1 +
include/tty.h | 22 ++
protobuf.c | 2 +
protobuf/Makefile | 1 +
protobuf/tty.proto | 45 +++
tty.c | 806 ++++++++++++++++++++++++++++++++++++++++++++++++++++
15 files changed, 941 insertions(+), 10 deletions(-)
create mode 100644 include/tty.h
create mode 100644 protobuf/tty.proto
create mode 100644 tty.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0014-tty-Add-checkpoint-restore-for-unix-terminals.patch
Type: text/x-patch
Size: 29111 bytes
Desc: not available
Url : http://openvz.org/pipermail/criu/attachments/20120902/587c64d5/0014-tty-Add-checkpoint-restore-for-unix-terminals-0001.bin
More information about the CRIU
mailing list