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

64 Commits

Author SHA1 Message Date
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
Pavel Emelyanov
3dd8f2e659 fds: Introduce service fd-s
These are the fds that help us to do c/r. We want them not to intersect
with any "real-life" ones and thus store them close the the file rlimit
boundary. For now only the logfd one is such.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-16 20:45:42 +04:00
Kinsbursky Stanislav
fe1cf26085 dump: add const qualifiers where possible
Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-06 17:00:42 +04:00
Cyrill Gorcunov
827cabb480 show: Use pr_msg for showing contents on console
Due to code sharing, especially in IPC area,
the unbinding is done via helper macros and
sysclt engine tuning (new CTL_SHOW action
added).

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-02 11:12:59 +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
Cyrill Gorcunov
fe99f501ef Move pr_ helpers to log.[ch]
This is a place where they should belong to.
util.c is too big already.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-02-20 14:23:28 +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
Kir Kolyshkin
03294077af util.c: introduce open_proc_rw()
To be used by the next patch

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
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
6c1e5978c4 hex_dump(): fix address printing
- Fix printing the same address on every line (ie p+i, not p).
 - Use GNU %p to print pointer, to avoid messing with width etc.
   Side effect: 0x is added, hope that's ok.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-31 17:19:00 +04:00
Cyrill Gorcunov
a9ba9732c9 hex_dump: Convert argument to long
To eliminate format problem

 | util.c:60:10: error: format ‘%lx’ expects argument of
 | type ‘long unsigned int’, but argument 2 has type
 | ‘unsigned char *’ [-Werror=format]

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-31 16:54:03 +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
Andrey Vagin
255cd497bd util: print warning if a image file is absent
It may be legal. E.g. for zombie

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-27 15:10:38 +04:00
Pavel Emelyanov
af3616d0ce util: Sanitize get_image_path
Make it shorter and simpler and use one in open_image_ro_nocheck.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-16 13:43:33 +04:00
Pavel Emelyanov
8c9c575ab4 util: Move get_image_path to util.c
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-16 13:43:23 +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
1c96c5cff0 Merge branch '@xemul' into dev
* @xemul:
  crtools: Collect dumping fd parameters into one place
  crtools: Toss dump_one_fd args around
  crtools: Rename fd to lfd in dump_one_fd
  crtools: Sanitize pstree construction
  crtools: Remove unused printk_registers and co
  crtools: Deduplicate file info showing code
  crtools: Merge pstree collecting into showing
  crtools: Remove unused and wrong arrays from pstree image
  crtools: Remove lseeks after prep_cr_ calls
  crtools: Cleanup collect_pstree in cr-show

Conflicts:
	cr-dump.c
	include/sockets.h
	sockets.c

The conflicts are mostly because of commit
995ef5eca3b8d74cf192e41c307f5329d93f9795

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-13 21:39:14 +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
81d91983d3 util: Move reopen_fd_as to reopen_fd_as_safe
[avagin@: Drop redundant fcntl call, and err variable]
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-01-13 13:26:28 +04:00
Pavel Emelyanov
a9e2321c38 crtools: Remove unused printk_registers and co
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-12 22:09:58 +04:00
Andrey Vagin
eac52b6090 util: reopen_fd_as to return an error if destination descritor is busy
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-10 16:55:02 +04:00
Cyrill Gorcunov
a14ceb4950 util: Fix parse_maps to handle anonymous shared mappings
In commit 99eb3d09c5c42200b230783e793b778882ce8dd6
we started to use self-contained shared memory
region but it revealed the problem that anonymous
sgared mappings might be parsed by parse_maps incorrectly,
so fix it and be ready to get anon-shared mappings.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2012-01-04 16:36:56 +04:00
Pavel Emelyanov
5f7d677fad crtools: Sanitize collect_mappings path buffers usage
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-30 16:25:42 +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
bf7a74d47e Helper for moving image fd
When opening an fd at a position where the current image fd sits
the latter one should be moved.

Introduce a helper for this.

