Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.16.1 release #1624

Merged
merged 7 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Documentation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ endif

FOOTER := footer.txt
SRC1 += crit.txt
ifeq ($(PYTHON),python3)
SRC1 += criu-ns.txt
endif
SRC1 += compel.txt
SRC8 += criu.txt
SRC := $(SRC1) $(SRC8)
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ lint:
shellcheck scripts/*.sh
shellcheck scripts/ci/*.sh scripts/ci/apt-install
shellcheck test/others/crit/*.sh
shellcheck test/others/libcriu/*.sh
shellcheck test/others/config-file/*.sh
# Do not append \n to pr_perror or fail
! git --no-pager grep -E '^\s*\<(pr_perror|fail)\>.*\\n"'
Expand Down
3 changes: 3 additions & 0 deletions criu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ install: $(obj)/criu
$(Q) install -m 644 $(UAPI_HEADERS) $(DESTDIR)$(INCLUDEDIR)/criu/
$(Q) mkdir -p $(DESTDIR)$(LIBEXECDIR)/criu/scripts
$(Q) install -m 755 scripts/systemd-autofs-restart.sh $(DESTDIR)$(LIBEXECDIR)/criu/scripts
ifeq ($(PYTHON),python3)
$(E) " INSTALL " scripts/criu-ns
$(Q) install -m 755 scripts/criu-ns $(DESTDIR)$(SBINDIR)
endif
.PHONY: install

uninstall:
Expand Down
91 changes: 91 additions & 0 deletions lib/c/criu.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ void criu_local_free_opts(criu_opts *opts)
}
opts->rpc->n_external = 0;

if (opts->rpc->join_ns) {
for (i = 0; i < opts->rpc->n_join_ns; i++) {
free(opts->rpc->join_ns[i]->ns);
free(opts->rpc->join_ns[i]->ns_file);
if (opts->rpc->join_ns[i]->extra_opt) {
free(opts->rpc->join_ns[i]->extra_opt);
}
free(opts->rpc->join_ns[i]);
}
}
opts->rpc->n_join_ns = 0;

if (opts->rpc->ps) {
free(opts->rpc->ps->address);
free(opts->rpc->ps);
Expand Down Expand Up @@ -1804,3 +1816,82 @@ int criu_set_network_lock(enum criu_network_lock_method method)
{
return criu_local_set_network_lock(global_opts, method);
}

int criu_local_join_ns_add(criu_opts *opts, const char *ns, const char *ns_file, const char *extra_opt)
{
int n_join_ns;
char *_ns = NULL, *_ns_file = NULL, *_extra_opt = NULL;
JoinNamespace **join_ns_arr, *join_ns = NULL;

if (!ns) {
fprintf(stderr, "ns parameter for join_ns is not specified");
goto err;
}

_ns = strdup(ns);
if (!_ns) {
perror("Can't allocate memory for ns");
goto err;
}

if (!ns_file) {
fprintf(stderr, "ns parameter for join_ns is not specified");
goto err;
}

_ns_file = strdup(ns_file);
if (!_ns_file) {
perror("Can't allocate memory for ns_file");
goto err;
}

if (extra_opt) {
_extra_opt = strdup(extra_opt);
if (!_extra_opt) {
perror("Can't allocate memory for extra_opt");
goto err;
}
}

join_ns = malloc(sizeof(JoinNamespace));
if (!join_ns) {
perror("Can't allocate memory for join_ns");
goto err;
}

n_join_ns = opts->rpc->n_join_ns + 1;
join_ns_arr = realloc(opts->rpc->join_ns, n_join_ns * sizeof(join_ns));
if (!join_ns_arr) {
perror("Can't allocate memory for join_ns_arr");
goto err;
}

join_namespace__init(join_ns);
join_ns->ns = _ns;
join_ns->ns_file = _ns_file;
if (_extra_opt) {
join_ns->extra_opt = _extra_opt;
}

join_ns_arr[n_join_ns - 1] = join_ns;
opts->rpc->join_ns = join_ns_arr;
opts->rpc->n_join_ns = n_join_ns;

return 0;

err:
if (_ns)
free(_ns);
if (_ns_file)
free(_ns_file);
if (_extra_opt)
free(_extra_opt);
if (join_ns)
free(join_ns);
return -1;
}

int criu_join_ns_add(const char *ns, const char *ns_file, const char *extra_opt)
{
return criu_local_join_ns_add(global_opts, ns, ns_file, extra_opt);
}
9 changes: 9 additions & 0 deletions lib/c/criu.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
extern "C" {
#endif

#define CRIU_LOG_UNSET (-1)
#define CRIU_LOG_MSG (0) /* Print message regardless of log level */
#define CRIU_LOG_ERROR (1) /* Errors only */
#define CRIU_LOG_WARN (2) /* Warnings */
#define CRIU_LOG_INFO (3) /* Informative */
#define CRIU_LOG_DEBUG (4) /* Debug only */

enum criu_service_comm { CRIU_COMM_SK, CRIU_COMM_FD, CRIU_COMM_BIN };

