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

295 Commits

Author SHA1 Message Date
Pavel Emelyanov
98f4c2e4de ns: Support UTS namespace
Only two fields are modifiable -- hostname and domainname. So
read them on dump and write on restore.

File format is simple --

u32 magic
u32 length of nodename
u8[] nodename string
u32 length of domainname
u8[] domainname string

For OpenVZ we can write the release at the end, but this is later.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-26 16:54:22 +04:00
Pavel Emelyanov
3391416a1b crtools: Namespaces support skeleton
New option -n to dump/restore namespaces.

Fork the namespaces dumping task and write a helper for switching a namespace.

Prepare the restorer code for restoring namespaces before root task.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-26 16:54:22 +04:00
Pavel Emelyanov
b5e5aac9e9 restore: Switch task fork-ing into clone-ing
In order to restore task in namespaces we'll have to clone() them,
not fork. Thus switch the restorer into using clone.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-26 16:54:22 +04:00
Pavel Emelyanov
2e48f0528b crtools: Move options deeper into the code
I will need them in the place where we restore the root task.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-26 16:54:22 +04:00
Pavel Emelyanov
b7de83aaf3 crtools: Interval timers support
Timers are dumped from inside parasite code, the format is plain -- just
3 pairs of interval/value one-by-one.

The restoration occurs in two stages -- first prepare the timer values in
restorer (and check for sanity), then setup the timers in the latest stage
before actually calling the sigreturn.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-24 18:41:49 +04:00
Pavel Emelyanov
5c2083ee87 cr: Support zombie tasks
Dump the core-pid.img file only. On restore select the way of killing
task based on his exit_code -- exit or kill with a signal. Before dying
unblock all the handlers and set SIG_DFL to it (to make the dead signal
other than KILL be deliverable).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-23 01:44:01 +04:00
Pavel Emelyanov
3822c079c4 restore: Ignore ENOENT when preparing shared resources
The absent image file on shared resources preparation now means -- no resources
for this pid (zombies will not have these files).

This is not the most elegant solution, but I don't have anything better in mind.
Need to think over, all the more so we're most likely about to reimplement the
way image is stored some day in the future.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-23 01:43:53 +04:00
Pavel Emelyanov
164ccc095f crtools: R/W API rewrite
Kill all the macros for reading/writing image parts. New API looks like

* write_img_buf/write_img
  Write an object into an image. Reports 0 for OK, -1 for error. The _buf
  version accepts object size as an argument, the other one uses sizeof()

* read_img_buf/read_img
  Reads an object from image. Reports 0 for OK, -1 for error or EOF.

* read_img_buf_eof/read_img
  Reads an object from image. Reports 1 for OK, 0 for EOF and -1 for error.
  This is not symmetrical with the previous one, but it was done deliberately
  to make it possible to write code like

  ret = read_img_bug_eof();
  if (ret <= 0)
	return ret; /* 0 means OK, all is done, -1 means error was met */.

  ... /* 1 means object was read, can proceed */

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-23 01:43:10 +04:00
Cyrill Gorcunov
48f624ee17 restore: Drop real_pid member from shmem_info structure
It's not needed anymore, it was handing cases
where no fork-with-pid functionality were in
kernel, but now it's simply unneeded.

Also drop redundant getpid() calls.

