Skip to content

Commit

Permalink
Merge branch 'checkpoint-restore:criu-dev' into fdavid/cap-buffer-size
Browse files Browse the repository at this point in the history
  • Loading branch information
fdavid-amd committed Oct 26, 2023
2 parents 91205ae + c474816 commit 918b1cc
Show file tree
Hide file tree
Showing 82 changed files with 635 additions and 282 deletions.
4 changes: 2 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ task:
ln -sf /usr/include/google/protobuf/descriptor.proto images/google/protobuf/descriptor.proto
dnf config-manager --set-enabled crb # Same as CentOS 8 powertools
dnf -y install epel-release epel-next-release
dnf -y install --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python-devel python-PyYAML python-protobuf python-junit_xml python3-importlib-metadata python-flake8 xmlto
dnf -y install --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python-devel python-PyYAML python-protobuf python-junit_xml python3-importlib-metadata python-flake8 xmlto libdrm-devel
systemctl stop sssd
# Even with selinux in permissive mode the selinux tests will be executed.
# The Cirrus CI user runs as a service from selinux point of view and is
Expand Down Expand Up @@ -108,7 +108,7 @@ task:
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm || :
yum install -y dnf-plugins-core
yum config-manager --set-enabled powertools
yum install -y --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python3-devel python3-flake8 python3-PyYAML python3-protobuf python3-importlib-metadata python3-junit_xml xmlto
yum install -y --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python3-devel python3-flake8 python3-PyYAML python3-protobuf python3-importlib-metadata python3-junit_xml xmlto libdrm-devel
alternatives --set python /usr/bin/python3
systemctl stop sssd
# Even with selinux in permissive mode the selinux tests will be executed
Expand Down
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma # Unknown to clang-format-4.0
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 120
ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false # Unknown to clang-format-4.0
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Expand Down
24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ ifeq ($(ARCH),arm)
ARMV := $(shell echo $(SUBARCH) | sed -nr 's/armv([[:digit:]]).*/\1/p; t; i7')

ifeq ($(ARMV),6)
USERCFLAGS += -march=armv6
ARCHCFLAGS += -march=armv6
endif

ifeq ($(ARMV),7)
USERCFLAGS += -march=armv7-a+fp
ARCHCFLAGS += -march=armv7-a+fp
endif

ifeq ($(ARMV),8)
# Running 'setarch linux32 uname -m' returns armv8l on travis aarch64.
# This tells CRIU to handle armv8l just as armv7hf. Right now this is
# only used for compile testing. No further verification of armv8l exists.
USERCFLAGS += -march=armv7-a
ARCHCFLAGS += -march=armv7-a
ARMV := 7
endif

Expand Down Expand Up @@ -159,12 +159,12 @@ export GMON GMONLDOPT
endif

AFLAGS += -D__ASSEMBLY__
CFLAGS += $(USERCFLAGS) $(WARNINGS) $(DEFINES) -iquote include/
CFLAGS += $(USERCFLAGS) $(ARCHCFLAGS) $(WARNINGS) $(DEFINES) -iquote include/
HOSTCFLAGS += $(WARNINGS) $(DEFINES) -iquote include/
export AFLAGS CFLAGS USERCLFAGS HOSTCFLAGS

# Default target
all: flog criu lib
all: flog criu lib crit
.PHONY: all

#
Expand Down Expand Up @@ -298,9 +298,9 @@ clean mrproper:
$(Q) $(MAKE) $(build)=criu $@
$(Q) $(MAKE) $(build)=soccr $@
$(Q) $(MAKE) $(build)=lib $@
$(Q) $(MAKE) $(build)=crit $@
$(Q) $(MAKE) $(build)=compel $@
$(Q) $(MAKE) $(build)=compel/plugins $@
$(Q) $(MAKE) $(build)=lib $@
.PHONY: clean mrproper

clean-amdgpu_plugin:
Expand Down Expand Up @@ -347,6 +347,10 @@ amdgpu_plugin: criu
$(Q) $(MAKE) -C plugins/amdgpu all
.PHONY: amdgpu_plugin

crit: lib
$(Q) $(MAKE) -C crit
.PHONY: crit

