2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 09:58:09 +00:00

48 Commits

Author SHA1 Message Date
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
Andrey Vagin
f3e8977c73 proc: add a static buffer to prevent segv (v3)
A few of our functions use buffer and string functions.
All these functions require that a string contains '\0' at the end.
Before this patch we didn't guarantee that.

I've seen segmentation fault in parse_pid_stat_small.

v2: simplify code
v3: remove assignment, because it's redundant and a size of object file
become bigger.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-03 13:09:20 +04:00
Cyrill Gorcunov
06986dfe50 proc: Fix parsing of stack string
Kernel 3.4-rc4 has two formats for stack
"[stack]" and "[stack:%d]" (for threads)
so adopt our parsing routine for both.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-26 00:55:20 +04:00
Konstantin Khlebnikov
bef7092834 Replace printf format "0x%x" with "%#x"
printf() has standard flag for adding "0x" prefix before hexadecimal integer.

MOD='[-+]\?[0-9]*.\?[0-9]*[lL]*'
git grep -l "0x%${MOD}x" | xargs -n1 sed -e "s/0x%\(${MOD}\)x/%#\1x/g" -i

Signed-off-by:    Konstantin Khlebnikov <khlebnikov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-24 15:20:24 +04:00
Cyrill Gorcunov
5d03b52fd3 proc_parse: Fix task name parsing
The task name may include spaces so %s
scanning format will fail (in particular
dumping rsyslogd fails since thread has
name "rs:main Q:Reg"). Fix it.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-17 20:11:21 +04:00
Kinsbursky Stanislav
35eedb5f1f output: add "0x" to hex prints using sed
Command below was executed several times:

sed 's/\(pr_.*[^%,x,X]\)\(\%[0-9,l,L]*x\)/\10x\2/g' -i *.c

Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-16 12:33:35 +04:00
Pavel Emelyanov
6ed9f87269 proc: Make small stat parsing read pgid and sid
They are just two next in this file, so extend. This is
required for pgid/sid early read, see next patches for
details.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-11 22:09:12 +04:00
Andrey Vagin
37a6c1fc88 mm: move shmid to vma_entry (v2)
It will be used to restore shared mappings

v2: clean up

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-21 10:56:31 +04:00
Pavel Emelyanov
caf860c2ef proc parse: Small sanitation of maps parsing
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-17 01:22:18 +04:00
Pavel Emelyanov
7b7f09e4f0 sanitize vma types parsing
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-04 17:06:36 +04:00
Pavel Emelyanov
fc225709b0 proc: Make parse_maps return the amount of them found
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-03-02 21:31:35 +04:00
Pavel Emelyanov
199e8d8248 dump: Check for pids reuse at suspend
While we try to seize task it can die and give its pid to
somebody else. This can break pstree consistency. Check for
parent being valid after task is seized.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-03-01 19:31:20 +04:00
Kir Kolyshkin
447388d79b open_proc() and friends: hide pid_dir
This patch tries to introduce lazy and hidden pid_dir support,
meaning one don't have to worry about pid_dir but the optimization
is still there.

The patch relies on the fact that we work with many /proc/pid files for
one pid, then for another pid and so on, i.e. not in a random manner.

The idea is when we call open_proc() with a new pid for the first time,
the appropriate /proc/PID directory is opened and its fd is stored.
Next call to open_proc() with the same PID only need to check that
the PID is not changed. In case PID is changed, we close the old one
and open/store a new one.

Now the code using open_proc() and friends:
- does not need to carry proc_pid around, pid is enough
- does not need to call open_pid_proc()

The only thing that can't be done in that "lazy" mode is closing the last
PID fd, thus close_pid_proc().

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-02-17 16:46:25 +04:00
Kir Kolyshkin
5661d806cb Move error reporting to inside open_proc and friends
...and make it correctly print the file name we were unable to open.
Also, error from fdopen[dir]() is now reported with file name as well.

Note that open_proc() and friends need to be macros in order for
pr_perror() to show actual file name and line number where error occured.

Historical note: the original version of this patch was way more radical,
changing openat() to open() and thus removing pid_dir (replacing with pid
when needed) and open_proc_dir(), changing openat() to open(). The word
from Pavel is he wants to keep the openat/pid_dir optimization because
it saves two dentry lookups in kernel code for each open(). Because of
this optimization (and desire to print correct file name in case
of error) we have to carry both pid and pid_dir everywhere.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-02-17 16:46:25 +04:00
Kinsbursky Stanislav
b3cfe73556 dump: support SYSV IPC vma
This patch introduces the following changes:

1) introduces new flag VMA_AREA_SYSVIPC to mark corresponding vma entries.
2) enhance task /proc/<pid>/maps parsing to obtain first 5 letters of mapped
   file. If device major file belong to ins equal to 0 (tmpfs) and it's name
   starts with "/SYSV", then this mapping is considered as SYSV IPC and
   corresponding vma entry status is updated with VMA_AREA_SYSVIPC flag.
3) omit dumping of mapping pages for SYSV IPC vmas.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-02-15 13:30:34 +04:00
Cyrill Gorcunov
e61605169f ctrools: Rewrite task/threads stopping engine is back
This commit brings the former "Rewrite task/threads stopping engine"
commit back. Handling it separately is too complex so better try
to handle it in-place.

Note some tests might fault, it's expected.
---

Stopping tasks with STOP and proceeding with SEIZE is actually excessive --
the SEIZE if enough. Moreover, just killing a task with STOP is also racy,
since task should be given some time to come to sleep before its proc
can be parsed.

