Commit graph

5142 commits

Author SHA1 Message Date
Oleg Nesterov
b66728ef14 parse_mountinfo: fix and simplify the usage of r_fstype
1. parse_mountinfo() forgets to free(fst) if parse_mountinfo_ent()
   succeeds.

2. The usage of fst/r_fstype is ovecomplicated for no reason.

Just change the parse_mountinfo() paths to populate/use/free this
fsname unconditionally, and move the ownership to the caller. There
is no reason to check FSTYPE__UNSUPPORTED and/or fallback to ->name.

Better yet, we could even turn fsname into the local "char []" and
avoid %ms and free(), but then we would need to pass the length of
this buffer to parse_mountinfo_ent().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-30 13:20:37 +03:00
Oleg Nesterov
2cfeeac465 parse_mountinfo: add the "end" block into the main loop
Preparation to simplify the review. parse_mountinfo() assumes that:

1. The "err:" block does all the necessary cleanups on failure.

   This is wrong, see the next patch.

2. We can never skip the mountpoint.

   This is true, but we are going to change this.

s/goto err/goto end/ in the main loop, add the "end:" label which inserts
the new mount_info into the list and then checks ret != 0 to figure out
whether we need to abort.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-30 13:20:36 +03:00
Andrey Vagin
b23268e492 service: add ability to set inherit file descriptors (v3)
This is required to use criu swrk in libcontainer.

v2: remove useless function declaration
    allow to set inherit_fd only for swrk
v3: check swrk out of loop

Cc: Saied Kazemi <saied@google.com>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-30 13:09:25 +03:00
Andrey Vagin
54d0f24107 proc_parse: fixed format strings
Use the format specifier PRIx64 instead of %lx to print uint64.
integer.

Reported-by: Mr Travis CI
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-27 15:27:59 +03:00
Cyrill Gorcunov
6608402c97 zdtm: Don't modify global @errno in test_msg
This is logging routine, lets it not affect the global @errno.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-27 14:06:23 +03:00
Cyrill Gorcunov
f76a57c29a log: Don't modify global @errno in __print_on_level
The __print_on_level routine may modify global @errno
variable which is inacceptable: this is logging routine
which must be transparent to the rest of the program code.

Thus save @errno in local @__errno variable and restore
it on return.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-27 14:06:20 +03:00
Andrey Vagin
019ab4b795 test: check read-only bind-mounts
Here is a real example how it's used.

Cc:  Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Tested-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-27 14:04:26 +03:00
Oleg Nesterov
57db932a0a mount: always report ->mnt_id as decimal
validate_mounts() prints ->mnt_id in hex when it reports the failure.
This complicates the understanding because this ->mnt_id is printed as
decimal elsewhere, including /proc/$pid/mountinfo.

parse_mountinfo() adds "0x" at least and this is just pr_info(), but
lets change it too.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Andrew Vagin <avagin@openvz.org>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-27 14:03:04 +03:00
Andrey Vagin
8329f06145 zdtm: suppress error messages if a cgroup holder exists
mkdir: cannot create directory ‘zdtm.mpAWGL/holder’: File exists

Reported-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-27 14:02:17 +03:00
Andrey Vagin
36f0c16db0 proc: move logic about adding vma into a list in a separate function
parse_smaps() is too big for easy reading. In addition, we are
creating a new interface to get information about processes, which is
called taskdiag, so parse_smaps() will do only what it should do
accoding with the name. All other should be moved in a separate
functions which will be reused to work with task_diag.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-27 14:01:19 +03:00
Andrey Vagin
046245dcb0 proc: move logic about filling vma structures into a separate function
parse_smaps() is too big for easy reading. In addition, we are
creating a new interface to get information about processes, which is
called taskdiag, so parse_smaps() will do only what it should do
accoding with the name. All other should be moved in a separate
functions which will be reused to work with task_diag.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-27 14:00:50 +03:00
Cyrill Gorcunov
6d30f4680b test: poll -- Move it out of namespace list
For some reason it returns ENOENT sometime
when run in namespace. Need to figure out
why. Disable it for a while to continue
testing the rest.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-26 14:13:27 +03:00
Andrey Vagin
4988a57981 test: create /etc in a temporary root
inotify_irmap creates files in /etc so it should be able to do
this from userns.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-26 14:12:08 +03:00
Andrey Vagin
9daefff5ca cgroup: call fini_cgroup() on error paths
Currenlty if criu fails before prepare_cgroup_properties(),
cgyard isn't umounted.