#
# Generating tar requires tag matched CRIU_VERSION.
# If not found then simply use GIT's describe with
Expand Down Expand Up @@ -412,6 +416,7 @@ help:
@echo ' Targets:'
@echo ' all - Build all [*] targets'
@echo ' * criu - Build criu'
@echo ' * crit - Build crit'
@echo ' zdtm - Build zdtm test-suite'
@echo ' docs - Build documentation'
@echo ' install - Install CRIU (see INSTALL.md)'
Expand All @@ -435,11 +440,12 @@ lint:
flake8 --config=scripts/flake8.cfg test/zdtm.py
flake8 --config=scripts/flake8.cfg test/inhfd/*.py
flake8 --config=scripts/flake8.cfg test/others/rpc/config_file.py
flake8 --config=scripts/flake8.cfg lib/py/images/pb2dict.py
flake8 --config=scripts/flake8.cfg lib/py/images/images.py
flake8 --config=scripts/flake8.cfg lib/pycriu/images/pb2dict.py
flake8 --config=scripts/flake8.cfg lib/pycriu/images/images.py
flake8 --config=scripts/flake8.cfg scripts/criu-ns
flake8 --config=scripts/flake8.cfg test/others/criu-ns/run.py
flake8 --config=scripts/flake8.cfg crit/setup.py
flake8 --config=scripts/flake8.cfg crit/*.py
flake8 --config=scripts/flake8.cfg crit/crit/*.py
flake8 --config=scripts/flake8.cfg scripts/uninstall_module.py
flake8 --config=scripts/flake8.cfg coredump/ coredump/coredump
flake8 --config=scripts/flake8.cfg scripts/github-indent-warnings.py
Expand Down
7 changes: 6 additions & 1 deletion Makefile.install
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ install-lib: lib
$(Q) $(MAKE) $(build)=lib install
.PHONY: install-lib

install-crit: lib
$(Q) $(MAKE) $(build)=crit install
.PHONY: install-crit

install-criu: criu
$(Q) $(MAKE) $(build)=criu install
.PHONY: install-criu
Expand All @@ -50,12 +54,13 @@ install-compel: $(compel-install-targets)
$(Q) $(MAKE) $(build)=compel/plugins install
.PHONY: install-compel

install: install-man install-lib install-criu install-compel install-amdgpu_plugin ;
install: install-man install-lib install-crit install-criu install-compel install-amdgpu_plugin ;
.PHONY: install

uninstall:
$(Q) $(MAKE) -C Documentation $@
$(Q) $(MAKE) $(build)=lib $@
$(Q) $(MAKE) $(build)=crit $@
$(Q) $(MAKE) $(build)=criu $@
$(Q) $(MAKE) $(build)=compel $@
$(Q) $(MAKE) $(build)=compel/plugins $@
Expand Down
68 changes: 47 additions & 21 deletions compel/arch/ppc64/src/lib/infect.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "log.h"
#include "common/bug.h"
#include "common/page.h"
#include "common/err.h"
#include "infect.h"
#include "infect-priv.h"

Expand Down Expand Up @@ -303,33 +304,58 @@ static int get_tm_regs(pid_t pid, user_fpregs_struct_t *fpregs)
return -1; /* still failing the checkpoint */
}

