2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 05:48:05 +00:00

81 Commits

Author SHA1 Message Date
Pavel Emelyanov
eed38acc72 service: Do one exit point from cr_service_work
That's preparation to "several requests per connection" patch.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-09-05 13:49:19 +04:00
Pavel Emelyanov
76017ec5a4 scripts: Use numeric action val in RPC notifications
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-09-05 13:48:27 +04:00
Pavel Emelyanov
069bdd9674 scripts: Move scripts code into separate sources
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-09-05 13:48:21 +04:00
Pavel Emelyanov
7058714fda service: Add ability to inherit page server socket
The swrk action is turning out to be a cool thing. We can
spawn criu with swrk action with some FD being open, then
ask for dump/pre-dump/page-server telling it that some
descriptor it needs is "out there".

This patch lets us specify that the page server communication
channel is already in criu's fdtable.

TODO: teach regular service to accept fd via service socket.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-09-03 20:50:12 +04:00
Ruslan Kuprieiev
9089ce89c4 service: use setproctitle
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Acked-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-09-02 16:15:20 +04:00
Pavel Emelyanov
070757c142 rpc: Add "cgroup root" fields to criu_opts
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
2014-08-22 19:20:04 +04:00
Tycho Andersen
f95b05eb75 opts: add --manage-cgroups option
criu managed cgroups is now an opt-in thing, so by default criu does not manage
(i.e. dump or restore) cgroups. This allows users to use the previous behavior.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-12 14:32:50 +04:00
Ruslan Kuprieiev
2b268c6c21 security: check additional groups,v5
Currently, we only check if process gids match primary gid of user.
But process and user have additional groups too. So lets:
     1) check that process rgid,egid and sgid are in the user's grouplist.
     2) on restore check that user has all groups from the images.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-06 10:20:27 +04:00
Pavel Emelyanov
d30521a3cf crtools: Add internal "swrk" action
To help restoring tasks from images as kids to the caller, we can
do the trick.

1. Caller sets himself as child reaper with PR_SET_CHILD_SUBREAPER prctl
2. Caller makes sure criu binary is suid-ed and owned by root
3. Caller forks and calls execv() on criu asking it to restore
4. Criu finishes restore and exits. All its kids get reparented to the
   criu's parent, i.e. -- to the library caller.
5. Caller stops being subreaper

In order to make the execv() and arguments passing simpler I propose
to execv() the service worker function, that accepts options via socket.

This is good for two reasons.

1. We don't have to construct CLI options in libcriu
2. We reuse other service's facilities, such as security checks,
   ability to dump, pre-dump and other stuff

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-27 14:24:33 +04:00
Pavel Emelyanov
c7e0042946 crtools: Introduce the --ext-mount-map option (v3)
On dump one uses one or more --ext-mount-map option with A:B arguments.
A denotes a mountpoint (as seen from the target mount namespace) criu
dumps and B is the string that will be written into the image file
instead of the mountpoint's root.

On restore one uses the same --ext-mount-map option(s) with similar
A:B arguments, but this time criu treats A as string from the image's
root field (foobar in the example above) and B as the path in criu's
mount namespace the should be bind mounted into the mountpoint.

v3:
* Added documentation
* Added RPC bits
* Changed option name into --ext-mount-map
* Use colon as key and value separator

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-17 10:36:30 +04:00
Deyan Doychev
69a6bf4439 criu: Add exec-cmd option (v3)
The --exec-cmd option specifies a command that will be execvp()-ed on successful
restore. This way the command specified here will become the parent process of
the restored process tree.

Waiting for the restored processes to finish is responsibility of this command.

All service FDs are closed before we call execvp(). Standad output and error of
the command are redirected to the log file when we are restoring through the RPC
service.

This option will be used when restoring LinuX Containers and it seems helpful
for perf or other use cases when restored processes must be supervised by a
parent.

Two directions were researched in order to integrate CRIU and LXC:

1. We tell to CRIU, that after restoring container is should execve()
   lxc properly explaining to it that there's a new container hanging
   around.

2. We make LXC set himself as child subreaper, then fork() criu and ask
   it to detach (-d) from restore container afterwards. Being a subreaper,
   it should get the container's init into his child list after it.