enum criu_cg_mode {
Expand Down Expand Up @@ -103,6 +110,7 @@ int criu_set_page_server_address_port(const char *address, int port);
int criu_set_pre_dump_mode(enum criu_pre_dump_mode mode);
void criu_set_pidfd_store_sk(int sk);
int criu_set_network_lock(enum criu_network_lock_method method);
int criu_join_ns_add(const char *ns, const char *ns_file, const char *extra_opt);

/*
* The criu_notify_arg_t na argument is an opaque
Expand Down Expand Up @@ -263,6 +271,7 @@ int criu_local_set_page_server_address_port(criu_opts *opts, const char *address
int criu_local_set_pre_dump_mode(criu_opts *opts, enum criu_pre_dump_mode mode);
void criu_local_set_pidfd_store_sk(criu_opts *opts, int sk);
int criu_local_set_network_lock(criu_opts *opts, enum criu_network_lock_method method);
int criu_local_join_ns_add(criu_opts *opts, const char *ns, const char *ns_file, const char *extra_opt);

void criu_local_set_notify_cb(criu_opts *opts, int (*cb)(char *action, criu_notify_arg_t na));

Expand Down
2 changes: 1 addition & 1 deletion scripts/criu-ns
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import ctypes
import ctypes.util
import errno
Expand Down
4 changes: 3 additions & 1 deletion test/others/libcriu/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ test_iters
test_notify
test_self
test_sub
wdir
test_join_ns
output/
libcriu.so.*
3 changes: 2 additions & 1 deletion test/others/libcriu/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
include ../../../../criu/Makefile.versions

TESTS += test_sub
TESTS += test_sub
TESTS += test_self
TESTS += test_notify
TESTS += test_iters
TESTS += test_errno
TESTS += test_join_ns

all: $(TESTS)
.PHONY: all
Expand Down
58 changes: 33 additions & 25 deletions test/others/libcriu/run.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,52 @@
#!/bin/bash

set -x
source ../env.sh || exit 1

MAIN_DIR=$(dirname "$0")
OUTPUT_DIR="${MAIN_DIR}/output"
TEST_DIR="${OUTPUT_DIR}/$1"
TEST_LOG="${TEST_DIR}/test.log"
DUMP_LOG="${TEST_DIR}/dump.log"
RESTORE_LOG="${TEST_DIR}/restore.log"

# shellcheck disable=1091
source "${MAIN_DIR}/../env.sh" || exit 1

echo "== Clean"
make clean
make libcriu
rm -rf wdir

echo "== Prepare"
mkdir -p wdir/i/
rm -rf "${OUTPUT_DIR}"

echo "== Run tests"
export LD_LIBRARY_PATH=.
export PATH="`dirname ${BASH_SOURCE[0]}`/../../../criu:$PATH"
export PATH="${MAIN_DIR}/../../../criu:${PATH}"

RESULT=0

function run_test {
run_test() {
echo "== Build $1"
if ! make $1; then
if ! make "$1"; then
echo "FAIL build $1"
echo "** Output of $1/test.log"
cat wdir/i/$1/test.log
echo "---------------"
if [ -f wdir/i/$1/dump.log ]; then
echo "** Contents of dump.log"
cat wdir/i/$1/dump.log
echo "---------------"
fi
if [ -f wdir/i/$1/restore.log ]; then
echo "** Contents of restore.log"
cat wdir/i/$1/restore.log
echo "---------------"
fi
RESULT=1;
else
echo "== Test $1"
mkdir wdir/i/$1/
if ! setsid ./$1 ${CRIU} wdir/i/$1/ < /dev/null &>> wdir/i/$1/test.log; then
mkdir -p "${TEST_DIR}"
if ! setsid ./"$1" "${CRIU}" "${TEST_DIR}" < /dev/null &>> "${TEST_LOG}"; then
echo "$1: FAIL"
echo "** Output of ${TEST_LOG}"
cat "${TEST_LOG}"
echo "---------------"
if [ -f "${DUMP_LOG}" ]; then
echo "** Contents of dump.log"
cat "${DUMP_LOG}"
echo "---------------"
fi
if [ -f "${RESTORE_LOG}" ]; then
echo "** Contents of restore.log"
cat "${RESTORE_LOG}"
echo "---------------"
fi
RESULT=1
fi
fi
Expand All @@ -48,13 +55,14 @@ function run_test {
run_test test_sub
run_test test_self
run_test test_notify
if [ "$(uname -m)" == "x86_64" ]; then
if [ "$(uname -m)" = "x86_64" ]; then
# Skip this on aarch64 as aarch64 has no dirty page tracking
run_test test_iters
fi
run_test test_errno
run_test test_join_ns

echo "== Tests done"
make libcriu_clean
[ $RESULT -eq 0 ] && echo "Success" || echo "FAIL"
exit $RESULT
[ "${RESULT}" -eq 0 ] && echo "Success" || echo "FAIL"
exit "${RESULT}"
4 changes: 2 additions & 2 deletions test/others/libcriu/test_iters.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int main(int argc, char **argv)
criu_set_service_binary(argv[1]);
criu_set_pid(pid);
criu_set_log_file("dump.log");
criu_set_log_level(4);
criu_set_log_level(CRIU_LOG_DEBUG);

open_imgdir();
ret = criu_dump_iters(next_iter);
Expand All @@ -121,7 +121,7 @@ int main(int argc, char **argv)

printf("--- Restore loop ---\n");
criu_init_opts();
criu_set_log_level(4);
criu_set_log_level(CRIU_LOG_DEBUG);
criu_set_log_file("restore.log");
criu_set_images_dir_fd(cur_imgdir);

Expand Down
Loading