2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-28 21:07:43 +00:00

446 Commits

Author SHA1 Message Date
Alexander Kartashov
b97e24e3fb cr: introduced the functions decode_pointer() and encode_pointer()
These functions are designated to convert a native pointer
to uint64_t used to store a virtual address in protobuf messages
and vice versa in a machine-independent way.

Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-18 11:41:43 +04:00
Qiang Huang
95801808aa crtools: dump flock&posix file locks
Dump file locks' necessary entries to the image, we only support flock and
posix file lock right now.

Changelog since the initial version:
We got file lock info from global list, so the dump_task_file_locks
can be much simpler.

Originally-signed-off-by: Zheng Gu <cengku.gu@huawei.com>
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-17 14:42:41 +04:00
Qiang Huang
286801d4c1 crtools: collect and check file locks
We collect all file locks to a golbal list, so we can use them easily
in dump_one_task. For optimizaton, we only collect file locks hold by
tasks in the pstree.

Thanks to the ptrace-seize machanism, we can aviod the blocked file lock
issue, makes the work simpler.

Right now, the check handles only one situation:
-- Dumping tasks with file locks hold without the -l option.

This covers for the most part. But we still need some more work to make
it perfect robust in the future.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-17 14:42:07 +04:00
Cyrill Gorcunov
962af52932 fsnotify: Add dumping of fanotify objects
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-15 18:34:50 +04:00
Cyrill Gorcunov
05bb44960f dump: Collect mount information on dump
For fanotify dumping we need to find mount points the path
lay on, moreover we save a mount point device number in the
image, thus collect mount point information on dump stage.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-15 18:34:48 +04:00
Cyrill Gorcunov
b724096f0f fsnotify: Rename inotify files to fsnotify
We will be handling both inotify and fanotify
objects here thus to make less confusion rename
the files to fsnotify.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-15 18:34:26 +04:00
Pavel Emelyanov
6773090014 core: introduced the macro CORE_THREAD_INFO to access the machine-specific part of CoreEntry
This is the merge and a slight rework (no TI_SP macro) of Alexander's patches
about the subj.

Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-14 17:19:06 +04:00
Alexander Kartashov
9209d9eb21 core: introduced the macro CORE_ENTRY__MARCH to represent the target architecture
Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-14 14:17:04 +04:00
Alexander Kartashov
b84059a608 multiarch: removed target architecture checks from the following files:
* include/image.h,
* include/syscall-types.h,
* include/restorer.h,
* parasite-syscall.c,
* cr-dump.c,
* cr-show.c,
* pie/parasite.c.

Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-14 13:48:07 +04:00
Andrey Vagin
979eb2a179 restore: restore pocesses which share one fdtable (v5)
Currenly crtools supports a case when a child shared a fd table
with parent.

Here is only two interesting things.
* Service descriptors should be cloned for each process
  who shared one fd table.
* One task should restore files and other tasks should sleep in this
* time.

v2: * allocate fdt_lock from shared memory
    * don't wait a child, if it doesn't share fdtable
v3: * don't move ids on the pstree image
v4: * save ids in a separate image
    * save fdinfo per id instead of pid
v5: fix alignment of service_fd_id

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-12 00:54:46 +04:00
Andrey Vagin
d50c786c7e files: dump fdinfo per files_id instead of pid
A few processes can share one fdtable.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-12 00:54:44 +04:00
Andrey Vagin
0ec10e4e16 dump: save ids on pstree_item
It will be used for determing which resources are shared

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-12 00:54:40 +04:00
Andrey Vagin
20b5ed916f crtools: put kobj-ids into separate image file (v2)
It is read together with pstree items for checking what kind of
resources should be shared. Core is too big for reading it in
this place.

v2: fix check_core

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-12 00:54:39 +04:00
Andrey Vagin
0fc129a121 files: pass a file descriptor on an fdinfo image instead of cr_fdset
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>
2013-01-11 14:47:09 +04:00
Pavel Emelyanov
748be83181 cr: Support rlimits
Dump the with "new" prlimit syscall that works on arbitrary pid.

Restore is done in restorer _after_ mappings mixup and _before_
caps drop to make it set any max value.

The RLIM_INFINITY is handled explicitly to help future 64<->32
bits migration.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-10 20:08:38 +04:00
Pavel Emelyanov
d703f8260e fs: Support umask dump/restore
This one is bound to task's fs info (with cwd and root)
thus put it in the fs.img file.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-10 12:48:31 +03:00
Pavel Emelyanov
f787f922e2 dump: Pass CoreEntry into thread-dumping routine
The number of arguments used to carry data via them is too
big already. Just fill the required core fields inside.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-09 18:32:56 +03:00
Pavel Emelyanov
e129ae26c4 dump: Pass whole struct pid into thread dumping routine
And do "get real pid, report virtual one" inside.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-09 18:27:54 +03:00
Alexander Kartashov
e1e2346880 cr: Introduce stubs for tls dump/restore
Leave them empty for x86, will be used on ARM.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-09 19:01:22 +04:00
Alexander Kartashov
7b7a08dde5 auxv: save and restore AUXV's in a machine-independent way.
The size of an auxv is the machine pointer but a 64-bit integer is reserved
in a MmEntry protobuf message to store an auxv. Moreover the number of auxv's
varies from one architecture to another. So the following is proposed
to alleviate the issue.