The main reason for choosing the first option is that the second one can't work
with the RPC service. If we call restore via the service then criu service will
be the top-most task in the hierarchy and will not be able to reparent the
restore trees to any other task in the system. Calling execve from service
worker sub-task (and daemonizing it) should solve this.

Signed-off-by: Deyan Doychev <deyandoichev@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-03-25 01:20:02 +04:00
Pavel Emelyanov
edde5fb461 irmap: Add option that forces fsnotify watches paths resolve
When migrating container with copying its FS, the inode numbers
and thus their handles wil change. This will make the restore of
inotify/fanotify fail, since they do it via fhandles.

We've already faced the problems with fsnotifies on NFS -- they
don't work there. To address this an irmap cache is created on
pre-dump, so to resolve the issue with changed inodes during
migration, we can force the irmap cache build.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-03-06 15:12:05 +04:00
Cyrill Gorcunov
09c810142c service: Add setup of @cpu_cap from rpc request
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-28 20:34:41 +04:00
Tikhomirov Pavel
8a3939a277 rpc: Add the auto-dedup option
Signed-off-by: Tikhomirov Pavel <snorcht@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-21 23:41:43 +04:00
Ruslan Kuprieiev
ab6c165b11 service: don't use name "opts" for CriuOpts
As we have global variable opts, it is bad to use
local var with the same name.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-21 16:24:35 +04:00
Ruslan Kuprieiev
6aaca7968a service: use send_criu_pre_dump_resp() in pre_dump_using_req()
Currently we have a bug, service sends resp of type PRE_DUMP
instead of DUMP. So lets introduce send_criu_pre_dump_resp() and
use it.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-21 16:12:23 +04:00
Pavel Emelyanov
01e88d1c87 rpc: Add ability to specify veth pairs (--veth-pair option)
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-12 00:33:02 +04:00
Pavel Emelyanov
72bf807cfb rpc: Report PID of restore task on setup-namespaces script
This is the first time restorer gets info back from CRIU
service. At that time it makes perfect sense to report
what PID we're working with.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-11 09:53:32 +04:00
Pavel Emelyanov
3172b0bd62 rpc: Add link-remap option
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-07 16:24:37 +04:00
Kir Kolyshkin
3835ff83c9 cr-service.c: rm extra error messages
setup_opts_from_req() prints an error message, so there's no need
for its caller to print another one.

While at it, simplify/unify error checking, treating any
non-zero value as an error.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-07 15:36:58 +04:00
Ruslan Kuprieiev
4a360f5ed5 service: Ban subdirs in logfile name
There are two reasons to ban subdirs in logfile name.
First, process might be in different namespace, so it is right to give us fd
for work dir, just like we did with images dir. Second, as service might be ran
as root, it is unsafe to give an opportunity to fill any dir with trash.
If you wan't to put logs/stats somwhere else than images_dir, you could
set work_dir_fd.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-04 18:42:48 +04:00
Ruslan Kuprieiev
1775416c4f service: Add work_dir support
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-04 18:24:35 +04:00
Pavel Emelyanov
28ec90b20f service: Implement pre-dump request support
This works as multi-req thing -- caller issues the
pre-dump request, criu serves it and sends result back.
Then service waits for the next request on the same
session, client doesn't have to re-connect back.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-01-30 15:58:48 +04:00
Pavel Emelyanov
0091f81906 service: Start page-server request implementation
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-01-30 15:58:46 +04:00
Pavel Emelyanov
9753501297 rpc: Introduce CLI's --action-script analogue
Service shouldn't call client provided scripts, as it
creates a security issue (client may be unpriviledged,
while the service is).

In order to let caller do what it would normally do with
criu-scripts, make criu notify it about scripts. Caller
then do whatever it needs and responds back.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-01-30 15:58:45 +04:00
Pavel Emelyanov
3587dc1ff7 rpc: Add more stuff to RPC messages
This includes pre-dump and page-server actions and
arguments for memory tracking and page-server.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-01-30 15:58:44 +04:00
Pavel Emelyanov
e7ed1bc31a service: Helper for sending generic RPC errors
We'll need such further.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-01-30 15:58:30 +04:00
Pavel Emelyanov
5226efe328 service: Handle client unexpected disconnection
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-01-11 09:19:10 +04:00
Pavel Emelyanov
4617b77e34 service: Send dump resp in case of dump failure
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-01-11 09:18:52 +04:00
Pavel Emelyanov
48d3b1fc67 service: On check req check for minimal kernel support
When RPC is being requested to check the kernel, it's
enough to check the minimal amount of kernel feature.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-01-04 23:57:11 +04:00
Kir Kolyshkin
94b09be23a cr_service(): don't use pr_perror()
Since sd_listen_fds() doesn't set errno when returning a value > 1,
it doesn't make sense to use pr_perror(). Use pr_err() instead.

