files: Add a few comments on structures we use for files handling

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
files: Add a few missing brackets

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
proc_parse: Add parsing of control tty

We will need this number to find out the
control terminal id a task has.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
dump: Add fetching control tty for dumpee

We will need it for c/r of ttys the task have.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
protobuf: Add TTY file type

Not yet used, but will need it to describe
fdinfo for tty entries.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Add CTL_TTY_OFF service fd

This entry will help us to create control terminal.
We need a special fd number for it, because control
terminal is to be restored in context of a process
which sid matches the one terminal has.

No real usage though in this commit yet.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
files: Use switch in collect_fd

For easier transition to tty c/r. We will need more
types here, thus using switch statement makes code
a bit easier to read.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Add separate lists for master/slave fd on restore

When we will be restoring ttys we need that restore
procedure for master peers will be yielded earlier
than for slave peers due to ttys specifics. With this
commit we introduce @tty_masters and @tty_slaves
lists which will allow us to order tty file restore
procesure.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
files: Add collecting of control terminals

This patch prepares the ground for control terminal
restore code. In case if a task has a control terminal
we do create a fake file info entry and collect in into
file list of the appropriate task. Such trick will allow
us to use a general file restoration engine.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
tty: Add checkpoint/restore for unix terminals

The main idea of TTY restore (the dumping is straight forward
and has nothing special) is the following

 - because master peers must be opened before slave peers
   we add new tty lists into rst_info structure. The lists
   will carry tty information related to file descriptors
   and a task will try to open master peers before slave
   ones

 - because SID should be restored in a task context which
   SID mathes peer's we introduce CTL_TTY_OFF special file
   descriptor which allow us to transfer restored control
   terminal to the task which needs it.

Anything else is straighforward -- master get opened via
/dev/ptmx interface, while slaves are via /dev/pts/N.

Known problems

 - 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@openvz.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
tty: tty_handle_priv can be called from inside of collect_tty

Simplification, no need to carry tty_handle_priv as non static.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
tty: Add a comment about assigning control terminal id

Otherwise it's unclear why the hell we do such trick.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
dump: Drop tty parsing from procfs

It's leftover. We don't need it now.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>