Commit graph

8820 commits

Author SHA1 Message Date
Pavel Emelyanov
05abfa5d74 fdinfo: Extract FdinfoEntry from dump_one_file
To support SCMs we'll need to receive them into criu task
(see the SCM patch for details), then dump the received
file as if it was in the dumpee. Then the info about received
descriptor will be written into packet entry.

For this we'll need to perform all the regular file dumping
 code BUT not write the FdinfoEntry into image, so shuffle
the code for that.

The gist of the patch is in two changes -- one in the
do_dump_gen_file(), the other in dump_task_files_seized().
The rest is just tossing the arguments of the functions
relevant to that change.

Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:41:50 +03:00
Pavel Emelyanov
d4c6e78515 tty: Generate unique ID for satellite regfile entry
Same thing as for fifo-s.

Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:41:50 +03:00
Pavel Emelyanov
c0e929abc5 fifo: Generate unique ID for satellite regfile entry
The plan is to have all file entries have unique ID. Fifo
generates a reg file entry to reuse the whole reg-files
c/r-ing engine (ghosts, open-by-path, etc.) and right now
ID for this entry is the same as for fifo entry.

Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:41:50 +03:00
Pavel Emelyanov
73a1f362fe tty: Prepare for no parasite_ctl
SCM-dumping code won't provide the ctl for TTY dump. To
make this work we'll have to peek required tty info from
current (see the SCM patch), but I doubt that anyone
sends TTYs via sockets ... so keep this in TODO list.

Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:41:49 +03:00
Pavel Emelyanov
49a2cbd62f zdtm: Send two descriptors in two SCMs
Only the send code is altered, as upon receiving kernel
merges all scm_rights int one. CRIU relies on this merge
and this is to catch situations if the kernel suddenly
stops doing this.

Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:41:49 +03:00
Pavel Emelyanov
ff90e847ac zdtm: Send two descriptors in one message
Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:41:49 +03:00
Pavel Emelyanov
c6908011bb zdtm: Send two descriptors via unix socket
Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:41:49 +03:00
Pavel Emelyanov
00468aa801 zdtm: Test descriptor sent over unix and kept open
Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:41:49 +03:00
Kirill Tkhai
f084b24609 files: Add task link to created fdinfo_list_entry and populate it
This will be used in further to determine whether task's namespace
allows to restore file_desc.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:41:02 +03:00
Kirill Tkhai
a95f68e082 files: Reorder fdinfo_list_entry fields
Keep int pid with short-len fields to avoid
alignment gaps in structure.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:34:57 +03:00
Kirill Tkhai
50131370ae files: Extract new_fle assignment from collect_fd() to separate func
The algorhythm of searching file master will be more complicated
in next patches. So, move current functionality in separate func.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:33:02 +03:00
Kirill Tkhai
deba6311ce files: Assign fdesc to fle in collect_fd() earlier
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:32:07 +03:00
Kirill Tkhai
5360ed761f files: Kill file_desc_options::collect_fd()
The only user is fifo, but it uses collect_fd()
to do read only actions (the only change is
fifo_info::reg_d population, which may be easily
moved to open_fifo_fd()).

So, move the collect_special_file() functionality
from collect_fifo_fd() to open_fifo_fd() and
kill collect_fd method at all.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2017-10-17 11:26:37 +03:00
Kirill Tkhai
dc89ac658b files: Teach collect_fd() mark fake files
Add new argument to this function.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:18:03 +03:00
Kirill Tkhai
674651995f files: Export collect_fd()
Declare it extern and allow to use outside files.c.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:16:15 +03:00
Kirill Tkhai
107f2e40fe files: Kill autofs_create_fle() and use generic helper
On 01.06.2017 14:34, Kirill Tkhai wrote:
> Everything is prepared: the pair "type and id" is
> uniqul, so find_file_desc() in collect_fd() will
> work as expected and it will find the file_desc
> we just added in autofs_create_pipe()->collect_one_pipe_ops().
>
> So, the not-generic helper may be killed.
>
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>

Returned debug print:

