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

54 Commits

Author SHA1 Message Date
Adrian Reber
4e7ec3c88b pidns: add pidns image file definition
TODO: create correct magic

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Andrei Vagin
4127ef4ab7 criu: Add support for time namespaces
The time namespace allows for per-namespace offsets to the system
monotonic and boot-time clocks.

C/R of time namespaces are very straightforward. On dump, criu enters a
target time namespace and dumps currents clocks values, then on restore,
criu creates a new namespace and restores clocks values.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-04-25 00:43:23 -07:00
Nicolas Viennot
56d8e2455f memfd: add seals support
See "man fcntl" for more information about seals.

memfd are the only files that can be sealed, currently. For this
reason, we dump the seal values in the MEMFD_INODE image.

Restoring seals must be done carefully as the seal F_SEAL_FUTURE_WRITE
prevents future write access. This means that any memory mapping with
write access must be restored before restoring the seals.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-03-27 19:36:20 +03:00
Nicolas Viennot
c1e72aa936 memfd: add file support
See "man memfd_create" for more information of what memfd is.

This adds support for memfd open files, that are not not memory mapped.

* We add a new kind of file: MEMFD.
* We add two image types MEMFD_FILE, and MEMFD_INODE.
  MEMFD_FILE contains usual file information (e.g., position).
  MEMFD_INODE contains the memfd name, and a shmid identifier
  referring to the content.
* We reuse the shmem facilities for dumping memfd content as it
  would be easier to support incremental checkpoints in the future.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-03-27 19:36:20 +03:00
Andrei Vagin
ff756cbb28 python: sort imports
202 Additional newline in a group of imports.
I100 Import statements are in the wrong order.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-02-16 09:15:31 -08:00
Nicolas Viennot
2ac43cd426 python: Improve decoding of file flags
Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-02-04 12:39:44 -08:00
Nicolas Viennot
2e656222d7 crit: fix python3 encoding issues
Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-02-04 12:39:05 -08:00
Radostin Stoyanov
72402c6e7a py: Fix tabs in code comments
These were left by yapf formatter

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2019-09-07 15:59:57 +03:00
Andrei Vagin
5aa72e7237 py: Reformat everything into pep8 style
As discussed on the mailing list, current .py files formatting does not
conform to the world standard, so we should better reformat it. For this
the yapf tool is used. The command I used was

  yapf -i $(find -name *.py)

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2019-09-07 15:59:56 +03:00
Radostin Stoyanov
b25d1facae pb2dict: Disable undefined name 'basestring'
The following error is falsely reported by flake8:

lib/py/images/pb2dict.py:266:24: F821 undefined name 'basestring'

This error occurs because `basestring` is not available in Python 3,
however the if condition on the line above ensures that this error
will not occur at run time.

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2019-09-07 15:59:55 +03:00
Radostin Stoyanov
cd58de7a2b pb2dict: Resolve Python 2/3 compatibility issues
In Python 3, bytes has only a decode() method, and string has only
an encode() method. [1]

The modules quopri and base64 from the Python Standard Library perform
quoted-printable transport encoding and decoding with both Python 2 [2]
and Python 3 [3].

[1] https://docs.python.org/3/howto/pyporting.html#text-versus-binary-data
[2] https://docs.python.org/2/library/quopri.html
[3] https://docs.python.org/3/library/quopri.html

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2019-09-07 15:59:52 +03:00
Radostin Stoyanov
831ae18dac pb2dict: Fix is_string() check for Python 2
In the __main__ module, __builtins__ is the built-in module builtins.
In any other module, __builtins__ is an alias for the dictionary of
the builtins module itself. [1]

Thus, hasattr(__builtins__, "basestring") would only work in __main__
module. Since pb2dict is part of pycriu and is intended to be called
by modules other than __main__, we can assume that __builtins__ would
always be a dictionary (not a module).

In Python 2, basestring is a superclass for str and unicode. [2]
However, the assignment statement creates a variable basestring in the
local scope of the function is_string() which, in Python 2, causes a
failure with UnboundLocalError. In order to mitigate this issue the
local variable name has been changed to string_types.

Fixes #708

