Commit graph

6592 commits

Author SHA1 Message Date
Pavel Emelyanov
4576a03385 tests: Check that no-breakpoints restore works
v2: Don't clear_breakpoints too.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-05-06 14:38:29 +03:00
Cyrill Gorcunov
54d7913be0 build: Add INSTALL.md and update "make help"
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-05-06 14:38:29 +03:00
Stanislav Kinsburskiy
ca393ebdf7 sources: fix pr_perror usage
This is log cleanup patch.
Pr_perror prints new line by itself.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-05-06 14:38:25 +03:00
Pavel Emelyanov
1c7afb7f61 actions: Do not set envs twice
The IMAGES_DIR and INIT_PID are constants so it's
enough to set the only once per criu.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-05-06 14:35:45 +03:00
Pavel Emelyanov
185cfc05ee actions: Move shell scripts into helper
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-05-06 14:35:45 +03:00
Pavel Emelyanov
ac78f13bdf actions: Introduce explicit scripts mode
We effectively have two modes of actions -- call shell
scripts and call RPC. So make ths code work such. As a
side effect -- we don't mess with environment variables
in case of RPC notifications.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-05-06 14:35:45 +03:00
Pavel Emelyanov
a8510f7d31 actions: Add rpc notify with separate call
This lets us clean the action-script.c eventually.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-05-06 14:35:45 +03:00
Pavel Emelyanov
f2012edce3 actions: Move struct script into .c file
The same -- it's internal action-scripts.c business.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-05-06 14:35:44 +03:00
Pavel Emelyanov
a9c0864284 actions: Move scripts list into .c file
It's used purely inside action-scripts.c, so move
it there not to pollute the global opts.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-05-06 14:35:44 +03:00
Pavel Emelyanov
eb53f9beae mount: Fix brace formatting
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-05-04 19:02:31 +03:00
Andrew Vagin
6dfd7cf519 util: cr_system_userns() should not affect log_fd
Fixes: 1dc2f87b33ce ("util: shutdown log in cr_system_userns if error fd is negative")
Cc: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-27 14:13:35 +03:00
Cyrill Gorcunov
3276406d65 build: Add uninstall action
While most are handled from the scratch there is a significant
problem with python setup. So I added some preliminaty solution,
probably someohe with good knowledge of how setup.py works
improve it later.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-27 14:13:35 +03:00
Cyrill Gorcunov
339a7868b9 build: install -- Add BINDIR var
Will need it for uninstall action.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-27 14:13:33 +03:00
Stanislav Kinsburskiy
7a25c82bfd util: shutdown log in cr_system_userns if error fd is negative
Otherwise error in case of exec error won't be printed
The problem is that when err fd is negative, it's replaced by log fd.
Then err is moved to STDERR (that means, that log_fd is _closed_).
But log facility still consider log fd as valid and tries to use it to print
error message in case of exec failure.
Which is equal to writing to /dev/null, basically.
This patch shutdown log, if err fd was negative, thus forcing criu to output
exec error to STDERR (which was replaced by log fs, btw).

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-27 14:12:25 +03:00
Kirill Tkhai
781601a053 zdtm: Custom file names in binfmt_misc test
If several copies of binfmt_misc test are running, we may fail because of duplicate names.
Fix that by giving a custom name for registered /proc/sys/fs/binfmt_misc/xxx.

################## Test zdtm/static/binfmt_misc FAIL at start ##################
Test output: ================================
18:03:33.594: 4: string: :magic_file:M:9:\x73\x51\xff\x4a\xec\x29\xcd\xba\xab\xf2::/bin/interpreter:OCP
18:03:33.594: 4: FAIL: binfmt_misc.c:133: write magic_file (errno = 22 (Invalid argument))
18:03:33.594: 3: ERR: test.c:204: Test exited unexpectedly with code 1

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-27 14:12:25 +03:00
Andrew Vagin
d3cf1c4f2b restore: Wait for userns being prepared before moving into cgroups (v3)
When user namespace are stepping in we should wait for their preparation
to complete before start using userns daemon (internally the kernel
checks for uids and if uids are not set -EINVAL will be returned
when usersn calls for sendmsg()).

v2: change stages correctly
v3: Wait prepare_userns() before making any calls to usernsd()

Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-27 14:12:23 +03:00
Dmitry Safonov
bd057dc3ad util: add parameter parenthesis to __open_proc statement in expr
Fixes small bug:
__open_proc() macro is called from parse_pid_loginuid as:
>	fd = __open_proc(pid, (ignore_noent) ? ENOENT : 0,
>			O_RDONLY, "loginuid");

