First thing people typically do with criu is run something
in shell and try to dump it. This is typicall pitfall, as
in that case we face external sid and tty problem. Print a
message on stdout about this and advice wiki page to read.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
We have generic do_pb_show() call and tons of show_foo
routines, that just call one with proper args. Compact
the code by putting the args into array and calling
the do_pb_show() in one place.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
These contain linkage between number, data type and routines
for pb messages we write/read to/from image files. Most of them
have simple number-type-routines mapping, so introduce a generating
script for that.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Since *all* of them just call do_dump_gen_file with proper ops,
just call one directly. Compacts the code.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
In case if we are migrating a session leader task with a solely
slave peer we should not try to restore a group on the terminal
but rather simply inherit it, because a session of the group of
the inherited terminal is not the same as a session of our leader
thus kernel refuse to set any different group here.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This is easier for debugging, the former SID/PGID remains untouched
and printed out in logs.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This is less useful than fixing typos in output messages, but anyway.
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
If a master point has sid, it doesn't mean, that all slave points
will have sid. Look at tty03 for example:
PID SID TT COMMAND
26748 26748 ? tty03
26749 26749 pts/2 \_ tty03
26750 26750 ? \_ tty03
The second process has not a file descriptor for the ctl tty,
but this tty is opened in tty03.
v2: If a slave point with sid has not a master point, the option
--shell-job must be set and sid isn't restored for such terminals.
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
A service fd should be created, otherwise get_service_fd returns -1.
This patch removes this functionality from other subsystems and
allows to clone service descriptors.
v2: rename open_service_fd to install_service_fd
v3: two patches were merged for bisecting
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Currently fdinfo dumps for each task, so CR_FD_FDINFO is in cr_fdset.
A few tasks can share one fd table and the set of descriptors will be
dumped once and a image name will contain files_id instead of pid.
In this case CR_FD_FDINFO will go away from cr_fdset.
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
crtools should not failed, if new images are absent.
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
* The following files goes into the directory arch/x86/include/asm unmodified:
- include/atomic.h,
- include/linkage.h,
- include/memcpy_64.h,
- include/types.h,
- include/bitops.h,
- pie/parasite-head-x86-64.S,
- include/processor-flags.h,
- include/syscall-x86-64.def.
* Changed include directives in the source files that include the headers
listed above.
* Modified build scripts to reflect the source moves.
Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
We need to test every even index (which represents a slave
peer) thus use modulo operation here.
Reported-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Since we have find_next_bit in our sources now, lets
use for_each_bit helper to speedup a search procedure.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
In case if we're dumping the peer which another
end belongs not to us but some other application
the attempts to flush data may lead to endless
SIGTTOU storm:
| 1158 ioctl(53, TCFLSH, 0x2) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
| 1158 --- SIGTTOU {si_signo=SIGTTOU, si_code=SI_KERNEL, si_value={int=5, ptr=0x5}} ---
| 1158 --- stopped by SIGTTOU ---
| 1158 ioctl(53, TCFLSH, 0x2) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
| 1158 --- SIGTTOU {si_signo=SIGTTOU, si_code=SI_KERNEL, si_value={int=5, ptr=0x5}} ---
| 1158 --- stopped by SIGTTOU ---
so simply don't flush data, the initial attempt to use
TCIOFLUSH was rather "hey, we don't have a way to
say the kernel to freeze tty link for a while, lets
try to workaround this limitation" but without proper
kernel help this won't work anyway as Andrey has discovered.
Reported-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
The controling terminal should be sestored by a session leader,
thus we need to test if the SID we've found in process tree
is a leader.
Otherwise we might have pretty interesting situation: the user
passed -j on dump, ie telling us to inherit shell jobs and on
restore procedure the SID get inherited from the crtools but
session leader for this sid doesn't belong to our peocess tree
and thus we should not try to restore controlling terminal
but inherit it as well.
Reported-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
It's almost the same as find_first_sid, lets use
it instead.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
We have own mechanism to restore controlling
terminal thus we don't need the kernel to create
it in implicit way.
#2409
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
It's being found that we fail to restore tasks which
are not session leaders but have controlling terminals.
This patch reworks tty_find_restoring_task logic to fix
the problem. The problem itself basically was the following --
in case if there no sid present even on master peer or on both
master/slave peers, we were trying to find a restoring task,
and that's wrong since we have peers which do not belong our
session.
#2409
Reported-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
The slave peer should be restoring the controlling terminal.
It works for most of programs but need some more investigation
in future.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
The dumping of tty peers is somewhat tricky. And it became more
complex once we allowed to migrate/inherit sessions.
It's being found (in screen c/r) that we've a problem in looking
up of session leaders while dumping tty.
Let me explain with more details. Here is an example of screen
session
PID GID SID
20567 20567 20567 SCREEN
20568 20568 20568 pts/3 \_ /bin/bash
The screen opens master peer (ptmx) and then provides
bash the slave peer (pts/3) where bash sets up a session
leader on it.
Thus we get interesting scenario -- our pstree construction
is done in lazy fashion, we run parasite code to fetch sid/pgid
of a process tree item only when we're really dumping the task.
Thus when we start dumping ptmx peer (which belongs to SCREEN)
we've not yet constructed the process tree item for children
(ie /bin/bash) and the lookup function in tty code (which walks
over all process items in a tree) simply fails to find sid of
child, because we've not yet dumped it.
Thus, to resolve such situation we verify tty sids at late stage
of dumping.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
The sid may be present not only on slave peer
so fix up the message. Also extend it showing
peer type.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
No need for tricks, we fetch everything we need
from the parasite.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
In case if at checkpoint time we've fetched zero sid
associated with tty peer it doesn't obligatory means
that we've met a hangig up terminal, in particular
zero sid may be obtained if the slave peer do not
belong to the session the task run in but inherited
from the parent. Thus if --shell-job passed we should
handle such situation gracefully.
[ https://bugzilla.openvz.org/show_bug.cgi?id=2405 ]
Reported-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This is rather a code tossing for the next patch.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
In case of errors it provides us more information about what is going on.
For example, in my test case I now can see where the error came from
| (00.027248) tty: Unpaired slave 0
| (00.027261) tty: Unpaired slave 2
| (00.027273) Error (tty.c:174): tty: Only one slave external peer is allowed (index 2)
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
In case if we've dumped a slave peer only (say a user dumped `top'
application) we should migrate it on current active terminal, which
barely an own standart stream prepared for us by the file engine.
Note only one external slave peer is allowed simply because
otherwise we can't distinguish which indices should be used
for each of them.
The patch basically does the following things
- Check if the SID present on peer exist in current
process tree, we need to be sure that we can restore
peer parameters and controlling terminal if present
- Rename pty_open_fake_ptmx to pty_open_unpaired_slave
because we might be inheriting SELF_STDIN_OFF instead
of opening fake master peer
- Do inherit SELF_STDIN_OFF and restore tty group if
we are restoring external tty
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
We need to make sure that the only one external tty
is present, since otherwise we have no idea on which
pts index to connect them on restore.
This patch extends tty_verify_active_pairs procedure to
count how many external tty is present in the dump image.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Upon reception of tty we need to mark it in @tty_active_pairs
bitmam thus we will be able to verify if
- all active ttys obtained are paired
- if not paired then only one external tty is allowed
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
We will need it for slave ttys migration. They serve for one purpose --
to clone self stdio descriptor and use it with tty layer, which will
be addressed in further patches.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
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>
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>
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>
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>