* Introduced the type auxv_t representing a machine-pointer sized integer.

* The size of auxv array is extracted from a MmEntry message instead of using
  the value of the macro AT_VECTOR_SIZE.

Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-09 17:40:33 +04:00
Alexander Kartashov
f35661d164 cr-dump.c: moved the function core_free_entry() into the file arch/x86/crtools.c.
Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-09 17:27:55 +04:00
Alexander Kartashov
d2dfdeffd9 cr-dump.c: moved thread core initialization into the function arch_alloc_thread_info().
Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-09 17:27:53 +04:00
Alexander Kartashov
1c8be2b945 cr-dump.c: moved the routine get_task_regs() to the file arch/x86/crtools.c.
Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-09 17:27:49 +04:00
Alexander Kartashov
6f61488f21 x86: moved x86-specific files into the directory arch/x86.
* 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>
2013-01-09 17:02:47 +04:00
Cyrill Gorcunov
c1f7ab2150 checkpoint: Add dumping of FPU state
The dumping of FPU state is done with help of ptrace
facility. There are two cases which we need to handle
depending on which features are available on host machine

1) The dump via ptrace(PTRACE_GETFPREGS ...)

   In this case the kernel will use fxsave approach
   inside the kenrel and provides us back the data
   encoded in i387_fxsave_struct format.

2) The dump via ptrace(PTRACE_GETREGSET ...)

   In this case the kernel will use xsave approach
   inside the kernel and provides us back the data
   encoded in xsave_struct format.

In any case we decode data and save it in protobuf format.
This is why core.proto file has been extended to keep new
entries.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-12-21 17:35:39 +04:00
Cyrill Gorcunov
8b93676d90 dump: Move assign_reg/assign_array closer to place where they are used
And don't forget to undef them once they are not needed.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-12-21 17:35:38 +04:00
Cyrill Gorcunov
1256c390b6 dump: Drop FPU padding allocation
Actually it was never used, just drop it.
Because of backward compatibility problem we
can't just zap it in protofile.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-12-21 17:35:37 +04:00
Cyrill Gorcunov
41ebf5c377 cpu: Add testing if host cpu is suitable to FPU c/r
The cpu we're running on must at least support fxsave feature.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-12-21 17:35:36 +04:00
Andrey Vagin
2701316b46 dump: remove debug messages
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-12-20 16:08:12 +04:00
Pavel Emelyanov
4ced9531e6 files: Open-code MAKE_GEN_ID macro into its single caller
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-12-18 21:29:48 +03:00
Pavel Emelyanov
9428f3a9a2 dump: Make collect_mappings non static
Will be used by other code.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-12-17 22:50:06 +03:00
Pavel Emelyanov
1a7c7d0404 fd: Consolidate . and .. checks in various readdir callers
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-11-29 21:12:51 +03:00
Andrey Vagin
20e8eefb01 cr-dump: show virtual PID-s in a log file
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-11-27 19:20:20 +04:00
Cyrill Gorcunov
5da22b01fe dump: Fix message in thread dumping
And add missing new line in message.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-11-12 17:42:59 +04:00
Cyrill Gorcunov
7266efdec5 dump: Show blocked signals when dumping
For debug purpose.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-11-12 17:42:58 +04:00
Cyrill Gorcunov
5b7e3b8dae dump: Checkpoint per-thread blocked signals
I've moved dump_thread helper a bit lower in file
since I've to call for find_thread_state helper.
After all this groups all thread related functions
in one slab.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-11-12 17:42:56 +04:00
Cyrill Gorcunov
f107e8e9e2 dump: Save and remove per-thread argumens in parasite
This patch starts using parasite_init_threads_seized and
parasite_fini_threads_seized helpers to save per-thread
data in parasite and remove it on cure procedure.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-11-12 17:42:55 +04:00
Cyrill Gorcunov
616b96421e parasite: Rework init/fini to reserve/free space for per-thread data
The per-thread information requires own space in parasite data.
In particular we will keep the blocked signals bound to thread
pids.

For this sake the caller need to provide the parasite how many
threads will be used to calculate space.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-11-12 17:42:48 +04:00
Pavel Emelyanov
d4735a22fa packet: Support mmap-ing of packet sockets
Three parts.

Proc: open of map_files' link doesn't work on sockets. We fstatat
it and check that it's a socket (it will be packet), then save
the socket inode on vma_area.