I think it's déjà vu, but it isn't :)

commit 28b0e16d73
Author: Andrew Vagin <avagin@openvz.org>
Date:   Mon Aug 25 14:29:00 2014 +0400

    cgroup: call fin_cgroup() on error paths

Cc: Tycho Andersen <tycho.andersen@canonical.com>
Cc: Saied Kazemi <saied@google.com>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-26 14:11:24 +03:00
Oleg Nesterov
dd71cca58a dump/x86: sanitize the ERESTART_RESTARTBLOCK -> EINTR transition
1. The -ERESTART_RESTARTBLOCK case in get_task_regs() depends on kernel
   internals too much, and for no reason. We shouldn't rely on fact that
   a) we are going to do sigreturn() and b) restore_sigcontext() always
   sets restart_block->fn = do_no_restart_syscall which returns -EINTR.

   Just change this code to enforce -EINTR after restore, this is what
   we actually want until we teach criu to handle ERESTART_RESTARTBLOCK.

2. Add pr_warn() to make the potential bug-reports more understandable,
   a sane application should handle -EINTR correctly but this is not
   always the case.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-26 14:10:32 +03:00
Andrey Vagin
81a4d3b2eb test: don't run cow01 in userns
/proc/pid/pagemap is protected by the global CAP_SYS_ADMIN, so
it can't be opened in a non-root userns.

00:34:48.260 Execute ns/user/static/cow01
...
00:34:48.260 12:37:03.951:     4: ERR: cow01.c:87: Unable to open child pagemap file /proc/5/pagemap (errno = 1 (Operation not permitted))

Reported-by: Mr Jenkins
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-25 17:16:59 +03:00
Cyrill Gorcunov
089e81ac2f zdtm: test -- Add trivial poll() timeout test
The idea is simply make sure that timeour has not been
screwed during c/r cycle.

v2:
  - Drop unneeded early poll() call.
  - Make poll loop in cycle until caller passes c/r cycle.
v3:
  - Use test_go helper
  - Do poll in cycle

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-25 17:13:34 +03:00
Tycho Andersen
109ca471c4 fix error in tests when /bin/sh is not bash
== is a bashism, we should use = for /bin/sh; this prevents output like:

/home/ubuntu/criu/test/post-dump.sh: 3: [: post-dump: unexpected operator
/home/ubuntu/criu/test/post-dump.sh: 3: [: network-unlock: unexpected operator

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-24 11:24:02 +03:00
Tycho Andersen
7248cad94c finalize cgroups correctly
We need to finalize the cg yard both on successful cgroup restore and on a
failed restore. Further, we should restore the cgroup properties before
allowing the task to continue in all modes (previously properties were only
restored correctly in --restore-detached mode).

CC: Saied Kazemi <saied@google.com>
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-24 11:24:00 +03:00
Andrey Vagin
7c2b4b1380 test: add ability to execute tests in a docker container
# Build criu in a docker container
$ make direct-build
 # Execute tests in a docker container
$ make direct-test

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-24 11:05:47 +03:00
Andrey Vagin
9cabc3918a test: remove bashism from Makefile
* redirect both stdout and stderr
bash: >& and &>
dash: command > file 2>&1 or command 2>&1 | othercommand

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-24 11:05:26 +03:00
Andrey Vagin
902f9f3c89 zdtm: fix awk script for Ubuntu
mawk doesn't handle '\<...\>'

Ubuntu:
$ awk -W version
mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan
$ ldd /bin/ps
	linux-vdso.so.1 =>  (0x00007fffb290a000)
$ ldd /bin/ps  | awk '/\<linux-vdso\.so\>/ { print $1 }'
$ ldd /bin/ps  | awk '/linux-vdso\.so/ { print $1 }'
linux-vdso.so.1

Fedora:
$ ldd /bin/ps
	linux-vdso.so.1 =>  (0x00007fff61fcb000)
$ ldd /bin/ps  | awk '/\<linux-vdso\.so\>/ { print $1 }'
linux-vdso.so.1
$ awk --version
GNU Awk 4.1.1, API: 1.1

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-24 11:05:19 +03:00
Andrey Vagin
a2e0acfdcb cow01: try to read a page to take it from a swap
Vladimir said that a page can be unmapped from one process, but can be
mmaped in another one. In this case we can't understand whether both
processes link to the same page or they don't.

So we can try read both pages to take them from swap.

Cc: Vladimir Davydov <vdavydov@parallels.com>
Reported-by: Parallels' QA
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-24 10:59:50 +03:00
Andrey Vagin
bda4dfd173 test: add cow01 into TEST_SUID_LIST
cow01 uses /proc/pid/pagemap which has been protected by
CAP_SYS_ADMIN.

"""
	commit	ab676b7d6fbf4b294bf198fb27ade5b0e865c7ce
	pagemap: do not leak physical addresses to non-privileged userspace

	As pointed by recent post[1] on exploiting DRAM physical imperfection,
	/proc/PID/pagemap exposes sensitive information which can be used to do
	attacks.
"""

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-23 17:42:03 +03:00
Oleg Nesterov
07dcf0dbb6 restore/x86: restore_gpregs() needs to initialize ->ss as well
Before the recent "x86_64,signal: Fix SS handling for signals delivered
to 64-bit programs" kernel patch, sigreturn paths forgot to restore ->ss
after return from the signal handler.

Now that the kernel was fixed, restore_gpregs() has to initialize ->ss
too, it is no longer ignored.

Note: this is the minimal fix. In the long term we probably should not
dump/restore the segment registers at all. We can use sigcontext filled
by the target kernel and modify the general-purpose regs.

Reported-and-tested-by: Andrey Wagin <avagin@gmail.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-20 16:29:59 +03:00
Ruslan Kuprieiev
044011e579 reg-files: skip size for O_APPEND|O_WRONLY files, v2
This is common for log files, when a number of processes
are writing something into one file. Currently, if someone
wrote something to log since dump happened, on restore criu
will complain about "File has bad size" and refuse to restore.

If file is opened with O_APPEND|O_WRONLY flags it is going to
jump to the EOF anyway.

v2, use O_ACCMODE and separate helper

Signed-off-by: Ruslan Kuprieiev <rkuprieiev@cloudlinux.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-20 16:29:37 +03:00
Pavel Emelyanov
c625b4fbc9 doc: Remove -t from restore command
It's obsoleted and is not required.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-19 13:18:13 +03:00
Kirill Tkhai
83f7e667d9 tests: Add more debug info to caps00 test
Print all cap values in case of test is failed.
Also check for capset() and capsget() return values.

Signed-off-by: Kirill Tkhai <ktkhai@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-18 22:41:11 +03:00
Saied Kazemi
140d65ebca Dismantle cgyard in non-detached restore mode.
If the --restore-detached command line option is not specified during
restore, CRIU should unmount and remove the temporary cgyard directory
tree before waiting for the restored process to exit.  Otherwise, all
the temporary cgyard mount points will remain mounted and visible.

Signed-off-by: Saied Kazemi <saied@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-18 22:39:57 +03:00
Andrey Vagin
a66217a253 image: open lazy images in img_raw_fd()
Lazy images are opened on a first attempt of using.

00:01:18.534 Test: zdtm/live/static/pipe00, Result: FAIL
00:01:18.537 ==================================== ERROR ====================================
00:01:18.538 Test: zdtm/live/static/pipe00, Namespace: 1
00:01:18.538 Dump log   : /var/lib/jenkins/jobs/CRIU/workspace/test/dump/ns/static/pipe00/13536/1/dump.log
00:01:18.540 --------------------------------- grep Error ---------------------------------
00:01:18.543 (00.026666) Error (include/image.h:153): BUG at include/image.h:153
00:01:18.543 (00.050663) Error (namespaces.c:801): Namespaces dumping finished with error 134
00:01:18.543 (00.050918) Error (cr-dump.c:1979): Dumping FAILED.
00:01:18.545 ------------------------------------- END -------------------------------------
00:01:18.548 ================================= ERROR OVER =================================

Reported-by: Mr Jenkins
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-16 17:17:04 +03:00
Pavel Emelyanov
8ce37e676a img: Don't create empty images
Currently on dump we generate too many image files, effectively
all the stuff from the GLOB set is created. The thing is that
sometimes some of created images can be empty (just contain the
magic number at the head). Thos images are useless and just
waste the space.

When applied after the "empty images" set, this introduces the
lazy images -- when we call open_image() the actual file is
only created (and the magic number is written into it) when the
very first object goes into it.

For example for the simplest test we have, then static/env00
one, the created image files are

   core-7290.img
   creds-7290.img
   fdinfo-2.img
   fs-7290.img
   ids-7290.img
   inventory.img
   mm-7290.img
   pagemap-7290.img
   pages-1.img
   pstree.img
   reg-files.img
   sigacts-7290.img

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-16 15:58:32 +03:00
Pavel Emelyanov
7ede4697cf bfd: Don't leak image-open flags into bfdopen
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-16 15:58:14 +03:00
Pavel Emelyanov
f7f76d6ba6 img: Introduce empty images
When an image of a certian type is not found, CRIU sometimes
fails, sometimes ignores this fact. I propose to ignore this
fact always and treat absent images and those containing no
objects inside (i.e. -- empty). If the latter code flow will
_need_ objects, then criu will fail later.

Why object will be explicitly required? For example, due to
restoring code reading the image with pb_read_one, w/o the
_eof suffix thus required the object to be in the image.

Another example is objects dependencies. E.g. fdinfo objects
require various files objects. So missing image files will
result in non-resolved searches later.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-13 14:42:54 +03:00
Pavel Emelyanov
45a0cc4234 page-read: Explicitly mark ENOENT with return code
When page-read fails to open the pagemap image it reports error.
One place (stacked page-reads) need to handle the absent images
case gracefully, so fix the return codes to make this check
work.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-13 14:42:11 +03:00
Pavel Emelyanov
e29c9daec2 img: Remove O_OPT and COLLECT_OPTIONAL
Current code doesn't make any difference between OPT and no-OPT
except for the message is printed or not in the open_image().
So this particular change changes nothing but the availability of
this message.

In the next patches I wil introduce "empty images" to deal with
the ENOENT situation in a more graceful manner.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-13 14:42:01 +03:00
Cyrill Gorcunov
8218e014d0 pie: parasite -- Drop dangling \Tab
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-13 14:33:16 +03:00
Cyrill Gorcunov
290211fb94 tty: Aligh tty_driver members
As done for other structures here in file.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-10 21:16:40 +03:00
Cyrill Gorcunov
19948472d9 tty: Rename tty_type to tty_driver
There are too many "type" in code.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-10 21:16:22 +03:00
Cyrill Gorcunov
819f41eaa5 tty: Drop dangling \Tab
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-10 21:16:15 +03:00
Cyrill Gorcunov
652fbf3bd1 tty: Drop redundant constants
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-10 21:16:10 +03:00
Pavel Emelyanov
f32f4ffa76 img: Open images for dump in O_WRONLY mode
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-09 22:21:15 +03:00
Pavel Emelyanov
618c17b6f8 img: Simplify the open_image() macro
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-09 22:21:08 +03:00
Pavel Emelyanov
131d4b8691 mem: Sanitize error path in prepare_mappings()
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-09 22:20:33 +03:00
Pavel Emelyanov
fce8cac1df mem: Move private vmas maping code into subroutine
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-09 22:20:07 +03:00
Pavel Emelyanov
dceb6633c7 page-read: Introduce custom flags for opening
Instead of open flags and boolean is_shmem argument.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:50:32 +03:00
Pavel Emelyanov
7c7d50fb98 util-fd: Use standard BUG_ON instead of hand-made
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:50:06 +03:00
Cyrill Gorcunov
0328d33e62 test: posix_timers -- Beautify code and output
- easier to read @posix_timers
 - more verbose logging is convernient for handling errors

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:49:29 +03:00
Cyrill Gorcunov
3bd6d9d7b0 image: Add comments about VMA_AREA constants and drop FORCE_READ flag
Force-read came from very first dev version of CRIU (even before 1.0 release)
and never been used actually in image.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:48:47 +03:00
Pavel Emelyanov
48032d8780 tty: Introduce TTY_MASTER flag
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:47:40 +03:00
Pavel Emelyanov
bc535380de tty: Sanitize ctl terminal restore codeflow
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:47:38 +03:00