[PATCH 4/5 v2]files: Kill autofs_create_fle() and use generic helper

Everything is prepared: the pair "type and id" is
uniqul, so find_file_desc() in collect_fd() will
work as expected and it will find the file_desc
we just added in autofs_create_pipe()->collect_one_pipe_ops().

So, the not-generic helper may be killed.

v2: Leave debug print on the place.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Acked-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Acked-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:14:06 +03:00
Kirill Tkhai
940187818c autofs: Delete alignment in autofs_create_fle()
shmalloc() already returns address with sizeof(unsigned long)
alignment. So, the second alignment is useless.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:13:51 +03:00
Kirill Tkhai
70be2395bf files: Add fake fle flag and close such fles after restore files
Allow to mark some fles as "fake" and close them, when they are not needed.

v2: Cache fake file in separate list, when they are restored,
to do not iterate over files list again.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:09:10 +03:00
Kirill Tkhai
82acfd4487 files: Merge shmalloc() to fle_init()
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:08:50 +03:00
Kirill Tkhai
7e9fe49f54 files: Move fle_init() to files.c
It has only one user. Also, in next patches will be
used pstree_item_by_virt() function, and I don't
want to add "#include" to "files.h" for it, and to
nest headers.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:08:33 +03:00
Kirill Tkhai
f6c9ac7e0d files: Declare structures of fake masters
Fake masters are files, which are not owned by
a process, that is able to open them.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 11:03:22 +03:00
Pavel Emelyanov
882bacffc1 net: Don't try to restore sit6rd when not present
Due to a misprint in an if the 6rd info for sit device
was restored when not present.

https://github.com/xemul/criu/issues/366

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 10:48:46 +03:00
Pavel Emelyanov
fb85281c3b zdtm: Test sit device C/R
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 10:48:46 +03:00
Pavel Emelyanov
87bfe58800 net: Restore sit device from image
Same here -- prepare the IFLA_INFO_DATA section using the
date from SitEntry.

Issue #11

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 10:48:46 +03:00
Pavel Emelyanov
4a044e6af9 net: Dump regular sit device
Nothing special here, just parse all known NLAs and keep them
on the image.

Issue #11

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 10:48:46 +03:00
Andrei Vagin
0509bc9f17 restore: set a dumpable flag after restoring changing uid and gid
This flag is reseted each time when uid-s, gid-s or capabilities
are changed.

------------------------ grep Error ------------------------
(00.235109)      6: Opening 0x002ad2fb7a1000-0x002ad2fb7a2000 0000000000000000 (101) vma
(00.235115)      6: Search for 0x002ad2fb7a1000 shmem 0x3ec72 0x2b9ac74058c0/5
(00.235119)      6: Waiting for the 3ec72 shmem to appear
(00.235122)      6: Opening shmem [/proc/5/fd/6]
(00.235153)      6: Error (criu/shmem.c:453): Can't open 5/fd/6 on procfs: Permission denied
(00.235171)      6: Error (criu/mem.c:1200): `- Can't open vma
(00.283466) uns: calling exit_usernsd (-1, 1)
(00.283521) uns: daemon calls 0x47f6b0 (189, -1, 1)
(00.283532) uns: `- daemon exits w/ 0
(00.289212) uns: daemon stopped
(00.289232) Error (criu/cr-restore.c:2152): Restoring FAILED.
------------------------ ERROR OVER ------------------------

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 10:21:45 +03:00
Andrei Vagin
f65517b95d shmem: dump shared memory before dumping namespaces
page_ids is a global variable and it is used to dump shared memroy,
process memory and ipc shared memory.

The problem is that an IPC namespace is dumped in a child process,
so page_ids isn't changed in a parent process. This patch is a quick
workaround this issue.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 10:21:45 +03:00
Andrei Vagin
0768d9203f zdtm: rework a synchronization scheme
Currently test_daemon() sends a signal to a parent process,
when a test completed a prepartion stage. But it doesn't work,
if a child changed uid and gid, because it doesn't have enough
permissions in this case.