Passes all tests (except fork test which known to fail).

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parllels.com>
2012-01-20 13:08:06 +04:00
Pavel Emelyanov
6128b88c76 restorer: Use LAST_PID_PATH directly
After Andrey's work with making restorer a regular .o file we can do it
(the pthread00 test doesn't fail on it).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-19 22:41:32 +04:00
Andrey Vagin
1dd20b087a restore: detect that someone failed (v2)
Handle SIGCHLD and if someone failed, nr_in_progress is set to -1.
If crtools notices that nr_in_progress is negative, it kills all
tasks.

v2: * Use named constants for task_entries->start in restorer.c
    * Use SA_NOCLDWAIT when setting sigchild handler,
      this makes sigchild handler simpler.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-19 16:16:58 +04:00
Andrey Vagin
99498681e6 restore: new mechanism to sync tasks
Now we have only one mutex nr_in_progress, it says how many
tasks are not restored yet. A negative value signs that someone
failed.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-19 16:16:58 +04:00
Andrey Vagin
f00efadd2c This patches improves execution of zdtm tests.
It's really like in VZ.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-18 23:31:22 +04:00
Andrey Vagin
2cd82bc7ff restorer: move log descriptor from crtools (v2)
v2: add FIXME for linking restorer-log.c and restorer.c by ld
    I don't know how to do it now.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-01-17 18:08:03 +03:00
Andrey Vagin
014841825a restorer: isolate restorer like parasite (v4)
Before this patch the restorer's code is linked in crtools and then
we copied functions from it. In this case all function should
be inline and we can't use a global variables.

I suggest to make it like parasite. The restorer's code is isolated in
own file and will be copied wholly.  The restorer's code is compiled as
position-independent code, so we can use functions and global variale
(E.g. to save descriptor for log messages).

v2: correct indentions in a separate patch
v3: introduce a variable restore_task_exec_start symmetrical to
    restore_thread_exec_start
v4: don't give command in restorer_thread()

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-01-17 18:08:03 +03:00
Andrey Vagin
c266644150 tasks: synchronize restoration of tasks (v2)
This patch prepares code to handle errors. In the near future
we will handle SIGCHLD. If a restore of one task fails, we will
send a signal to other for completing.

For this we should have ability to wait until all task wills be
restored. This patch does it.

v2: Don't wait children.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-01-17 18:08:03 +03:00
Andrey Vagin
fb177e0312 restore: generalize mechanism of remapping memory to restorer (v2)
Sometime we want to have a shared mapping in restorer. E.g. A storage
for shared memory entries. This entries contains locks, which should
be released in restorer.

v2: fixed according to Pavel's comments

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-01-17 18:07:58 +03:00
Cyrill Gorcunov
31e99b7b37 restore: Drop uneeded code
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-17 11:52:14 +04:00
Cyrill Gorcunov
55d491fb0e restore: Use non sys_ versions of libc functions
There is no need to use sys_ versions of libc functions
when we run in non relocated code. It's a leftover from
early testing time. Fix it.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-17 11:52:04 +04:00
Cyrill Gorcunov
b3c6742a7a restore: Use xmalloc instead of plain malloc
And add error checking

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-16 14:31:25 +04:00
Pavel Emelyanov
2e31cb1f8e restore: Close and drop shmem remap fd
Reprimand to commits bd8b2b0f and d0a6e9a1 authors for not
cleaning after themselves...

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-16 13:44:06 +04:00
Pavel Emelyanov
a28d53f4e1 restore: Don't init master thread args
This one is skipped at restore and leaves an open core file
in target task's fdtable.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-16 13:43:57 +04:00
Pavel Emelyanov
368c4a508b restore: Close ns_last_pid file fd
Otherwise it pops up after restore in target task's fdtable.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-16 13:43:49 +04:00
Pavel Emelyanov
09a7273e04 restore: O_TRUNC file instead of unlink
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-16 13:43:41 +04:00
Andrey Vagin
8cc08ada8e cr-restore: don't close image fd in create_pipe
create_pipe() may restore up to 3 descriptors. They may be both ends
of pipes and a target descriptor. The image fd may hold any of them.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-16 12:01:33 +04:00
Cyrill Gorcunov
579e241c3b Revert "restore: pipes -- Allow to reuse descriptors"
This reverts commit 46c613cc7d869ebf39532a1def054de7678e441f.

Andrey posted a proper fix for it. Moreover, the problem in first
place was initiated by a parasite application running during test
case, crtools knows nothing about.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-16 12:01:23 +04:00
Cyrill Gorcunov
46c613cc7d restore: pipes -- Allow to reuse descriptors
It's perfectly fine to reuse descriptors here,
since we use plain pipe() call and it migh choose
the descriptor which we need after.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-15 23:37:20 +04:00
Pavel Emelyanov
cc14c6eb61 pstree: Sanitize pstree image opening on restore
The old code carried the path through the stack. Now we have
pstree_pid and handy helpers to get one.

Tested by pipes00 test from zdtm (it forks).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-15 22:37:27 +04:00
Cyrill Gorcunov
a9969dcf72 restore: Format printing in restore_pipe_data
To align data with previous callers.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-15 22:36:52 +04:00
Pavel Emelyanov
3302183c05 restore: Pass self-vma file descriptor directly
Instead of passing self-vma file path to restorer
code simply open it before restore_task call and
pass descriptor instead. This saves some memory.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-14 14:38:53 +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
Cyrill Gorcunov
995ef5eca3 Use openat() helper intensively when opening /proc/pid/X files
This allows us to get rid of open-coded "/proc/pid/X".

Based-on-patch-from: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-01-13 18:29:18 +04:00
Cyrill Gorcunov
7a11cfc0b3 restore: No need to track pid of main shmems, open map_files/ via /proc/self
It basically reverts e189efc1763d9cae55e1cafd7aff7ffef6e47303
which was overdone one.

Reported-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-01-13 17:09:08 +04:00
Andrey Vagin
14e42bb704 pipe: fix error code and message
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-11 18:24:40 +04:00
Andrey Vagin
d6a1cd0fbc restore: Learn to work with shared struct file-s
Some process can share one struct file-s, we may find them by "object IDs".
A file descriptor is opened in one process and send to other via unix socket.

The procedure of restoring files contains four stages.
* Collect data about all file's descriptors
  On this stage we find process which will restore a file descriptor and
  create a list of processes, who should get this descriptor.

* Create datagrams unix sockets
  If a file descriptor should be received, a unix socket is created
  instead of it.

* Open file descriptors
  A process with the least pid opens a file and sends this file
  descriptors to all one who wait it.

* Receive file descriptors.

When we were thinking up this algoritm, we wanted to minimize a number
of context switches. A number of context switches is proportional of a
number of processes.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-11 16:01:44 +04:00
Andrey Vagin
7fde5f061b restore: move file-related stuff to a separate file
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-10 18:39:39 +04:00
Cyrill Gorcunov
5d5e8b801c retore: Fix up shared anonymous memory restore procedure
Restorer does really restore shared memory (including page
contents restore) only on master process, while all other
processes do open such memory area via map_files/ procfs entry
so that we might have a situation when shared VMA is present
in some particular core-%d.img file but it's not listed in
collected shmems array and find_shmem_by_pid will return NULL.
This is perfectly fine, be ready for that.

Another issue is that shared memory might look like

CR_FD_SHMEM: /home/cyrill/projects/kernel/crtools/shmem-2641.img
----------------------------------------
0x7f2200775000-0x7f2200776000 id 19664
0x7f2200776000-0x7f2200777000 id 19663
----------------------------------------

So vma area is [x;y) range and we should distinguish two
shmem lookup cases

 - one when we search for page in shmem area
 - second when we lookup shmem area in collected ranges

They both have a different lookup conditions so single
find_shmem splitted into two helpers find_shmem and
find_shmem_page as appropriate.

This patch finally fixes the three process asynchronious
shared memory updates test-case.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 18:31:48 +04:00
Cyrill Gorcunov
1b21a27b0c restore: Simplify shmem_wait_and_open
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:41:05 +04:00
Cyrill Gorcunov
d0a6e9a101 restore: Pass shmems_fd as argument as well
We might be needing to close the shmems file descriptor.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:40:54 +04:00
Cyrill Gorcunov
e0e934aa4b restore: shmems -- Use cr_wait_init helper
Just in a sake of consistency

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:40:24 +04:00
Cyrill Gorcunov
793f3aa947 restore: shmem_remap arguments resort
Style tuning, no func change

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:39:58 +04:00
Cyrill Gorcunov
e189efc176 restore: shmems -- Fix /proc path
The remapping of /proc path to shmem should be
done with pid of process which did mmap() call
initially.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:39:08 +04:00
Cyrill Gorcunov
58ad088870 restore: Fix typo in shmem_wait_and_open
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:38:44 +04:00
Cyrill Gorcunov
80492c78e6 restore: More detailed log on shmem restore
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:38:18 +04:00
Cyrill Gorcunov
a03e3622f2 restore: Add log message that restore via sigreturn is started
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:38:04 +04:00
Cyrill Gorcunov
3afb83299c restore: Gather setting agrument for sigreturn code in one place
Also add a few more comments.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:37:41 +04:00
Cyrill Gorcunov
ee0f17b0a7 restore: Fix typo in shmem size assignment
And use SHMEMS_SIZE constant as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:37:12 +04:00
Pavel Emelyanov
96f92ee612 crtools: Cleanup open_image_ro
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-29 19:56:34 +04:00
Pavel Emelyanov
7b0b203b34 crtools: Use open_image_ro where appropriate
Several places just need to open an image, thus the helper is OK to use.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-28 21:38:00 +04:00
Andrey Vagin
aeb638f845 restore: shmem -- Don't poll, use wait helpers instead
Signed-off-by: Andrey Vagin <avagin@openvz.org>
[gorcunov: A few tuneups]
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-26 23:54:18 +04:00