[1] https://docs.python.org/2/reference/executionmodel.html#builtins-and-restricted-execution
[2] https://docs.python.org/2/library/functions.html#basestring

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2019-09-07 15:59:52 +03:00
Radostin Stoyanov
8accfe6cc9 python: Drop six dependency
From the python-six module is used only six.string_types in the
is_string() function. An alternative solution is to use
basestring with additional if statement for Python 3 compatibility.

This change avoids the dependency on the six module.

However, this module is required by junit_xml and it is not listed
as a dependency in the CentOS 7 package python2-junit_xml.

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2019-09-07 15:59:51 +03:00
Adrian Reber
681c05392d crit: display help message when using python3
Running crit with python2 gives following minimal help message:

 $ crit/crit
 usage: crit [-h] {decode,encode,info,x,show} ...
 crit: error: too few arguments

Using a python3 only system crit shows the following error:

 $ crit/crit
 Traceback (most recent call last):
   File "crit/crit", line 6, in <module>
     cli.main()
   File "/home/criu/crit/pycriu/cli.py", line 334, in main
     opts["func"](opts)
 KeyError: 'func'

Using this patch the python3 output changes to:

 $ crit/crit
 usage: crit [-h] {decode,encode,info,x,show} ...
 crit: error: too few arguments

Suggested-by: Andrei Vagin <avagin@gmail.com>
Signed-off-by: Adrian Reber <areber@redhat.com>
2019-04-20 20:25:26 -07:00
Radostin Stoyanov
76f8c09093 crit-images: Fix reference to ipc_msg()
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2018-10-30 19:28:19 +03:00
Radostin Stoyanov
3b1563ebd0 crit-images: Don't overwrite 'pb' with local var
Rename the local variables 'pb' to 'pbuff' to avoid conflict with the
imported 'pb' module.

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2018-10-30 19:28:19 +03:00
Radostin Stoyanov
7064cbaa35 python: Remove unnecessary semicolons
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2018-10-30 19:28:01 +03:00
Radostin Stoyanov
7ce23b2a74 python: Remove unused imports
Auto-detected with pylint.

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2018-10-30 19:28:01 +03:00
Cyrill Gorcunov
825ac61090 crit: Show cpuinfo image
Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-07-09 18:26:49 +03:00
Andrei Vagin
9462f2aed7 crit: typo fix
test/dump/zdtm/static/msgque/43/1/ipcns-msg-12.img decode fails: object of type 'NoneType' has no len()

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-07-09 18:26:49 +03:00
Andrei Vagin
841edaf317 lib: a few fixes to be compatible with python3
All these issues was found by running test/crit-recode.py

https://github.com/checkpoint-restore/criu/issues/495

v2: drop FD_CLOEXEC for swrk descriptors
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-07-09 18:26:48 +03:00
Adrian Reber
4feb07020d crit: enable python2 or python3 based crit
With this last commit of the crit with python3 series it is possible to
either use python2 or python3 with CRIU.

Now the basic build system functionality (make and make install) are
python2/python3 aware. zdtm.py and criu-coredump are still python2, but
as they are not part of 'make install' those parts have not yet been
ported from python2 to python3.

Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-07-09 18:25:16 +03:00
Adrian Reber
1a0ad1ae87 Makefiles: auto-detect python version - prefer python2
This prepares CRIT for python2/python3 compatibility by auto-detecting
the installed python version. python2 is detected first and then the
variable PYTHON is set.

By setting the variable PYTHON to python2/python3 the user can override
the auto-detection.

Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-07-09 18:25:16 +03:00
Adrian Reber
98cb5c627d crit: make crit python2/python3 compatible
Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-07-09 18:25:16 +03:00
Radostin Stoyanov
3b3384352d Fix typos
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-03-02 21:52:13 +03:00
Andrei Vagin
008db0cb7a zdtm: run page-server via rpc
v2: typo fix
v3: run criu pre-dump via rpc
v4: don't use status-fd for rpc

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-23 20:23:23 +03:00
Andrei Vagin
397df9c035 lib/py: allow to execute page-server as a child process
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-23 20:23:23 +03:00
Cyrill Gorcunov
0b6f9c7975 build: Reused .FORCE from nmk
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-23 20:23:14 +03:00
Avindra Goolcharan
8e45ce4905 images.py: remove shebang
This file is not executable directly, so it should not have the shebang.