Dump: we resolve socket inode to socket id and save it on vma.
We use id, not inode, since on restore we'll have to mmap some
opened file, not just abstract socket with inode.

Restore: when reading vma-s we just need to find out on what fd
the respective packet socket is opened (i.e. -- no map-and-close
sockets supported by now) and dup() it to let restorer mmap it
back.

All this make it possible to c/r the tcpdump tool!

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-11-02 16:00:18 +03:00
Cyrill Gorcunov
b1f1154c8a auxv: Use real size of the auxv vector
The size of vector depends on the kernel config
so use the real size of a vector dumped. Otherwise
we might fail on restore.

Reported-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-29 19:54:12 +04:00
Cyrill Gorcunov
f0606bc8d9 tty: Introduce deferred checking of tty sids
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>
2012-10-29 13:37:34 +04:00
Pavel Emelyanov
aa731ee1d7 core: Support task scheduler policies and priorities
No magic here, just fetch info using getpriority and sched_getxxx calls.
Good news is that the mentioned syscalls take pid as argument and do work
with it, i.e. -- no need in parasite help here.

Restore is splitted into prep -- copy sched bits from image on restorer
args -- and the restore itself. It's done to avoid restoring tasks info
with IDLE priority ;) To make restorer not-fail sched bits are validated
for sanity on prep stage.

Minimal sanity test is also there.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-17 00:23:25 +04:00
Cyrill Gorcunov
2b816a593a dump: Make struct fd_parms to carry @parasite_ctl pointer
Some file-type specific parameters can be fetched with
parasite code only, so lets carry parasite control block
pointer in struct fd_parms.

This is a bit ugly but requires less code to touch and
enough for now. In long terms we need some more generalized
routine/hooks which would depends on file type.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-15 23:42:50 +04:00
Pavel Emelyanov
699a33e1b9 creds: Dump creds with the help of parasite
Currently move there the secbits dumping, which is not dumped
via misc-dumping command. This patch is required to support
per-task groups dumping (setgroups/getgroups) -- we'll have to
drain the groups from parasite.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-11 17:06:58 +04:00
Cyrill Gorcunov
3ef0d9735b dump: No need to init root_item->sibling
It's already done in alloc_pstree_item() by
recently merged commit.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-08 19:00:11 +04:00
Cyrill Gorcunov
17a1548a5b pstree: Rename @list member to @sibling
To be close to the kernel naming.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-08 18:59:26 +04:00
Cyrill Gorcunov
1de8adbf71 tty: Verify active pairs once dump complete
We don't support yet detached terminals migration,
so fail early if we can't proceed.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-20 13:35:39 +04:00
Andrey Vagin
3957a9a69a cr-dump: lock network before dump and unlock in case of errors
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-17 20:05:55 +04:00
Cyrill Gorcunov
89a7a45d37 tty: Add checkpoint/restore for unix terminals v6
Usually the PTYs represent a pair of links -- master peer and slave
peer. Master peer must be opened before slave. Internally, when kernel
creates master peer it also generates a slave interface in a form of
/dev/pts/N, where N is that named pty "index". Master/slave connection
unambiguously identified by this index.

Still, one master can carry multiple slaves -- for example a user opens
one master via /dev/ptmx and appropriate /dev/pts/N in sequence.
The result will be the following

master
`- slave 1
`- slave 2

both slave will have same master index but different file descriptors.
Still inside the kernel pty parameters are same for both slaves. Thus
only one slave parameters should be restored, there is no need to carry
all parameters for every slave peer we've found.

Not yet addressed problems:

- At moment of restore the master peer might be already closed for
  any reason so to resolve such problem we need to open a fake master
  peer with proper index and hook a slave on it, then we close
  master peer.

- Need to figure out how to deal with ttys which have some
  data in buffers not yet flushed, at moment this data will
  be simply lost during c/r

- Need to restore control terminals

- Need to fetch tty flags such as exclusive/packet-mode,
  this can't be done without kernel patching

[ avagin@:
   - ideas on contol terminals restore
   - overall code redesign and simplification
]

v4:
 - drop redundant pid from dump_chrdev
 - make sure optional fown is passed on regular ptys
 - add a comments about zeroifying termios
 - get rid of redundant empty line in files.c

v5 (by avagin@):
 - complete rework of tty image format, now we have
   two files -- tty.img and tty-info.img. The idea
   behind to reduce data being stored.

v6 (by xemul@):
 - packet mode should be set to true in image,
   until properly fetched from the kernel
 - verify image data on retrieval

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
CC: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:00:54 +04:00
Andrey Vagin
8a7dc1da8f dump: dump zombies from another PID namespace
The problem is to get a virtual pid for zombies.
This code gets two list of children from current and target pidns.
Then it removes alive task from the second list and dumps remaining zombies.

A procfs from a target pidns is needed for dumping zombies,
crtools gets it from parasite code.

v2: Fix comment and get proc fd from a root task

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-07 19:17:18 +04:00