This patch reworks a synchronization scheme to use a futex
instead of sending signals.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 10:21:45 +03:00
Cyrill Gorcunov
eff4c2acf4 test: thread_different_uid_gid -- Fixup sync points
Wait for thread to finish its creation instead of
calling sleep. Same time call for test_daemon
only when we're ready.

CC: Vitaly Ostrosablin <vostrosablin@virtuozzo.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 10:21:45 +03:00
Cyrill Gorcunov
bd56115303 test: thread_different_uid_gid -- Style nitpicking
CC: Vitaly Ostrosablin <vostrosablin@virtuozzo.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 10:21:45 +03:00
Andrei Vagin
105765830b zdtm: skip vsyscall vmas for x32 tests
It is known issue that a vsyscall vmas are not unmapped
from x32 processes.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 10:21:45 +03:00
Andrei Vagin
aa9b6a5d1a fault_inject: use SIGKILL instead of BUG() to kill itself
If a process calls BUG(), it genereates a core file and
we get a false warning from abrtd.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 10:21:45 +03:00
Andrei Vagin
44dc01597a zdtm: don't use getpwnam and getgrnam
For us it doesn't matter what names of users and groups are used,
we want to be sure that we restore right uid-s and gid-s.

If we use these functions, we can't run tests in namespaces and
they use an external unix socket, what can be a problem too.

sk unix: 	Runaway socket: ino 0x1df1ae4 peer_ino 0x1df1ae3 family    1 type    1 state  1 name /run/dbus/system_bus_socket
Error (criu/sk-unix.c:712): sk unix: External socket is used. Consider using --ext-unix-sk option.

Cc: Vitaly Ostrosablin <vostrosablin@virtuozzo.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 10:21:45 +03:00
Andrei Vagin
ac21ffe215 travis: set umask before a first criu run
so that .gcda (coverage data) files are created with read-write
permissions for all, otherwise uns tests will not be able to
modify these files and code coverage data will not be collected
for them.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 10:21:45 +03:00
Andrei Vagin
040c2487ea zdtm: check a reseted tcp connect
This test create a closed socket with a non-empty sent queue.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Andrei Vagin
c821f24d5b libsoccr: ignore data in a sent queue, if a connect is closed
If a connection was reseted, it can have some data in a sent queue,
a use can't read this data, so we can ignore them too.

https://jira.sw.ru/browse/PSBM-67026

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Alice Frosi
865f099d70 s390: Add test case for RI
- Add new test "s390x_runtime_instr" to check if the RI control block is
   correctly restored when the RI is active.

 - Add RI control block in test s390x_regs_check.c

The original test case for RI has been provided by
Martin Schwidefsky <schwidefsky@de.ibm.com>

Signed-off-by: Alice Frosi <alice@linux.vnet.ibm.com>
Reviewed-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Alice Frosi
581f731ba6 s390: Add test case for GS
- Add new test "s390x_gs_threads" for GS with broadcast command for the
s390_guarded_storage() system call.

 - Add GS control blocks in test s390x_regs_check.c

The original test case for GS has been provided by
Martin Schwidefsky <schwidefsky@de.ibm.com>

Signed-off-by: Alice Frosi <alice@linux.vnet.ibm.com>
Reviewed-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Alice Frosi
16474786cb s390: Add runtime-instrumentation support
Dump and restore process with RI control block. Runtime instrumentation
allows to collect information about program execution as CPU data.

The RI control block is dumped and restored for all threads.

Ptrace kernel interface is provided by:
c122bc239b13 ("s390/ptrace: add runtime instrumention register get/set")

Signed-off-by: Alice Frosi <alice@linux.vnet.ibm.com>
Reviewed-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Alice Frosi
a144210451 s390: Add guarded-storage support
Dump and restore tasks with GS control blocks. Guarded-storage is a new
s390 feature to improve garbage collecting languages like Java.

There are two control blocks in the CPU:

 - GS control block
 - GS broadcast control block

Both control blocks have to be dumped and restored for all threads.