Signed-off-by: Avindra Goolcharan <aavindraa@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-23 20:23:14 +03:00
Cyrill Gorcunov
fc21d6fb53 crit: Add socket states decoding
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-23 20:23:14 +03:00
Cyrill Gorcunov
4d0fc1a496 crit: Add socket types decoding
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-23 20:23:14 +03:00
Cyrill Gorcunov
d4c29ab7cb crit: Add protocols decoding
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-23 20:23:14 +03:00
Cyrill Gorcunov
56cd56706d crit: Add more families into socket decoding
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-23 20:23:14 +03:00
Cyrill Gorcunov
ec273275fe crit: Add INET6 familiy
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-23 20:23:14 +03:00
Mike Rapoport
48675a3c7e Drop support for zero pagemap entries
The pagemap entries for pages mapped to zero pfn proved to be not useful...

travis-ci: success for revert zero pagemaps
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-09-16 11:47:02 +03:00
Adrian Reber
2ce576e646 crit: translate pagemap flags into strings
This translates pagemap flags into strings for easier readability.

Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-09-16 09:16:33 +03:00
Pavel Emelyanov
fe6fa3bec3 image: Introduce files.img and file_entry
There are two goals of this merge. First is to reduce the amount
of image files we generate and scan on restore. The latter is
more importaint, as even if we have no weird stuff like signalfd,
we still try to open this file. So after the merge we try to
open ~15 image files (out of ~30) less %) which is nice.

The 2nd goal is to simplify the C/R support for SCM messages.
This becomes possible with the fact, that all files we have can
be distinguished by their ID only, w/o type. This, in turn,
makes image layout for SCMs much simpler.

Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-08-09 18:51:39 +03:00
Pavel Emelyanov
c7ab0cd934 crit: Add support for chunked ghost images
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-07-18 09:34:44 +03:00
Pavel Emelyanov
1e1d0dde26 pycriu: Dont produce zombies
When running criu_dump() with zero pid (self dump) a zombie
from the library is left underneath the running processes
and this zombie is thus written into the images.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-05-10 04:13:41 +03:00
Dmitry Safonov
057c3f2947 python: specify python2 as .py interpreter
On some distro the default python interpreter is Python 3,
which results in such errors:
>  Running zdtm/static/socket-tcp-closed.hook(--post-start)
>  make[1]: Nothing to be done for default.
>  ./socket-tcp-closed --pidfile=socket-tcp-closed.pid --outfile=socket-tcp-closed.out
>    File "zdtm/static/socket-tcp-closed.hook", line 16
>      except OSError, e:
>                    ^
>  SyntaxError: invalid syntax
>  ######### Test zdtm/static/socket-tcp-closed FAIL at hook --post-start #########
>  Running zdtm/static/socket-tcp-closed.hook(--clean)
>    File "zdtm/static/socket-tcp-closed.hook", line 16
>      except OSError, e:
>                    ^
>  SyntaxError: invalid syntax
>  Traceback (most recent call last):
>    File "zdtm.py", line 1921, in <module>
>      do_run_test(tinfo[0], tinfo[1], tinfo[2], tinfo[3])
>    File "zdtm.py", line 1388, in do_run_test
>      try_run_hook(t, ["--clean"])
>    File "zdtm.py", line 1053, in try_run_hook
>      raise test_fail_exc("hook " + " ".join(args))
>  __main__.test_fail_exc: <__main__.test_fail_exc instance at 0x76294468>

Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-04-17 18:35:58 +03:00
Pavel Emelyanov
e77d36c375 crit: Beautify unix names recode
Unix socket name can be a string with any bytes in it. So to
print the name we use base64 encoding. Doing so doesn't allow
to see the socket name when it contains only printable chars.

So here's the custom encoding for bytes fields, that can be
used for custom conversion.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-04-11 09:01:11 +03:00
Pavel Emelyanov
5e3509ba16 crit: Decode some numbers into strings
There are several places in image files, where we store
integers, but these numbers actually mean some string.
E.g. socket families, states and types and tasks states.