static int __get_task_regs(pid_t pid, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs)
{
pr_info("Dumping GP/FPU registers for %d\n", pid);
/*
* This is inspired by kernel function check_syscall_restart in
* arch/powerpc/kernel/signal.c
*/

/*
* This is inspired by kernel function check_syscall_restart in
* arch/powerpc/kernel/signal.c
*/
#ifndef TRAP
#define TRAP(r) ((r).trap & ~0xF)
#endif

if (TRAP(*regs) == 0x0C00 && regs->ccr & 0x10000000) {
/* Restart the system call */
switch (regs->gpr[3]) {
case ERESTARTNOHAND:
case ERESTARTSYS:
case ERESTARTNOINTR:
regs->gpr[3] = regs->orig_gpr3;
regs->nip -= 4;
break;
case ERESTART_RESTARTBLOCK:
pr_warn("Will restore %d with interrupted system call\n", pid);
regs->gpr[3] = EINTR;
break;
}
static bool trap_is_scv(user_regs_struct_t *regs)
{
return TRAP(*regs) == 0x3000;
}

static bool trap_is_syscall(user_regs_struct_t *regs)
{
return trap_is_scv(regs) || TRAP(*regs) == 0x0C00;
}

static void handle_syscall(pid_t pid, user_regs_struct_t *regs)
{
unsigned long ret = regs->gpr[3];

if (trap_is_scv(regs)) {
if (!IS_ERR_VALUE(ret))
return;
ret = -ret;
} else if (!(regs->ccr & 0x10000000)) {
return;
}

/* Restart or interrupt the system call */
switch (ret) {
case ERESTARTNOHAND:
case ERESTARTSYS:
case ERESTARTNOINTR:
regs->gpr[3] = regs->orig_gpr3;
regs->nip -= 4;
break;
case ERESTART_RESTARTBLOCK:
pr_warn("Will restore %d with interrupted system call\n", pid);
regs->gpr[3] = trap_is_scv(regs) ? -EINTR : EINTR;
break;
}
}

static int __get_task_regs(pid_t pid, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs)
{
pr_info("Dumping GP/FPU registers for %d\n", pid);

if (trap_is_syscall(regs))
handle_syscall(pid, regs);

/* Resetting trap since we are now coming from user space. */
regs->trap = 0;
Expand Down
2 changes: 1 addition & 1 deletion compel/plugins/std/infect.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static struct rt_sigframe *sigframe;
*/
static unsigned __page_size;

unsigned __attribute((weak)) page_size(void)
unsigned long __attribute((weak)) page_size(void)
{
return __page_size;
}
Expand Down
2 changes: 1 addition & 1 deletion coredump/pycriu
2 changes: 2 additions & 0 deletions crit/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
crit.egg-info/
build/
dist/
version.py
40 changes: 40 additions & 0 deletions crit/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
PYTHON_EXTERNALLY_MANAGED := $(shell $(PYTHON) -c 'import os, sysconfig; print(int(os.path.isfile(os.path.join(sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED"))))')
PIP_BREAK_SYSTEM_PACKAGES := 0

VERSION_FILE := $(if $(obj),$(addprefix $(obj)/,crit/version.py),crit/version.py)

all-y += ${VERSION_FILE}
cleanup-y += ${VERSION_FILE}

${VERSION_FILE}:
$(Q) echo "__version__ = '${CRIU_VERSION}'" > $@

install: ${VERSION_FILE}
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP INSTALL crit: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make install"
else
$(E) " INSTALL " crit
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
endif
else
$(E) " INSTALL " crit
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
endif
.PHONY: install

uninstall:
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP UNINSTALL crit: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make uninstall"
else
$(E) " UNINSTALL" crit
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
endif
else
$(E) " UNINSTALL" crit
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
endif
.PHONY: uninstall
1 change: 1 addition & 0 deletions crit/crit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .version import __version__
19 changes: 10 additions & 9 deletions lib/py/cli.py → crit/crit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os

import pycriu
from . import __version__


def inf(opts):
Expand Down Expand Up @@ -41,9 +42,9 @@ def decode(opts):
try:
img = pycriu.images.load(inf(opts), opts['pretty'], opts['nopl'])
except pycriu.images.MagicException as exc:
print("Unknown magic %#x.\n"\
"Maybe you are feeding me an image with "\
"raw data(i.e. pages.img)?" % exc.magic, file=sys.stderr)
print("Unknown magic %#x.\n"
"Maybe you are feeding me an image with "
"raw data(i.e. pages.img)?" % exc.magic, file=sys.stderr)
sys.exit(1)

if opts['pretty']:
Expand All @@ -59,9 +60,9 @@ def encode(opts):
try:
img = json.load(inf(opts))
except UnicodeDecodeError:
print("Cannot read JSON.\n"\
"Maybe you are feeding me an image with protobuf data? "\
"Encode expects JSON input.", file=sys.stderr)
print("Cannot read JSON.\n"
"Maybe you are feeding me an image with protobuf data? "
"Encode expects JSON input.", file=sys.stderr)
sys.exit(1)
pycriu.images.dump(img, outf(opts, False))

Expand Down Expand Up @@ -131,7 +132,7 @@ def ftype_find_in_files(opts, ft, fid):
if files_img is None:
try:
files_img = pycriu.images.load(dinf(opts, "files.img"))['entries']
except:
except Exception:
files_img = []

if len(files_img) == 0:
Expand Down Expand Up @@ -364,6 +365,7 @@ def main():
desc = 'CRiu Image Tool'
parser = argparse.ArgumentParser(
description=desc, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--version', action='version', version=__version__)

subparsers = parser.add_subparsers(
help='Use crit CMD --help for command-specific help')
Expand All @@ -373,8 +375,7 @@ def main():
'decode', help='convert criu image from binary type to json')
decode_parser.add_argument(
'--pretty',
help=
'Multiline with indents and some numerical fields in field-specific format',
help='Multiline with indents and some numerical fields in field-specific format',
action='store_true')
decode_parser.add_argument(
'-i',
Expand Down
1 change: 0 additions & 1 deletion crit/pycriu

This file was deleted.

23 changes: 21 additions & 2 deletions crit/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
[build-system]
# Minimum requirements for the build system to execute.
requires = ["setuptools", "wheel"] # PEP 508 specifications.
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "crit"
description = "CRiu Image Tool"
authors = [
{name = "CRIU team", email = "criu@openvz.org"},
]
license = {text = "GPLv2"}
dynamic = ["version"]
requires-python = ">=3.6"

[project.scripts]
crit = "crit.__main__:main"

[tool.setuptools]
packages = ["crit"]

[tool.setuptools.dynamic]
version = {attr = "crit.__version__"}
7 changes: 0 additions & 7 deletions crit/requirements.txt

This file was deleted.

Loading

0 comments on commit 918b1cc

Please sign in to comment.