Signed-off-by; Pavel Emelyanov <xemul@parallels.com>

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-26 21:53:44 +04:00
Pavel Emelyanov
99cc87949f reopn_fd_as return code fixlet and cleanup
Nobody cares the returned fd, so just make it 0/-1 and clean up the callers.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-26 21:53:36 +04:00
Cyrill Gorcunov
3e45e04050 util: Add fopen_fmt helper
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-26 02:24:27 +04:00
Cyrill Gorcunov
2e3c4e3692 Move everything related to ptrace into ptrace.[ch]
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-19 21:57:59 +04:00
Cyrill Gorcunov
8a90464cc9 Drop some duplicated #include
And rearrange the rest.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-19 21:05:37 +04:00
Cyrill Gorcunov
d6eab944e3 Move logging functions to log.c
Instead of keeping all unrelated to
C/R procedure helpers in util.c move
logging related helpers to log.c.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-19 18:52:50 +04:00
Cyrill Gorcunov
c1350f9ab1 Make error codes returned being a negative value
We have a mess in our return codes:
some functions return negative values,
while others -- positive.

Sanitize the return codes and make error
condition to return negative values.

Reported-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-13 15:03:33 +04:00
Andrey Vagin
650318f4b2 crtools: add options to specified a log file
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-08 18:55:13 +04:00
Andrey Vagin
2c237b6973 Don't use standard descriptors for logging
The standard descriptors may be redirected.

crtool dumplicates stderr in rlimit.maxfileno-1 and this descriptor
is inherited by all children and will be closed before sigreturn.

Known issues:

 - The logging descriptor may be used by a target process and
   a resume will fail.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-05 12:07:52 +04:00
Andrey Vagin
555efbb374 Set MAP_GROWSDOWN flag for stacks
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-11-30 22:04:29 +04:00
Cyrill Gorcunov
4dc0736697 dump,restore: Dump and restore vDSO area from userspace
There is no need to force kernel to remap vDSO area, we
can do that from the user-space as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-29 16:39:48 +04:00
Cyrill Gorcunov
9eeb003766 util: Add K/M/G bytes helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-24 15:07:03 +04:00
Pavel Emelyanov
47b7404d73 crtools: Don't save vma's inode info in image
This one isn't used on restore process, since the file mapped is
stored in the fdinfo part of the images.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-23 14:03:24 +04:00
Pavel Emelyanov
9299d53d32 crtools: Don't show vma fd in --show output
This entry is for restorer only. In image the fd is -1 always.

Signed-off-by; Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-23 14:03:20 +04:00
Pavel Emelyanov
fb44c9d82b crtools: Don't hold pid on vma image
It's pointless. All vmas are stored in the per-pid image file.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-23 14:03:14 +04:00
Cyrill Gorcunov
c704fc272e util: Make VMA proto being printed with 8 char width
Fancy output.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-22 00:13:04 +04:00
Cyrill Gorcunov
0fd17a08cb Bring some order in usage of VMA entries helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-15 17:12:29 +04:00
Cyrill Gorcunov
bbabbe89a7 util: Use vma_entry_len helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-15 14:02:00 +04:00
Cyrill Gorcunov
35781a8c6d util: Drop redundant vma_area->vma.status assignment
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-15 13:37:17 +04:00
Cyrill Gorcunov
3542220a00 util: Split long line
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-15 13:32:09 +04:00
Cyrill Gorcunov
929e316f5f util: VMA area flags might exceed 4 symbols
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-15 13:28:56 +04:00
Cyrill Gorcunov
54b1455e8a util: Move maps buffer into routine stack
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-15 11:34:11 +04:00
Cyrill Gorcunov
dd4d829d61 util: Add error messages into files/dirs open helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-15 11:29:33 +04:00
Cyrill Gorcunov
83c209ef07 Move vma prot setup into parsing helper
To shrink restorer code.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-08 13:54:01 +04:00
Cyrill Gorcunov
b9d0883d76 dump: Anonymous shared mappings should have MAP_ANONYMOUS flag
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-11-08 12:19:43 +04:00