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

153 Commits

Author SHA1 Message Date
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
bb25ed38c8 files: close_old_fds before forking children (v2)
A few processes can share one fd table. Each process has own set of
service file descriptors and a process knows nothing about servic fds
of another processes. So if two process share one fd table,
close_old_fds will close servic descriptors of another process.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-12 00:54:42 +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
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
Huang Qiang
223dce83c2 fix many unclosed file opened by open_image_ro
Many image files opened by open_image_ro weren't closed before return, fix
them all in this patch.

Signed-off-by: Huang Qiang <h.huangqiang@huawei.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-24 16:51:50 +04:00
Cyrill Gorcunov
9c579cfd02 sfd_type: Add SELF_STDIN_OFF service fd and call helpers where needed
We will need it for slave ttys migration. They serve for one purpose --
to clone self stdio descriptor and use it with tty layer, which will
be addressed in further patches.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-10-18 15:51:56 +04:00
Andrey Vagin
d33d2290bd files: rework a function for closing all descriptors (v2)
It reads /proc/PID/fd and close all descriptors except service fds.

v2: s/is_one_of_service_fds/is_any_service_fd

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-29 11:01:53 +04:00
Pavel Emelyanov
62cf23b93a files: Hide pslist selection logic into file desc handlers
Don't do explicit switch by file type in files.c and don't export
intimate knowledge of pty being master/slave. Use a file desc op
for that.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-14 21:53:51 +04:00
Pavel Emelyanov
845f3ee973 fd: Indirect fd opening states engine
Put the states into in one place.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 00:34:37 +04:00
Pavel Emelyanov
1ea03bf80c fd: Relax file master checking in open and post_open
pid == pid && fd == fd equals fle == fle :)

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 00:21:14 +04:00
Pavel Emelyanov
cc41192f10 fd: Standartize arguments for fd opening stages handlers
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 00:17:57 +04:00
Pavel Emelyanov
b0502e4fe8 fd: Split fd opening and serving out routines
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 00:08:39 +04:00
Cyrill Gorcunov
0910b72b3d tty: Use is_service_fd where appropriate
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-13 14:45:14 +04:00
Pavel Emelyanov
ccce9fed2a tty: Brush up ctl tty preparation
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:09:05 +04:00
Cyrill Gorcunov
20d6762d93 tty: Add restoration of controlling terminal v4
The idea behind is pretty simple -- once we find
that there is a controlling terminal present we
do call ioctl on appropriate /dev/pts/N.

This is done in a bit unusuall manner. When we
find that there is a controling terminal present
we do create an additional FdinfoEntry for it
with object id taken from existing master peer.

The file engine stack this new FdinfoEntry on
fd_info_head head list. Thus we will have at
least two entries on this list. One for real
Fdinfo associated with master peer and one for
our new generated Fdfinfo entry, it depends on
pid which one become a file master.

Finally we do use post_open_fd hook in our
tty code which allows us to open controlling
terminal and yield proper ioctl on it.

v2:
 - restore control terminals via service fd,
   still need to speedup service fd retrieval.

v3:
 - use prepare_ctl_tty() helper to generate
   control terminal fdinfo entry

v4:
 - use post_open_fd

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:00:58 +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
Cyrill Gorcunov
5340807b87 Add separate list for slave tty fds on restore v2
When we will be restoring ttys we need that restore
procedure for master peers will be yielded earlier
than for slave peers due to ttys specifics. With this
commit we introduce @tty_slaves list which will allow
us to order tty file restore procesure.

Because we need to fetch which list to be used depending
on tty type this patch extend select_ps_list with fdinfo_list_entry
parameter.

v2 (by xemul@):
 - make sure the epoll list is still last

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 20:00:52 +04:00
Andrey Vagin
403dcb9de5 files: place the state POST_CREATE after the state RECV
It will be used for restoring epollfd.
Currently a transport fd may be added to epollfd.
epollfd should be populated, when all descriptors were already received.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-12 17:50:22 +04:00
Pavel Emelyanov
720cab0bd8 fd: Sanitize open_fd with send_fd_to_self helper
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-11 22:27:21 +04:00
Pavel Emelyanov
8cc9477d46 fd: Rename tmp to ret in open_fd
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-11 22:20:21 +04:00
Pavel Emelyanov
97dba0eb8f fd: Fast path post open
Check for post_open callback presense before any other checks.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-11 22:07:21 +04:00
Pavel Emelyanov
84d1ffb986 fd: Move rst fd list iteration into helper
Same again -- for code to be cleaner.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-11 21:47:14 +04:00
Pavel Emelyanov
455aa8cd37 fd: Move ps fd list selection to separate routine
Just for cleaner (from my pov) code.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-11 21:33:19 +04:00
Cyrill Gorcunov
e25d115212 files: Use switch in collect_fd
For easier transition to tty c/r. We will need more
types here, thus using switch statement makes code
a bit easier to read.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-09-05 20:00:06 +04:00
Cyrill Gorcunov
d2fab85055 files: Rename variables in collect_fd
Variables `l' and `le' are short and named
too similar which makes them hard to distinguish.