Rewrite all this code to SEIZE task and all its threads from the very beginning.

With this we can distinguish stopped task state and migrate it properly (not
supported now, need to implement).

This thing however has one BIG problem -- after we SEIZE-d a task we should
seize
it's threads, but we should do it in a loop -- reading /proc/pid/task and
seizing
them again and again, until the contents of this dir stops changing (not done
now).

Besides, after we seized a task and all its threads we cannot scan it's children
list once -- task can get reparented to init and any task's child can call clone
with CLONE_PARENT flag thus repopulating the children list of the already seized
task (not done also)

This patch is ugly, yes, but splitting it doesn't help to review it much, sorry
:(

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-02-01 19:49:28 +04:00
Cyrill Gorcunov
63b88720a3 Revert "ctrools: Rewrite task/threads stopping engine"
This reverts commit 6da51eee3f6cd7aca9dd88275844e73fb78b767b.

It breaks transition/file_read test case
2012-02-01 19:27:28 +04:00
Pavel Emelyanov
6da51eee3f ctrools: Rewrite task/threads stopping engine
Stopping tasks with STOP and proceeding with SEIZE is actually excessive --
the SEIZE if enough. Moreover, just killing a task with STOP is also racy,
since task should be given some time to come to sleep before its proc
can be parsed.

Rewrite all this code to SEIZE task and all its threads from the very beginning.

With this we can distinguish stopped task state and migrate it properly (not
supported now, need to implement).

This thing however has one BIG problem -- after we SEIZE-d a task we should seize
it's threads, but we should do it in a loop -- reading /proc/pid/task and seizing
them again and again, until the contents of this dir stops changing (not done now).

Besides, after we seized a task and all its threads we cannot scan it's children
list once -- task can get reparented to init and any task's child can call clone
with CLONE_PARENT flag thus repopulating the children list of the already seized
task (not done also)

This patch is ugly, yes, but splitting it doesn't help to review it much, sorry :(

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-02-01 17:29:13 +04:00
Kir Kolyshkin
11f2ce03da parse_pid_stat(): use pr_err()
We do not want to use pr_perror() here, because

1. fscanf only sets errno in case it returns EOF
2. we are not really interested in errno value

So use pr_err() instead.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-02-01 02:55:16 +04:00
Kir Kolyshkin
1408ead858 Assorted trivial message fixes
* kid -> child
* First letter should be uppercase
* Misc typos in messages and comments

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-02-01 02:55:16 +04:00
Kir Kolyshkin
b44cd5885c proc_parse.c: fix printf format warnings
proc_parse.c: In function ‘parse_maps’:
proc_parse.c:75:6: error: format ‘%Lu’ expects type ‘long long unsigned int’, but argument 5 has type ‘u64’
proc_parse.c:118:5: error: format ‘%Lu’ expects type ‘long long unsigned int’, but argument 5 has type ‘u64’

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-31 15:56:56 +04:00
Kir Kolyshkin
0b237ae9f2 pr_perror(): print error at the end of line
This is a standard convention to print error message (i.e. strerror(errno))
at the end of line, like this:

        Cannot remove file: Permission denied

So pr_perror is fixed to follow this convention (using GNU extension
%m helps a lot here). Unfortunately, due to this we have to make
pr_perror() print a new line character, too, so we had to strip it
from the all pr_perror() invocations.

That (appending a newline) also makes pr_perror() a black sheep
in the herd of pr_* helpers, but what can we do? Worst case scenario
is an extra newline after an error message, not too harmful.

An alternative approach (stripping the newline from the passed format
string and re-adding it) was discussed thoroughly, and it was decided
that such a hack looks a bit too dirty.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-31 15:49:15 +04:00
Pavel Emelyanov
f382d2a376 proc_parse: Routine for reading creds from /proc/pid/status
All the IDs and caps are in there. Just read them for future use.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-30 13:00:18 +04:00
Cyrill Gorcunov
faf41eb5b2 dump: Dump cmdline and envirion parameters
It implies update to kernel side as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-01-24 18:01:07 +04:00
Pavel Emelyanov
21bbfee919 proc: Read exit code from /proc/pid/stat
Requires patch #14 (for kernel). Also check for number of entries read be
at least required, not exactly equal for forward compatibility.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-23 01:43:28 +04:00
Cyrill Gorcunov
f80694deed proc_pase: Make sure we may scan up to 15 symbols in name
And do not use strcpy, better to stick with strncpy.

Moreover, to be on a safe side make proc internal
buffer big enough even for "(%16s)" format, it's
hardly possible that the kernel ever change stat
format but just to be on a safe side.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-15 22:37:17 +04:00
Cyrill Gorcunov
05c142c0f5 proc_parse: Make sure the fields in parsing stream do match
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-15 22:36:40 +04:00
Cyrill Gorcunov
04a6f0449d proc_parse: Zap ending ')' in name
Repored-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-15 01:41:58 +04:00
Cyrill Gorcunov
acfd1d7fc4 crtools: Fix command line parsing in parse_pid_stat
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-14 02:00:59 +04:00
Cyrill Gorcunov
1e073d05eb crtools: A few style update on proc_parse
No func changes.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-14 02:00:48 +04:00
Pavel Emelyanov
3202d72f85 crtools: Parse /proc/pid/stat in a more readable way
We will later need other fields of this file, so let's parse it right
now in a way, that allows to easily get new fields.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-14 02:00:38 +04:00
Pavel Emelyanov
12d4c85410 crtools: Move proc parsing routines to one file
Start with /proc/pid/maps parser

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