Signed-off-by: Alice Frosi <alice@linux.vnet.ibm.com>
Reviewed-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Alice Frosi
04e0bcae1d Restore registers not present in the sigreturn signal frame
Add new function arch_set_task_regs_nosigrt(). It allows to restore
architecture-specific registers not present in sigreturn signal frame.

Each architecture can overwrite this function.

The arch_set_task_regs_nosigrt function restores the registers between the
final sigreturn and PTRACE_DETACH. We do this at this point because
we are sure that all threads have already been created.

Add arch_set_thread_regs in pre-dump because some registers may have
been changed by the parasite infection and they are not present in
sigreturn signal frame.

Signed-off-by: Alice Frosi <alice@linux.vnet.ibm.com>
Reviewed-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Mike Rapoport
3fb3e87058 travis/lazy-pages: explicitly define the tests to verify lazy-pages
Running all the tests with --lazy-pages and --remote-lazy-pages takes too
long. Let's run only several representing tests for those cases.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Mike Rapoport
0ee7df54de lazy-pages: treat ENOMEM returned by UFFDIO_UNREGISTER as task exit
The UFFDIO_UNREGISTER returns ENOMEM only when it is unable to get
mm_struct. We can assume in such case that the task is exited.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Adrian Reber
f41e386d4d fix building on newest glibc and kernel
On Fedora rawhide with kernel-headers-4.14.0-0.rc2.git0.1.fc28.x86_64
glibc-devel-2.26.90-15.fc28.x86_64 criu does not build any more:

In file included from /usr/include/linux/aio_abi.h:31:0,
                 from criu/cr-check.c:24:
/usr/include/sys/mount.h:35:3: error: expected identifier before numeric constant
   MS_RDONLY = 1,  /* Mount read-only.  */
   ^
make[2]: *** [/builddir/build/BUILD/criu-3.5/scripts/nmk/scripts/build.mk:111: criu/cr-check.o] Error 1
make[1]: *** [criu/Makefile:73: criu/built-in.o] Error 2
make: *** [Makefile:233: criu] Error 2

This simple re-ordering of includes fixes it for me.

Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Andrei Vagin
5dc2e922d7 travis: mount tmpfs into /run for docker containers
Otherwise we will see warnings like these ones:
Warn  (criu/kerndat.c:805): Can't load /run/criu.kdat
Warn  (criu/net.c:2726): Unable to get a socket network namespace
Warn  (criu/kerndat.c:844): Can't keep kdat cache on non-tempfs

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Andrei Vagin
f54acb48f9 zdtm: fix warnings from flake8
test/zdtm.py:1535:30: E711 comparison to None should be 'if cond is not None:'
test/zdtm.py:1538:31: E711 comparison to None should be 'if cond is not None:'
test/zdtm.py:1601:31: E711 comparison to None should be 'if cond is not None:'

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Vitaly Ostrosablin
7d12ce293c zdtm: Implement different per-thread credentials testcase
As requested, implement a test with two threads that have mismatching,
non-root credentials, like Apache does.

Signed-off-by: Vitaly Ostrosablin <vostrosablin@virtuozzo.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Cyrill Gorcunov
da3f0d9a06 criu: threads -- Allow uids/gids being different
We are carrying uids/gids in per-thread way since v1.8,
so no need to require them to match anymore. We still
require seccomp to match though. Need to revisit, seems
may relax this requirement as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Cyrill Gorcunov
4ff68eeb36 fsnotify: Filter event mask from old kernels
When checkpoint is done on the kernels where
commit 6933599697c96c3213c95f5f1fc7cb6abfd08c54
is not yet present then mask is not filtered
and saved in image in this raw form.

For such case restore on more modern kernels
will fail because only a small set of events
are allowed to pass from userspace.

Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00
Andrei Vagin
251b4d06a9 zdtm: report test results in the junit format
We found a good plugin for Jenkins to analize test results,
but it can handle only the junit format.

v2: work without the junit python module
v3: install junit-xml, because zdtm.py is executed
    with the --report option from jenkins scripts.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-10-17 08:40:44 +03:00