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

219 Commits

Author SHA1 Message Date
Andrey Vagin
363812c9b9 restore: optimize restorer_get_vma_hint
It's an O(n) algorithm.

Now we iterate both lists simultaneously to find a hole.

[xemul: Discussion making the patch more understandable:

Cyrill:

	If s_vma is the last one on self_vma_list you could break immediately, no?

	And the snippet I somehow miss is -- how the situation handled when

		      hole
		    a      b
	source |----|      |-----|
	target   |----|      |-----|
		      c      d

	the hole fits the requested size but the hole is shifted
	in target, so that you've

	prev_vma_end = a

	and then you find that a - d > vma_len and return a
	as start address for new mapping while finally it
	might intersect with address c.

	Or I miss something obvious?

Andrey:

	Look at "continue" one more time.
	prev_vma_end is returned only if both condition are true

	if (prev_vma_end + vma_len > s_vma->vma.start) {
	....
	if (prev_vma_end + vma_len > t_vma->vma.start) {
	...

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Looks-good-to: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-09 10:31:00 +04:00
Andrey Vagin
fa11d76cab restore: check that a restorer vma doesn't intersect with target vma-s
[ xemul: The fix effectively is -- stop scanning the 2nd vma list
         once we see, that the hint's end hits the next vma ]

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-09 10:27:44 +04:00
Pavel Emelyanov
b386751697 sockets: Rework unix sockets onto fdinfo scheme
This is a big change, yes. Dump unix sockets in the same manner
as all the other files are done now. A few notes however.

1. We explicitly drop names for connected stream sockets. This is
   done to avoid conflicts with names -- accepted sockets share their
   names with the listening parent. This can be done later by binding
   a socket to a name, them renaming it to some temporary uniq one
   and at the very very end renaming some back to original.

2. Interconnected sockets are restored via socketpair() call. This is
   correct, but names are dropped. Need to bind() sockets after this
   (yes, this can be done), but for this we need to implement the trick
   with renames described before.

3. FD for socket queues is constantly re-opened not to resolve fd
   conflicts. Need to use service fds engine for this later.

4. Some code cleanup is still required, yes (will follow shortly).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-06 19:27:08 +04:00
Andrey Vagin
4f2bd37704 pipes: add functions for collecting pipes
pipe_entry is encapsulated in pipe_info.
All pipe_info-s connects in the list pipes.
All pipe_info-s with the same piep_id connects to pipe_list,
it a circular list without a defined head.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-05 21:22:16 +04:00
Andrey Vagin
382ebc3063 pipe: remove old code for restoring pipes
[ xemul: I don't know how to make this with incremental changes either,
         and just go with it :( ]

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-05 21:17:11 +04:00
Pavel Emelyanov
c40e3201f2 rst: Open thread core images without -nocheck
These are image files that weren't yet opened, thus should be
opened with proper checks.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-05 15:42:48 +04:00
Pavel Emelyanov
7570fbbf6a rst: Read pstree image once
Collect pstree_item-s on restore in big list. This lets
us not lseek this file on restore and simplifies the code
a little.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-05 15:34:31 +04:00
Pavel Emelyanov
a541fa8df3 rst: Remove unused pstree_pid
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-05 14:23:21 +04:00
Pavel Emelyanov
3b35d0531a rst: Use collected target vmas list in restorer_get_vma_hint
It uses the vma image right now, but the image is already sucked in.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-05 14:10:11 +04:00
Cyrill Gorcunov
d7961998bd lock: Restore ability to abort on futex waiting
In commit 71cc2733a79efba65d3466f784b19d17805cf50d
I occasionally dropped the ability to abort on waiting
(because we used signed -1 value to inform waiters that
something is wrong and waiting should be aborted, but
the type was changed to unsigned one and as result
this condition never triggers).

So to resolve it futex_abort_and_wake() is added and
should be used explicitly where appropriate instead
if signess hack.

Reported-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-05 14:07:39 +04:00
Pavel Emelyanov
2a33c4d5dc mem: Remove zero page from the end of mem image files
This was required when pages were stored in elf files for
exec. Now we can stop reading it on eof.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-05 14:07:31 +04:00
Pavel Emelyanov
d1c9f0d71c files: Show collected regfiles fd tree
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-05 12:48:57 +04:00
Pavel Emelyanov
54c1979c84 unix: Collect unix sockets early on restore
Same as prev 2 patches now for the unix sockets. They are still in per-pid image files, but
this is going to change soon (I hope).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-03 00:58:41 +04:00
Pavel Emelyanov
94a11df0a1 inet: Collect inet sockets early on restore
Same as previous patch -- pull inet sockets in and store in the hash for the same reasons.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-03 00:54:52 +04:00
Pavel Emelyanov
84678526ac files: Read regfiles image in early on restore
Instread of re-reading this image again and again on every fd restore, pull the
reg-files.img in early and store the entries in a hash. This will simplify the
further fd restoring fixes and will allow for dump/restore via a stream (socket).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-03 00:50:50 +04:00
Cyrill Gorcunov
f964951a14 restorer: Fix bug in address computation of thread args area
It's wrong to treat restore_thread_exec_start as arguments
area (I managed to overlook this problem in commit
014841825acb14a1d695569b9fe3575f5de6442b) it's rather
a function start address.

The thread arguments area allocated dynamically after the
restorer blob itself.

We didn't hit any problems earlier simply because there
were a few bytes owerwritten in function prologue.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
CC: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-02 22:38:29 +04:00
Pavel Emelyanov
2b175282fb restore: Don't write to vma image on restore
This is not good to update images while restoring.

Thus, read vma_entry-es once into a list, put opened (when required) fds
in there and make restorer walk the entries in mem, not those read from
the image file.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-27 18:42:18 +04:00
Pavel Emelyanov
65db28eafc restore: Helper for vmas list remap and copy
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-27 18:42:12 +04:00
Pavel Emelyanov
7f0b083a00 restorer: Round size of area with self vmas up to page size
These chunks of memry, which transit into restorer code gets unmapped one-by-one and thus each of them
should be page-aligned.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-27 15:32:45 +04:00
Pavel Emelyanov
ad1aed62a0 img: Fixup seeks
There's no need in seeking file on core dump.
Fix explicit sizeof(u32)-s in restore seeks.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-27 15:16:09 +04:00
Cyrill Gorcunov
71cc2733a7 lock: Add own type and helpers for mutexes
To be consistent. Mutexes are futex based but have
own semantics so better to be able to distinguish
the types.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrey Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-27 11:37:50 +04:00
Cyrill Gorcunov
dc848fae7a lock: Introduce futex_t and appropriate helpers
Instead of open-coded u32 variables poking lets use
futex_t type and appropriate helpers where needed.

This should increase readability.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrey Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-27 11:37:27 +04:00
Stanislav Kinsbursky
b82edc9fdf crtools: dump pstree to image file without pid number
Pid number is redundant - this file is one for the whole tree.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-26 15:46:07 +04:00
Pavel Emelyanov
7a451ff108 rst: Open exe link fd early
Open the exec link at fd restore stage as yet another service fd,
then pass it to restover via args and just call prctl on it.

This is good for several reasons -- the amount of code required for
this is less and opening files should better happen before we switch
to restorer (opening will be complex and it's MUCH easier to open all
we need in one place).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-24 15:30:20 +04:00
Pavel Emelyanov
d5f83530bd rst: Cleanup pstree walkthrough
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-22 21:06:41 +04:00
Pavel Emelyanov
3ad95b3706 shm: Fix one task shmem remaps restore
Since the collect_shmems updates start address for vmas, for
two shared mappings in one task we'll try to dup() the 1st
restoration attempt, since the si's start will be set to the
2nd one, which is not yet restored.

Thus we should map-and-open the first one being restored, not
the one with matched address and dup() all the rest.

[avagin@: There's no such thing, since the collect stage checks
for pid being less _or_ _equal_ and this only the first vma's start
will be saved. But anyway, this makes it more obvious.]

Acked-by: Andrey Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-22 14:01:49 +04:00
Pavel Emelyanov
8e47df998c shm: Sanitize ret val checks in shmem_wait_and_open
Acked-by: Andrey Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-22 14:00:53 +04:00
Pavel Emelyanov
6faac3a39e rst: Factor out vma fd fixup
Just make the fixup_vma_fds read and write vma images and
those called by it provide and fd for this.

Acked-by: Andrey Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-22 14:00:27 +04:00
Pavel Emelyanov
29e07fa24f rst: Remove extra calls when fixing up maps fds
Acked-by: Andrey Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-22 14:00:09 +04:00
Pavel Emelyanov
8639776154 shm: Use read_img in fixup_vma_fds
Acked-by: Andrey Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-22 13:59:45 +04:00
Pavel Emelyanov
97a1d8bb1c mm: Dump vmas into separate image file
The core image now contains only core per-task stuff.
The new file resurrects Tula magic number removed earlier.

Acked-by: Andrey Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-21 18:17:12 +04:00
Andrey Vagin
c3051512f3 crtools: delete CORE_OUT
It's a rudiment from old times, when restore worked via ececve.
Now we modify the core file in place to fixup vma-s.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-21 11:06:10 +04:00
Andrey Vagin
e869c16df5 mm: rework of dumping shared memory
vma_entry contains shmid and all shared memory are dumped in own files.
The most interesting thing is restore.
A maping is restored by process with the smallest pid. The mamping
is created before executing restorer.
We map a full mapping and restore it's conten, then we open a file from
/proc/pid/map_files and store a descriptor in vma_info. The mapping is
unmaped. Now we can map any region of this mapping in the restorer.

We use this trick, because a target process may have this mapping in
some places and the restorer has not function to open proc files.

v2: fix error hangling
xemul: Fixed static-s and args for cr_dump_shmem

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-21 11:03:55 +04:00
Andrey Vagin
31feef8ab4 mm: s/PAGES_SHMEM/SHMEM_PAGES
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-21 10:57:23 +04:00
Andrey Vagin
5dda50468b mm: change offset of zero_page_entry to ~0LL
Because 0 is actually a valid value.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-21 10:57:14 +04:00
Andrey Vagin
0ce623f9f7 crtools: use mremap for remaping shared memory
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-19 10:33:47 +04:00
Pavel Emelyanov
ffacd0f17c image: Open images via openat
Using absolute paths for this is dangerous - while doing c/r we should
be extremely carefully and not change tasks' roots and mount namespaces
too early. Sometimes it will not work -- when restoring containers we'll
be unable to switch to new CT and still have the ability to open images.

Rework the images opening via openat and keep the image dir fd open all
the time as the service fd (introduced earlier).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-16 20:45:50 +04:00
Andrey Vagin
adce8197c4 crtools: don't redeclarate the variable
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-16 15:26:23 +04:00
Cyrill Gorcunov
ea1ec9f619 restore: Don't close pstree_fd several times
There is a scenario when pstree_fd may be tried
to close several times -- if we start crtools
with "detach" option.

So simply make restore_root_task to close opened
file descriptor, this also simplifies the code.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-07 18:31:20 +04:00
Cyrill Gorcunov
644e4fec6b restore: Don't close LAST_PID_PATH descriptor if it was not opened
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-06 17:02:57 +04:00
Cyrill Gorcunov
351537c4f4 cr-restore: Fix typo in restorer_get_vma_hint
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-03-02 23:21:51 +04:00
Pavel Emelyanov
85f18ef02f restorer: Pass self-vmas via memory, not temp file
Reserve more mem for bootrstrap code and put all self vmas at its tail.

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
471d3c429c restore: Cleanup mem variables usage
Just prepare the code for smoother further bootstrap areas allocation.

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
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
e94c85fe6e restorer: Fix bootstrap allocation
There are three bugs in this code.

1. self vmas list is released before get-hint is called
2. get-hint code wrongly detects the hole (just bugs, no details)
3. exec hint is mapped without MAP_FIXED, but should

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-03-02 21:31:35 +04:00
Cyrill Gorcunov
7aa8e4b6e2 log: log-engine slight redesign
The messages are filtered by their type

    LOG_MSG     - plain messages, they escape any (!) log level
                  filtration and go to stdout
    LOG_ERROR   - error messages
    LOG_WARN    - warning messages
    LOG_INFO    - informative messages
    LOG_DEBUG   - debug messages

By default the LOG_WARN log level is used, thus LOG_INFO
and LOG_DEBUG messages will not appear in output stream.

pr_panic helper was replaced with pr_err, pr_warning
shorthanded to pr_warn and old printk if rather pr_msg
now.

Because we share messages between "show" and "dump" actions,
before the "show" action proceed we need to tune up
log level and set it to LOG_INFO.

Also note that printing of VMA and siginfo now
became LOG_INFO messages, it was not that correct
to print them regardless the log level.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-02 01:05:43 +04:00
Kinsbursky Stanislav
46535130c6 restore: UNIX sockets queue support
Based on xemul@ patches.

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-29 17:42:30 +04:00
Kinsbursky Stanislav
eeed250dc3 restore: close opened fd
This is a cleanup patch.

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-29 14:46:42 +04:00
Cyrill Gorcunov
8b187454b4 files: Rename prepare_fdinfo_global to prepare_shared_fdinfo
This function simply allocates shared memory. Name it so
and move it closer to the variables it referes on.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-02-28 19:13:47 +04:00
Cyrill Gorcunov
5cadfef1c1 restore: Add a comment about stack size used in restore procedure
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-02-28 19:13:47 +04:00