While at it, remove the period from the log message.

[v2: fix function names]

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-20 16:08:21 +04:00
Pavel Emelyanov
c79751171f service: Add coment about cr_dump_task() scripts code propagation
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-18 21:24:52 +04:00
Ruslan Kuprieiev
fba791a607 service: fix bug, when root_item isn't initialized
If restore fails on early stage(like no images in directory), then root_item
might be uninitialized, so when we are trying to send response with root_item->pid
criu crashes.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-18 21:18:00 +04:00
Ruslan Kuprieiev
003cfcae19 service: fix bug, when criu reports success on dump fail
cr_dump_tasks() may return not only -1 on fail.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-18 21:17:53 +04:00
Ruslan Kuprieiev
a1e7407397 service: move constants to cr-service-const.h
Such constants as CR_MAX_MSG_SIZE and CR_DEFAULT_SERVICE_ADDRESS are need to be used in both service and lib.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-18 14:26:10 +04:00
Kir Kolyshkin
abd061481b pr_perror(): don't end message with a period
When pr_perror is used, an error message is appended with a comma
and an strerror(errno), so we should not put a period at the end,
otherwise we'll end up with something like this:

	Error: Can't bind.: Permission denied

Found by git grep -w pr_perror | grep '\."'

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-13 13:58:05 +04:00
Kir Kolyshkin
bf5a8e13e1 cr_service(): don't exit(-1)
We should exit(1) on error, exit(0) on success.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-13 13:36:21 +04:00
Kir Kolyshkin
b744883e42 cr_service(): close fd on error
... and don't return -1.

This is a missing part from commit 3477223.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-13 13:36:14 +04:00
Shawn Landden
2e15e4da92 systemd socket activation support
Makes the criu RPC socket socket-activated with
systemd [1], meaning that systemd will create and listen to
the UNIX socket /var/run/criu-srvice.socket
on behalf of criu until a connection comes in, when it will
then pass control of the socket, along with the first connection
over to a newly spawned criu daemon.

This is similar to inetd, but criu stays around after getting
started, listening itsself on the socket.

[1] http://0pointer.de/blog/projects/socket-activation.html

v2: stripped down sd-daemon.[ch]
    moved units to scripts/sd

v3: stripped down further by removing unneeded includes

Signed-off-by: Shawn Landden <shawn@churchofgit.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-12 09:58:50 +04:00
Ruslan Kuprieiev
07e153fc4c service: set success to true before exit
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-05 12:05:46 +04:00
Ruslan Kuprieiev
2e8ff1a22a v2 service: don't send dump response in case of self-dump without leave_running
Currently we have a bug: if no leave_running is set in request, service won't send dump response. We must not send response only if it was a self-dump request and no leave_running option was set.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-02 19:50:44 +04:00
Ruslan Kuprieiev
b49d096016 service: set CHECK type on check response
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-22 09:29:12 +04:00
Pavel Emelyanov
c3b9448cf7 pidfile: Don't push opts.pidfile as write_pidfile arg
opts are criu-wide available.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-20 14:26:41 +04:00
Ruslan Kuprieiev
0b5b2f9906 service: Add support for check request
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-20 14:16:44 +04:00
Ruslan Kuprieiev
b1a197f0b8 page-server/service: do not chdir / when going daemon
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-15 21:38:44 +04:00
Ruslan Kuprieiev
dc80d6f125 log: get rid of LOG_DIR_FD_OFF and opening cwd in log_init()
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-15 21:38:41 +04:00
Ruslan Kuprieiev
127637bc49 image: add dir parameter to open_image_dir()
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-15 21:38:40 +04:00
Andrey Vagin
dd407dd04e hdrs: minor cleaup
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-07 15:13:50 +04:00
Andrey Vagin
4850fd94a8 crtools: move cr_options in a separate header
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-06 18:17:52 +04:00
Andrey Vagin
1cb945cafe crtools: don't include util.h in crtools.h
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-06 15:42:12 +04:00