Thus rename `l' to `le' (list entry) and `le' to
`new_le'. This makes them easy to recognize.

Also add braces around list_for_each_entry.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-27 23:24:06 +04:00
Cyrill Gorcunov
b3a050e1f1 files: Use BUG() instead of BUG_ON(1)
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-27 23:22:25 +04:00
Cyrill Gorcunov
b6b9bb0cd2 files: Drop unused FDINFO_POOL_SIZE
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-27 23:22:07 +04:00
Andrey Vagin
513dde00d2 sk-unix: connect unix sockets in post_open
Move logic from run_unix_connections to post_open().

I don't fix indents in this patch for easy reviewing.
They are fixed in the next patch.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-20 17:50:16 +04:00
Andrey Vagin
61490ba985 files: add one more operation post_create
It will be used for restoring inet sockets. An inet socket is created with
the option REUSEADDR, because the restore logic requires this.
The origin value can be restored only when all sockets were restored.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-20 17:50:01 +04:00
Cyrill Gorcunov
19672e9cd1 files: Rename argument to sock
It's unclear why we've had two different names
for same argument. Moreover, "tsk" is definitely
misnamed feature.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-17 15:43:22 +04:00
Pavel Emelyanov
9554b482c2 util: Introduce the shmalloc helper
This one allocates a memory, that will be shared (MAP_SHARED)
between all the subsequent children. This can now be just used
for fd resote, later it will be required at inet socket port
binding.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-16 20:41:34 +04:00
Pavel Emelyanov
b1b0a39a58 pb: Rewrite object reading to use pb-descs
The pb_read thing is no longer a macros. This will allow to
factor out objects collecting on restore.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-07 19:22:00 +04:00
Cyrill Gorcunov
26aa295135 files: Enhance error message
While being debugging problem I found plain BUG_ON is not enough.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-28 09:11:12 +04:00
Cyrill Gorcunov
4806e1395f protobuf: Convert vma_entry to PB format v3
v2:
 - Use regular uint types in message proto
 - Use PB engine for "show"
v3:
 - drop usage of temp. variable in prepare_shmem_pid

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-19 12:43:36 +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
0468355c12 protobuf: Drop fown_t type
We are ready to use FownEntry everywhere,
so drop fown_t type and clean up source code.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-19 09:39:00 +04:00
Cyrill Gorcunov
b02158c14c protobuf: Convert struct fs_entry to PB engine
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-17 07:28:38 +04:00
Cyrill Gorcunov
7c44757683 files: Add pb_ helpers
To not spread opencoded copying of PB entries and image structures
we add a few pb_ helpers to be used until PB code completely merged.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-17 07:24:51 +04:00
Cyrill Gorcunov
a1fe3caf04 protobuf: Start switching our image entries to Google's protobuf
A short story -- there were a long conversation on which format should
be used to keep checkpointed data on disk image. We ended up in using
Google's Protocol Buffers (see https://developers.google.com/protocol-buffers/
for detailed description). Thus image entries should be convered to PB.

This patch converts fdinfo_entry to PB "message fdinfo_entry".

Build note: one should have protobuf and protobuf-c installed to be able
to build crtools.

 - http://code.google.com/p/protobuf/
 - http://code.google.com/p/protobuf-c/

Inspired-by: Pavel Emelianov <xemul@parallels.com>
Inspired-by: Kinsbursky Stanislav <skinsbursky@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-17 07:10:41 +04:00
Cyrill Gorcunov
2db18f5e16 files: Use fdinfo_entry * in fdinfo_list_entry structure
We will need to use pointer here (to PB object) anyway
so better to make it in a separate patch for bisectability sake.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-09 15:04:35 +04:00
Andrey Vagin
49c1d43645 pstree: move all code about pstree in a separate file
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Looks-cool-to: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-06-27 21:07:30 +04:00
Pavel Emelyanov
43f62f42b2 rst: Close standard descriptors before fds restore
Strictly speaking we have to close all fds before reopening them from the
image. This can be done using not yet merged nextfd syscall, but it's not
yet merged :( By now just close std and 255 (bash's) descriptors. This is
ugly, but I prefer to wait for the nextfd syscall.

But skip the init tasks' stds becase the existing zdtm implementation
uses system() in such tasks which doesn't work when all fds are closed.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-06-27 20:57:42 +04:00
Cyrill Gorcunov
cb74aa3e48 files: Drop redundant declarations from files.h
These are declared in files-reg.h, so get rid of
them and add files-reg.h inclusion where needed.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-06-22 17:02:23 +04:00
Andrey Vagin
8075dc60a5 pstree: rename fields in struct pid
s/pid/virt/
s/real_pid/real/

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-06-22 12:09:44 +04:00
Pavel Emelyanov
57b1e94522 files: Sanitize transport creation
Current if/if/else scheme is ... not so easy to understand. Here's an
attempt to make it more readable. Bonus: free comments.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-06-21 17:37:10 +04:00
Pavel Emelyanov
3d24b7d54e files: Don't lookup fle by itself
When creating transport we have to find the corresponding fle. Currently
this is done by desc list scan %) but this is an overkill -- the required
fle is already at our hands.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-06-21 17:36:25 +04:00
Pavel Emelyanov
a842cfe68f files: Don't lookup fdesc twice
In the open_fdinfo we need to get a file_desc associated with the given
fdinfo_list_entry. This is done by searching the hash of descs, but this
can be speeded up by saving the desc pointer on the fdinfo at the time
of collecting them.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-06-21 17:32:56 +04:00
Cyrill Gorcunov
4140c9e4ec files: Move regular files handling code to files-reg
Instead of spreading regular files handling code over
files.c and cr-dump.c move it to files-reg.c.

This allows to extend regular file handling code in
future without disturbing other source files and
make code logically coupled, where files.c is mostly
a place for general file handling code unrelated to
file type specifics.

While mostly it was code tossing there is some change
I have to notice -- the structure ghost_file was previously
declared in two paces cr-dump.c and files.c, in cr-dump.c
it was used for dumping while in files.c it was used
for restore. The structure had different members.

So to resolve this conflict the ghost_file structure
was renamed to ghost_file_dumpee.

Nothing else is changed.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-06-21 12:10:13 +04:00
Cyrill Gorcunov
582954685b Escape using unsafe sprintf helper
Util it's very critical for speed we should
not use unsafe sprintf helper, we're root-granted
program and must be as safe as possible.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-06-20 15:04:51 +04:00