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

73 Commits

Author SHA1 Message Date
Tycho Andersen
8d992a680e lsm: support checkpoint/restore of stacked apparmor profiles
Support for apparmor namespaces and stacking is coming to Ubuntu kernels in
16.10, and should hopefully be upstreamed Soon (TM) :).

The basic idea is similar to how cgroups are done: we can restore the
apparmor namespace and profile blobs independently of the tasks, and then
at the end we can just set the task's label appropriately. This means the
code that moves tasks under a label stays the same, and the only new code
is the stuff that dumps and restores the policy blobs that are in the
namespace that were loaded by the container.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-09-03 10:31:00 -07:00
Adrian Reber
7e86519fe3 lib: fix crit-recode msgque errors in Jenkins
b'test/dump/zdtm/static/msgque/63/1/ipcns-msg-11.img'  encode fails: expected bytes-like object, not str
b'test/dump/zdtm/static/msgque/63/1/ipcns-msg-11.img' pretty  encode fails: expected bytes-like object, not str
FAIL

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-09-03 10:31:00 -07:00
Adrian Reber
fa9acb9dc7 lib: fix broken crit-recode test
Signed-off-by: Adrian Reber <areber@redhat.com>
2021-09-03 10:31:00 -07:00
Pavel Tikhomirov
2ebb1c7419 crit: fix error on memfd files parsing
Else we get error:

[root@fedora criu]# crit/crit x test/dump/zdtm/static/memfd00/56/1/ mems
...
Traceback (most recent call last):
  File "/home/snorch/devel/ms/criu/crit/crit", line 6, in <module>
    cli.main()
  File "/home/snorch/devel/ms/criu/crit/pycriu/cli.py", line 430, in main
    opts["func"](opts)
  File "/home/snorch/devel/ms/criu/crit/pycriu/cli.py", line 361, in explore
    explorers[opts['what']](opts)
  File "/home/snorch/devel/ms/criu/crit/pycriu/cli.py", line 283, in explore_mems
    fn = ' ' + get_file_str(opts, {
  File "/home/snorch/devel/ms/criu/crit/pycriu/cli.py", line 214, in get_file_str
    f = ft['get'](opts, ft, fd['id'])
  File "/home/snorch/devel/ms/criu/crit/pycriu/cli.py", line 165, in ftype_reg
    rf = ftype_find_in_image(opts, ft, fid, 'reg-files.img')
  File "/home/snorch/devel/ms/criu/crit/pycriu/cli.py", line 154, in ftype_find_in_image
    return f[ft['field']]
KeyError: 'reg'

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
2021-09-03 10:31:00 -07:00
fu.lin
d3ce492cc2 pycrit: fix the broken of cli the crit show xxx.img
It will broken when the cli `crit show ipcns-shm-9.img` is executed, msg:
  {
      "magic": "IPCNS_SHM",
      "entries": [
          {
              "desc": {
                  "key": 0,
                  "uid": 0,
                  "gid": 0,
                  "cuid": 0,
                  "cgid": 0,
                  "mode": 438,
                  "id": 0
              },
              "size": 1048576,
              "in_pagemaps": true,
              "extra": Traceback (most recent call last):
    File "/usr/bin/crit", line 6, in <module>
      cli.main()
    File "/usr/lib/python3/dist-packages/pycriu/cli.py", line 412, in main
      opts["func"](opts)
    File "/usr/lib/python3/dist-packages/pycriu/cli.py", line 45, in decode
      json.dump(img, f, indent=indent)
    File "/usr/lib/python3.9/json/__init__.py", line 179, in dump
      for chunk in iterable:
    File "/usr/lib/python3.9/json/encoder.py", line 431, in _iterencode
      yield from _iterencode_dict(o, _current_indent_level)
    File "/usr/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict
      yield from chunks
    File "/usr/lib/python3.9/json/encoder.py", line 325, in _iterencode_list
      yield from chunks
    File "/usr/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict
      yield from chunks
    File "/usr/lib/python3.9/json/encoder.py", line 438, in _iterencode
      o = _default(o)
    File "/usr/lib/python3.9/json/encoder.py", line 179, in default
      raise TypeError(f'Object of type {o.__class__.__name__} '
  TypeError: Object of type bytes is not JSON serializable

This is caused by `img['magic'][0]['extra']` which is bytes. I find
other load condtions, fix them at the same time.

Signed-off-by: fu.lin <fulin10@huawei.com>
2021-09-03 10:31:00 -07:00
Radostin Stoyanov
e393001095 lib/cli.py: Open explore file as a binary
Fixes #1484

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
2021-09-03 10:31:00 -07:00
Adrian Reber
13e6e68998 lib: also handle extra pipe data correctly
CI sometimes errors out encoding/decoding extra pipe data.

This should fix extra pipe data for Python 3 and still keep it working
on Python 2.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-09-03 10:31:00 -07:00
Adrian Reber
bf9e502c6f lib: print nice error if crit gets wrong input
Signed-off-by: Adrian Reber <areber@redhat.com>
2021-09-03 10:31:00 -07:00
Adrian Reber
bf80fee4f4 lib: correctly handle stdin/stdout (Python 3)
This changes stdin to be opened as binary if the input is not a tty.

This changes stdout to be opened as binary if encoding or if the output
is not a tty.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-09-03 10:31:00 -07:00
Adrian Reber
b82f222d6b lib: fix crit-recode fix for Python 2
The recent fix to make Jenkins run crit-recode again broke
Python 2 support (because Python 2 based CI was not running).

This should fix the Python 2 based test run.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-09-03 10:31:00 -07:00
Adrian Reber
248b773676 lib: correctly handle padding of dump images
With the switch to Python3 and binary output it is not possible to use
code like: 'f.write('\0' * (rounded - size))'. Switching to binary
helps.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-09-03 10:31:00 -07:00
Adrian Reber
abe3405b20 lib: fromstring() and tostring() are deprecated
fromstring() and tostring() are deprecated since Python 3.2 and have
been removed in 3.9. Both functions were just aliases and this patch
changes images.py to directly call fromybytes() and tobytes().

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-09-03 10:31:00 -07:00
Adrian Reber
71013465b8 lib: fix recode errors seen in Jenkins
Although we are running crit-recode.py also in all CI runs we never seen
following error except in Jenkins:

Traceback (most recent call last):
  File "/usr/lib/python3.8/base64.py", line 510, in _input_type_check
    m = memoryview(s)
TypeError: memoryview: a bytes-like object is required, not 'str'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./test/crit-recode.py", line 25, in recode_and_check
    r_img = pycriu.images.dumps(pb)
  File "/var/lib/jenkins/workspace/Q/test/pycriu/images/images.py", line 635, in dumps
    dump(img, f)
  File "/var/lib/jenkins/workspace/Q/test/pycriu/images/images.py", line 626, in dump
    handler.dump(img['entries'], f)
  File "/var/lib/jenkins/workspace/Q/test/pycriu/images/images.py", line 289, in dump
    f.write(base64.decodebytes(item['extra']))
  File "/usr/lib/python3.8/base64.py", line 545, in decodebytes
    _input_type_check(s)
  File "/usr/lib/python3.8/base64.py", line 513, in _input_type_check
    raise TypeError(msg) from err
TypeError: expected bytes-like object, not str

This commit fixes this by encoding the string to bytes.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-09-03 10:31:00 -07:00
Dmitry Safonov
ed0f4608f4 lib/cli.py: Open out file as a binary
python3 fails to encode image with the following:

> [dima@Mindolluin criu]$ ./crit/crit encode -i tmp -o tmp.1
> Traceback (most recent call last):
>   File "/home/dima/src/criu/./crit/crit", line 6, in <module>
>     cli.main()
>   File "/home/dima/src/criu/crit/pycriu/cli.py", line 410, in main
>     opts["func"](opts)
>   File "/home/dima/src/criu/crit/pycriu/cli.py", line 50, in encode
>     pycriu.images.dump(img, outf(opts))
>   File "/home/dima/src/criu/crit/pycriu/images/images.py", line 617, in dump
>     f.write(struct.pack('i', magic.by_name['IMG_COMMON']))
> TypeError: write() argument must be str, not bytes

Opening the output file as binary seems to help.

Signed-off-by: Dmitry Safonov <dima@arista.com>
2021-09-03 10:31:00 -07:00
Adrian Reber
1d403eb18a Use 'is None' instead of '== None'
Signed-off-by: Adrian Reber <areber@redhat.com>
2021-09-03 10:31:00 -07:00
Adrian Reber
1543527bf9 lib/py: remove unused variable
Signed-off-by: Adrian Reber <areber@redhat.com>
2021-09-03 10:31:00 -07:00
Abhishek Vijeev
4b8186cb6e crit: add BPF map data decoding
This commit enables CRIT to decode the contents of a protobuf image
that stores information related to BPF map

Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
3d67e8a0d2 Makefiles: do not re-generate magic.py every time
I always wondered why re-running make on a criu checkout always prints
out

  GEN      magic.py

even if no file has changed. It seems the Makefile was looking for the
file in the wrong location. Providing the full path to the file will now
only rebuild magic.py if something actually changed that requires a
rebuild.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Otto Bittner
9ce4ed0935 python: Handle byte strings when converting protobuf to dict
Fixes #1165
Traceback (most recent call last):
  File "../criu/crit/crit-python3", line 6, in <module>
    cli.main()
  File "/home/xcv/repos/criu/crit/pycriu/cli.py", line 410, in main
    opts["func"](opts)
  File "/home/xcv/repos/criu/crit/pycriu/cli.py", line 43, in decode
    json.dump(img, f, indent=indent)
  File "/usr/lib/python3.8/json/__init__.py", line 179, in dump
    for chunk in iterable:
  File "/usr/lib/python3.8/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.8/json/encoder.py", line 325, in _iterencode_list
    yield from chunks
  File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.8/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/usr/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable

Co-authored-by: Julian <jb@futureplay.de>
Signed-off-by: Otto Bittner <otto-bittner@gmx.de>
2020-10-20 00:18:24 -07:00
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