So, ier parameter is badly expanded with current version:
>	if (__fd < 0 && (errno != (ignore_noent) ? ENOENT : 0)

Which in result does not hide "No such file" error on feature
test (at least with arm-gcc). Not a big deal, tho.

Reported-by: alex vk <avankemp@gmail.com>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-27 14:11:03 +03:00
Dmitry Safonov
871d21807b kerndat: use PROC_SELF in loginuid test
Impact: little optimization

Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-27 14:11:03 +03:00
Andrew Vagin
7a2068e374 zdtm: fix compilation of netns-dev
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-27 14:11:03 +03:00
Pavel Tikhomirov
0d8289d852 zdtm/net/ipv4: rename devconfs4 and rand_limit4 and dir4
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-27 14:11:03 +03:00
Pavel Tikhomirov
af851fdf53 net/ipv4: suffix devconfs with "4"
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-27 14:11:03 +03:00
Pavel Tikhomirov
ae682757fd net/ipv4: add new sysctls
drop_unicast_in_l2_multicast and drop_gratuitous_arp appeared in MS:

commit 12b74dfadb5a ("ipv4: add option to drop unicast encapsulated in
L2 multicast")
commit 97daf3314550 ("ipv4: add option to drop gratuitous ARP packets")

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-27 14:11:03 +03:00
Andrew Vagin
5bdc16238b files: try to change fsuid only if linkat() failed
We found that linkat for "unsafe" files doesn't work in userns
if a file uid isn't equal to the currect fsuid. This issue was
fixed by changing fsuid before calling linkat. But in this
case we are not able to createa link if a target directory doesn't
have write premissions.

Starting with the 4.3 kernel, it's possible to create links of
"unsafe files":

f2ca379642d7 ("namei: permit linking with CAP_FOWNER in userns")

So we can try to call linkat() without changing fsuid and make one
more attempt with changing fsuid if the first one failed with EPERM.

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-27 14:11:02 +03:00
Cyrill Gorcunov
555972746f build: install -- Don't forget to init DESTDIR
When not set up it leaves empty making setup of
pycriu python library wrong. Define it as root.

Reported-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-21 16:21:24 +03:00
Andrew Vagin
6e7e2efc5e criu: check without file descriptors
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Acked-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-21 16:21:24 +03:00
Kirill Tkhai
2bf231496f files: Correctly handle tasks with no open file descriptors
Do not fail, if task doesn't have open files. This fixes
zdtm/static/fd test, which is broken now:

(00.004411) Error (cr-dump.c:1312): Dump files (pid: 25) failed with -1
(00.004548) Error (cr-dump.c:1614): Dumping FAILED.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-21 16:21:24 +03:00
Cyrill Gorcunov
cabfbbef36 criu: action-scripts -- Don't access @root_item_pid if not present
It might be nil on predump, so dereference only when present.

Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>
Acked-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-21 16:21:24 +03:00
Andrei Vagin
49877012e3 zdtm: check the mem_dirty_track if --pre or --snap is set
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-21 16:21:24 +03:00
Stanislav Kinsburskiy
fb7e5a3ee6 Fix compilation of action-scripts.c
The only one (so far) "post-resume" script needs some pid to join its

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-21 16:21:24 +03:00
Pavel Emelyanov
6d9507f44f kdat: Remove tcp_max_rshare
TCP code doesn't need one any longer.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-21 16:21:23 +03:00
Pavel Emelyanov
d5a7a1cb50 tcp: Send as much as possible
Don't mess with sysctl, just try sending queues in greedy mode
shrinking the max_chunk eventually.

This is needed for 2 reasons -- first, to get rig of reading the
max_rshare sysctl and to make libsoccr possible and simple.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-21 16:21:23 +03:00
Andrew Vagin
72b48d2713 sk: handle erorors of lseek
CID 159475 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)
1. check_return: Calling lseek(img_raw_fd(img), pkt->entry->length, 1)
   without checking return value. This library function may fail and return an error code.

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-21 16:21:23 +03:00
Stanislav Kinsburskiy
40b68eb405 cr-restore: set NS_PID environment variable before "post-resume" hook
The only one (so far) "post-resume" script needs some pid to join its
namespaces. Let it be containers root.

v4:
1) Enviroonment setup has been was moved to run_scripts
2) Environment variable NS_PID was renamed to CRTOOLS_INIT_PID

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-21 16:21:23 +03:00
Stanislav Kinsburskiy
2ab599398d cr-restore: "post-resume" hook introduced
This hook is called at the very end, when everything is restored and processes
were resumed.
Can be used for some actions, which require operation container, like
restarting of systemd autofs services.

