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

131 Commits

Author SHA1 Message Date
Pavel Emelyanov
5b343b40eb kerndat: Introduce the storage of kernel run-time info
One of such things we use right now is the device for anon shmem
mappings backing. In the furure this can be extended to check for
various kernel features.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-04-15 13:02:09 +04:00
Cyrill Gorcunov
ea438d3f86 proc-parse: Rework error paths
On error paths we don't explicitly close procfile.

CID 996191 (#5 of 6): Resource leak (RESOURCE_LEAK)
22. leaked_storage: Variable "f" going out of scope leaks the storage it points to.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-04-12 20:50:44 +04:00
Andrey Vagin
6a49f82fb6 mount: free all parts of mnt entries
mnt_entry contains a few strings and they should be release too

CID 996198 (#4 of 4): Resource leak (RESOURCE_LEAK)
20. leaked_storage: Variable "pm" going out of scope leaks the storage
it points to.

CID 996190 (#1 of 1): Resource leak (RESOURCE_LEAK)
13. leaked_storage: Variable "new" going out of scope leaks the storage
it points to.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-04-10 01:26:59 +04:00
Andrey Vagin
4ef152447c proc_parse: allocate memory for the terminating null of the string
CID 996207 (#1 of 1): Out-of-bounds access (OVERRUN)
5. alloc_strlen: Allocating insufficient memory for the terminating null of the string.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-04-05 08:18:57 +04:00
Pavel Emelyanov
4d0b24b52a vma: Keep track of lonest vma in list and sum of its lengths
I will have to push some sort of map of pages to dump into parasite.
For this, I need to have estimation of how much memory I'd need for
than in parasite args. These two values will help with it.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-03-01 20:12:33 +04:00
Pavel Emelyanov
b71f9e80be vma: Introduce list-of-vmas object
Right now when we collect list of vmas we need to know the
number of elements in it. In the future I will need to know
more, so it makes sense to create a vmas-list object for it.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-03-01 20:11:51 +04:00
Cyrill Gorcunov
fcb9a9bfb1 cpu: Make cpu routines being per-acrh
They are really depends on CPU we're running on.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-02-18 18:42:08 +04:00
Andrey Vagin
08837c63b1 dump: fix parsing of /proc/locks
is_blocked should be determined for each line independently.

For example:
1: POSIX  ADVISORY  WRITE 1974 fd:01:392012 0 EOF
2: POSIX  ADVISORY  WRITE 1974 fd:01:392011 0 EOF
3: POSIX  ADVISORY  WRITE 1698 fd:01:1196619 0 EOF
4: POSIX  ADVISORY  WRITE 1698 fd:01:1196620 0 EOF
5: POSIX  ADVISORY  WRITE 1698 fd:01:1196621 0 EOF
6: POSIX  ADVISORY  WRITE 1689 fd:01:1429204 0 EOF
7: POSIX  ADVISORY  WRITE 1690 fd:01:1429202 0 EOF
8: POSIX  ADVISORY  WRITE 1690 fd:01:1429201 0 0
8: -> POSIX  ADVISORY  WRITE 1701 fd:01:1429201 0 0
9: POSIX  ADVISORY  WRITE 1688 fd:01:1429206 0 EOF
10: FLOCK  ADVISORY  WRITE 1694 fd:01:1196520 0 EOF
11: POSIX  ADVISORY  WRITE 862 00:0f:12421 0 EOF
12: POSIX  ADVISORY  WRITE 846 00:0f:12377 0 EOF
13: FLOCK  ADVISORY  WRITE 821 00:0f:11378 0 EOF
14: POSIX  ADVISORY  WRITE 459 00:0f:9826 0 EOF
15: POSIX  ADVISORY  WRITE 511 00:0f:10413 0 EOF

Without this patch crtools returns the error:
(00.000613) Error (proc_parse.c:1089): Invalid file lock info!

It's because is_blocked is set in "true" for the line 8 and
it becomes "true" for the line 9.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-02-06 21:05:53 +04:00
Andrey Vagin
ce4c8c1d31 crtools: don't prevent to dump memory mappings on /dev/zero (v2)
Oracle has such mappings.

v2: add check, that a file is a character device

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-17 14:46:33 +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
Alexander Kartashov
3c16edc0bd cr: generalized format strings
This patch replaces the format specifier %ld with PRIx64
in the following places:

* the format string argument of the functions scanf() and printf(),
* in the macros GEN_SYSCTL_*_FUNC.

We need explicit specification of the integer size there.

Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-16 19:20:08 +04:00
Cyrill Gorcunov
d6664eea4a proc-parse: Add alloc_fhandle/free_fhandle helpers
This removes code duplication. There is no strong
need for free_fhandle but I decided to add it to
be consistent with alloc/free handlers.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-16 18:17:46 +04:00
Cyrill Gorcunov
eb8f8c12cd fsnotify: fanotify -- Group objects in image
As Pavel proposed we can refine fanotify image objects
squeezing common part in separate entry. Finally the objects
are grouped as

enum mark_type {
	INODE	= 1;
	MOUNT	= 2;
}

message fanotify_inode_mark_entry {
	required uint64		i_ino		= 1;
	required fh_entry	f_handle	= 2;
}

message fanotify_mount_mark_entry {
	required uint32		mnt_id		= 1;
}

message fanotify_mark_entry {
	required uint32		id		= 1;
	required mark_type	type		= 2;

	required uint32		mflags		= 3;
	required uint32		mask		= 4;
	required uint32		ignored_mask	= 5;
	required uint32		s_dev		= 6;

	optional fanotify_inode_mark_entry ie	= 7;
	optional fanotify_mount_mark_entry me	= 8;
}

This required some tuning in fdinfo parsing and
fsnotify code itself, but result looks good to me.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-15 23:17:57 +04:00
Cyrill Gorcunov
d5927a47f1 proc-parse: Add parsing of fanotify objects
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-15 18:34:49 +04:00
Alexander Kartashov
58064d9b72 cr: use unsigned long type for integers representing a virtual address
This patch is intended to reduce the usage of the macro P() since
integer size mismatches sometimes may be fixed by this type generalization.

Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-14 14:18:59 +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
cf2e6c54c9 cpu: Add code to fetch/test cpuinfo data
This patch add ability to test /proc/cpuinfo data
we're interested in at the moment.

The code provides the following functionality

 - cpu_init, to parse cpuinfo and check if the
   host cpu we're running on is suitable enough
   for FPU checkpoint/restore. If FPU present then
   there must be at least fxsave capability present

 - cpu_set_feature/cpu_has_feature helpers which
   provides to test certain bits and set them where
   needed (we need to set bits when parse cpuinfo)

Note, we reserve space for all cpuinfo bits known
by the kernel at moment, while use only three FPU
related bits for a while. This is done because we might
need to use or find out other features in future.

After all it's just 40 bytes of memory needed to keep
all possible bits.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-12-21 17:35:34 +04:00
Cyrill Gorcunov
fdc56e53f6 proc_parse: Update inotify format
Since fdinfo patches were merged to -mm
tree the output format has been slightly
changed. So update our tool accordingly.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-12-04 19:28:45 +04:00
Cyrill Gorcunov
fe7339570b proc-parse: Inotify files migh have no watchee assigned
Same as eventpoll -- we might have no watchee assigned
but only inotify descriptor created.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-11-28 21:49:57 +04:00
Andrey Vagin
13a7498c2a crtools: add EOL to error messages
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-11-23 16:43:33 +04:00
Pavel Emelyanov
6b2e13fcd9 proc: Fix anon shmem mapping detection
Linux kernel emulates anon-shared mappings by mapping internal
tmpfs file in. We try to detect this by checking that the file
under map is such, but do it with error -- major == 0 check is
wrong, as regular tmpfs file can be such as well as btrfs or
ecryptfs can screw things up.

The only working way of doing this is to get the dev_t of this
internal tmpfs mount.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-11-06 19:07:38 +03: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
Pavel Emelyanov
caca5daa84 proc-parse: Fix mapping address print format
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-11-02 13:53:21 +03:00
Cyrill Gorcunov
cc6af3898e memory: Add pasing of VmFlags
The kernel now supports providing VMA flags via smaps
interface so add pasting of them.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-26 00:16:05 +04:00
Andrey Vagin
df5f44425e proc: use bigger buffer for one line from mountinfo
Before 256 bytes were used for that, it may be not enough.
For example it was not enough for a NFS point on my test system.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-19 15:02:25 +04:00
Pavel Emelyanov
93de669270 proc: Don't report error in case fdinfo for epoll fd is empty
This is normal situation -- eventpoll fd may have no fds attached
thus resulting in empty fdinfo file. Report OK in that case.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 17:55:15 +04:00
Andrey Vagin
0ae2bad0c6 mm: mark a vma as stack, if a value of sp is in it
/proc/PID/maps can contains not up to date information about a stack vma.
A kernel marks a VMA as stack, if thread_struct->usersp is in it,
but usersp is updated, when a process calls a syscall.

This problem is occured, when we try to dump/restore a process in a loop.
When a restorer resumes a process, a restorer vma will be marked as stack.

A thread stack should not be marked as stack, because its vma is mapped
w/o MAP_GROWSDOWN.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-07 18:21:04 +04:00
Pavel Emelyanov
64149b40f2 code: A little but more checkpatch fixes over code
There are more in test/ (and checkpatch.pl crashes in the middle =),
but seem to be all.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-11 22:19:34 +04:00
Pavel Emelyanov
d10ee39f28 code: Fix checkpatch.pl warnings since v0.1
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-11 22:03:11 +04:00
Pavel Emelyanov
cdc4c99835 code: Fix spaced indentation where found
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-11 21:36:03 +04:00
Andrey Vagin
6949a848d3 mount: Add abstraction layer for dumping file systems (v2)
We need to dump content of some fs like binfmt_misc, tmpfs, ... To facilitate
this the existing list of filesystems is turned into an array of structures
with dump and restore callbacks. Each FS may declare them they need.

v2: rework encode/decode_fstype not to do it twice.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-09 16:27:30 +04:00
Pavel Emelyanov
8097a8dc09 signalfd: Add proc fdinfo parsing facility
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-02 12:25:18 +04:00
Pavel Emelyanov
bc21b29ba6 fdinfo: Report miss of required entries on parse
Otherwise dump succeeds but is inconsistent.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-01 07:41:19 +04:00
Pavel Emelyanov
9fc1d6bbeb fdinfo: Make fdinfo.type be an enum
This types specifies a strict set of what is hidden behind
the fd. Thus these numbers should be in the description of
the fdinfo message.

Plus protobuf makes shure nothing else will be there.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-19 10:18:37 +04:00
Cyrill Gorcunov
28638b611c protobuf: Convert inotify data to protobuf engine
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-17 07:25:42 +04:00
Cyrill Gorcunov
fa923ee14e protobuf: Convert eventpoll data to protobuf engine
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-17 07:25:40 +04:00
Cyrill Gorcunov
ca21674573 protobuf: Convert eventfd data to protobuf engine
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-17 07:24:54 +04:00
Pavel Emelyanov
feb6624ddf inotify: Wire into and use Generic fdinfo parsing engine
With this the code looks clearer and finally a ground for "check" code is prepared.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-11 09:35:36 +04:00
Pavel Emelyanov
0b9d1d970f event*: Move proc parsing stuff to proc_parse
And prepare it for inotify (oh my...)

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-11 09:22:38 +04:00
Pavel Emelyanov
fc416d8694 mount: Build mount points tree out of a plain list
Build a tree of mountpoins that can be (u)mounted in a straight
(forward or backward) order without EBUSY errors.

The tree is built in two steps -- first create hierarchy based
on mount iDs. Next -- resort siblings in the path depth order.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-06-27 20:57:34 +04:00
Pavel Emelyanov
e0cb53a19f mount: Rename struct proc_mountinfo into mount_info
This structure will be used on restore and will be created
from the image, thus the name proc_ is not suitable.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-06-27 20:57:30 +04:00
Pavel Emelyanov
b580345518 mount: Allocate mountinfo strings dynamically
On the restore path this structure will be used and it
will be better to have them char * rather than char[64].

When scanning proc use the %ms specifier for this.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-06-27 20:57:29 +04:00
Stanislav Kinsbursky
41195598cf parasite: remove excessive header deps from parasite.h and friends
The task is not complete - this is just a part of what have to be done. I.e.
looks like a lot of excessive deps can be fixed.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-30 12:50:18 +04:00
Pavel Emelyanov
3b21f72766 mount: Full parse of proc mountinfo file
The proc_parse file turns into a strange pile of homebrew
scanf/fgets/strtok/strchr/etc. combination. I don't like it :(

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-13 08:34:31 +04:00
Pavel Emelyanov
f986994272 proc: Move proc string parse into separate fn
We'll have to parse it all and the format is not scanf
friendly, so it's simpler to have it in a separate fn.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-13 08:34:26 +04:00
Pavel Emelyanov
5e593e9b57 proc: Sanitize mountinfo parsing
Make the proc_mountinfo obtaned after parse form a single linked list.
That's much easier to handle and doesn't have an artificial limitation
of 64 items...

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-13 08:34:16 +04:00
Pavel Emelyanov
90d0a6a0de mount: Collect mount root as well when parsing proc
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-12 03:45:47 +04:00
Pavel Emelyanov
79da538469 mount: Rename proc_mountinfo mnt_root to mountpoint
What is stored there is the path to mountpoint. The root
is the field previously named "parent root".

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-12 03:40:08 +04:00
Cyrill Gorcunov
62ee701c89 Use /proc/pid/smaps for VMA parsing v2
This allows us to detect nonlinear mappings.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-11 17:41:05 +04:00
Cyrill Gorcunov
9ea069d2c9 proc: Add parse_mountinfo helper
To restore inotify we need to know the
mount point device numbers, so this helper
parses /proc/pid/mountinfo file for that.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-04 14:00:28 +04:00