So here's the (criu).dict option for such fields that
helps to convert the numbers into strings and back.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-04-11 09:01:11 +03:00
Kir Kolyshkin
ab90777ca1 Makefiles: protect from % rules, don't rebuild
GNU make tries to rebuild any makefiles it uses. While in general it's
a good idea (and it is used e.g. in autoconf-based builds), in our case
it is not necessary, as all the makefiles are static.

More to say, as we have a few "match anything" rules for subdirectories,
Makefiles in these subdirs are also matching these rules, which leads to
excessive (re)building while a particular makefile is needed.

Protect such Makefiles with explicit (or pattern) rules, so make knows
it should do nothing to rebuild those.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-15 09:36:08 +03:00
Kir Kolyshkin
85b04c8bfd Makefiles: nuke $(SRC_DIR)
As all builds are done from top source dir, there is no need
to have SRC_DIR.

Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-15 09:36:08 +03:00
Kir Kolyshkin
2a9d9c6615 lib Makefiles: integrate
Our whole system of Makefiles are integrated from top to bottom,
meaning:

 1. The paths in sub-makefiles are relative to the top source dir.
 2. Sub-makefiles are executed via make $(build)=<SUBDIR> <TARGET>

For some reason, makefiles under lib/ are the exclusion. Let's fix it.

Side effect: you can now build any individual target under lib/,
for example, "make lib/c/libcriu.so" works.

[v2: use the .FORCE, thanks to dsafonov@]

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-06 20:44:07 +03:00
Pavel Emelyanov
9fe7ccca6e py: Fix resp.errno access
There's no such field in resp, only cr_errno

travis-ci: success for py: Fix resp.errno access
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Acked-by: Andrei Vagin <avagin@virtuozzo.com>
2016-12-21 11:23:02 +03:00
Tycho Andersen
f3e412f900 python lib: rename rpc.py to rpc_pb2.py
Unfortunately, newer versions of protobuf check that the file suffix ends
in _pb2.py:

sudo ./zdtm.py run -t zdtm/static/apparmor_stacking
Traceback (most recent call last):
  File "./zdtm.py", line 23, in <module>
    import criu as crpc
  File "/home/ubuntu/criu/test/criu.py", line 12, in <module>
    import rpc
  File "/home/ubuntu/criu/test/rpc.py", line 36, in <module>
    type=None),
  File "/usr/lib/python2.7/dist-packages/google/protobuf/descriptor.py", line 652, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors should not be created directly, but only retrieved from their parent.

v2: fix up the clean target, and remove some comments that were about the
    old rename

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
CC: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-10-10 12:49:28 +03:00
Stanislav Kinsburskiy
4d31b38a0d protobuf: autofs entry introduced
This entry will be used to carry all the autofs parameters, required to
restore mount point.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-07-05 23:06:58 +03:00
Pavel Emelyanov
4ead159258 crit: Show no payload for image objects
In some images there can be quite a long "payload" -- some
raw data that is represented by base64 encoding. If we want
to explore huge images reading tons of base64 symbols can
be quite time consuming :) E.g. I a 1.5 gigs image with sysv
shmem was sent to me some time ago for investigation %)

So here is the --nopl argument for show action (decode should
produce encode-able image, so payload there is needed) that
just shows the amount of bytes in payload (if any).

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-05-30 13:47:54 +03:00
Cyrill Gorcunov
ebc3421df2 tty: Write unread pty buffers on post dump stage
Updated version attached.

>From 6c0e1522e01e01aa89861862fbdf039a0892b89b Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov@openvz.org>
Date: Tue, 12 Apr 2016 20:00:24 +0300
Subject: [PATCH 1/2] tty: Write unread pty buffers on post dump stage

When unread data present on peers we currently simply ignore it but
actually we can try to fetch it in non(that)destructive way.

For this sake at the end of dump procedure (because fetching
queued data may go wrong and we will have to write it back,
which is heavy, and we need all ttys under our hands)
we walk over all collected TTYs and link PTYs peers which
indices are matching. Note to not overload tty_dump_info we
reuse @list member for new @all_ptys list.

Once link established we literally read queued data and flush
it into new tty-data.img. If something go wrong at this moment,
we stop reading queued data but walk back over already queued
ones and write them back to restore former state. Same applies
if the dump has been requested to leave task alive.

On restore we link peers back and write queued data once
peer back to live.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-05-27 13:39:00 +03:00