v3:
Call "post-resume" scripts before detach option check (to make sure, that
restored process(es) are still alive

v2:
Remove code chunk, escaped from debugging

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-21 16:21:23 +03:00
Pavel Emelyanov
9f7f0e02a4 criu: Version 2.1
Here's the first once-a-month release with whatever is there in
the master branch. We have quite a few new features, but a lot of
bugifxes :)

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-11 11:19:43 +03:00
Andrew Vagin
a4205bbab5 files: change PARASITE_MAX_FDS to work with the default file limit
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:45 +03:00
Andrew Vagin
96a355ab17 files: dump file descriptors by portions (v2)
Currently criu can't handle a processes with more than 1024
file descriptors.

In this patch, criu dumps file descriptors for a few iterations.

Fixes https://github.com/xemul/criu/issues/145

v2: don't move the collect stage

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:45 +03:00
Andrew Vagin
a249869dbb files: expand slice for parasite_drain_fd dinamically
We are going to remove the PARASITE_MAX_FDS limit and
this patch is a preparation for this.

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:45 +03:00
Dengguangxing
3b70d9a1ff modify switch_ns error message
Signed-off-by: Deng Guangxing <dengguangxing@huawei.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:45 +03:00
Tycho Andersen
4f84171df7 net: allow dumping of gre0 and gretap0
These devices are injected into every network namespace when the ip_gre
module is loaded. They cannot be configured as usable tunnels, so let's
just ignore them.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:45 +03:00
Cyrill Gorcunov
1700a9bf20 build: criu -- Don't forget to cleanup arch directory
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:44 +03:00
Cyrill Gorcunov
0602bca40f cg: Add rollback in get_cg_set
In case of error inside collect_cgroups we need

- @ctls list has been spliced into @cs->ctls so we cant just free it,
   but rather use put_ctls on @cs->ctls

- delete @cs->l from global @cg_sets list before free it

Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>
Reviewed-by: Andrew Vagin <avagin@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:44 +03:00
Cyrill Gorcunov
be5062c1c2 cg: Add rollback for add_cgroup
If add_cgroup_properties failed we have @ncd sitting
in @match->children or @current_controller->heads
list, and then we free @ncd entry leaving those
lists carrying dead pointers.

Add proper rollback action.

Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:44 +03:00
Cyrill Gorcunov
94bfda900e cg: Fix use-after-free in put_ctls
Since we're freeing list entries don't forget to
initialize list then, otherwise it gets out with
free entries and may hit use-after-free bug.

Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:44 +03:00
Dmitry Safonov
c553fe04f4 parasite-syscall: print syscall number as %lu
We will still able to distinguish if it's garbage in ax register, but
this is definitely prettier:
(00.036900) 687 was trapped
(00.036903) 687 is going to execute the syscall 158
(00.036928) 687 was trapped
(00.036931) 687 is going to execute the syscall 173

Than that:
(00.024403) 687 was trapped
(00.024407) 687 is going to execute the syscall 9e
(00.024419) 687 was trapped
(00.024421) 687 is going to execute the syscall ad

Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:44 +03:00
Cyrill Gorcunov
3e48109a4d criu: Drop prlimit compat layer
Previously when we've been on early stage we
tried to workaround lack of prlimit libc call
simply providing own implementation,  but it
cause problems on some libc configurations so
simply use rlimit64 and __NR_prlimit64 syscall
directly.

The kernel must support __NR_prlimit64 syscall
and provide rlimit64 structure as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:42 +03:00
Pavel Emelyanov
c881d0449c criu: Warn about --namespaces deprecation
The option was in use when we didn't have the /proc/pid/ns links
and thus ns ids. Later we used it at restore time to tell which
namespaces to restore the pstree into. Right now ids are always
generated and this option has no effect (and meaning).

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:56:50 +03:00
Pavel Emelyanov
75a9c3b697 rst: Deprecate no ids.img case
We've been writing this file since 0.4, hopefully nobody's
using such an oldie :)

v2: Don't BUG_ON, but return error, as this can be triggered
by corrupting images.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:56 +03:00
Cyrill Gorcunov
0cdd2a2964 pie: open_detach_mount -- Use pr_perror for regular build
This helper is used in both PIE and non-PIE code.
For the second we can use normal pr_perror.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:56 +03:00
Andrew Vagin
caec89267b util: return aligned pointers from shmalloc()
Atomic operations doesn't work for non-aligned pointers.

=[log]=> dump/zdtm/static/autofs/30/2/restore.log
------------------------ grep Error ------------------------
(00.185037)      5: Error (/root/git/criu/criu/include/lock.h:78): BUG at /root/git/criu/criu/include/lock.h:78
(00.207193) Error (cr-restore.c:1407): 100 killed by signal 9: Killed
(00.219187) Error (cr-restore.c:2237): Restoring FAILED.
------------------------ ERROR OVER ------------------------

4339  futex(0x7fa79c1561da, FUTEX_WAKE, 2147483647 <unfinished ...>
4339  <... futex resumed> )             = -1 EINVAL (Invalid argument)

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:56 +03:00