Commit 0758b4c2 authored by Pavel Emelyanov's avatar Pavel Emelyanov

test: Test and example how to dump namespace with macvlan

One note -- the macvlan's index _does_ change. We should
either patch iproute2 or use raw kernel API to preserve it.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent b88d8e1b
all: mvlink.so
mvlink.so: mvlink.c
gcc -g -Werror -Wall -shared -nostartfiles mvlink.c -o mvlink.so -iquote ../../include -fPIC
#!/bin/bash
# $1 -- link name
# $2 -- file with namespace pid
if [ "$CRTOOLS_SCRIPT_ACTION" == "setup-namespaces" ]; then
$(dirname $0)/addmv_raw.sh $1 $(cat $2)
else
exit 0
fi
#!/bin/bash
# $1 -- link name
# $2 -- pid of task in namespace
set -x
$ip link add link eth0 name $1 type macvlan || exit 1
$ip link set $1 netns $2
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include "criu-plugin.h"
#include "criu-log.h"
extern cr_plugin_init_t cr_plugin_init;
extern cr_plugin_dump_ext_link_t cr_plugin_dump_ext_link;
int cr_plugin_init(void)
{
pr_info("Initialized macvlan dumper\n");
return 0;
}
int cr_plugin_dump_ext_link(int index, int type, char *kind)
{
if (strcmp(kind, "macvlan"))
return -ENOTSUP;
else {
pr_info("Dump %d macvlan\n", index);
return 0;
}
}
#!/bin/bash
ip=${CR_IP_TOOL:-xip}
mvln="mv0"
finf="finish"
outf="ns_output"
pidf="ns_pid"
criu="../../criu"
export ip
export mvln
export finf
export outf
export pidf
function fail {
$ip link del $mvln
touch $finf
echo $@
exit 1
}
# Build the mvlink plugin
make
set -x
rm -f "$finf" "$outf" "$pidf"
rm -rf "dump"
# Unshare netns. The run_ns will exit once ns is spawned.
unshare --net ./run_ns.sh
nspid=$(cat $pidf)
ps $nspid
# Create and push macvlan device into it. CRIU doesn't support
# macvlans treating them as external devices.
./addmv_raw.sh $mvln $nspid || fail "Can't setup namespace"
# Dump
sleep 1
mkdir dump
$criu dump -t $nspid -D dump/ -o dump.log -v4 --lib $(pwd) || fail "Can't dump namespace"
# Restore
# Ask for the pid (shouldn't change, so just as an example), ask to call
# script that will put macvlan device back into namespace
sleep 1
rm -f $pidf
$criu restore -D dump/ -o restore.log -v4 --pidfile $(pwd)/$pidf --action-script "$(pwd)/addmv.sh $mvln $(pwd)/$pidf" -d || fail "Can't restore namespaces"
# Finish and check results
touch $finf
set +x
while ! egrep 'PASS|FAIL' $outf; do
echo "Waiting"
sleep 1
done
#!/bin/bash
set -x
echo "NS: $$" >> $outf
echo "Links before:" >> $outf
$ip link list >> $outf 2>&1
# Detach from session, terminal and parent
setsid ./run_wait.sh < /dev/null >> $outf 2>&1 &
# Keep pid for future reference :)
echo "$!" > $pidf
exit 0
#!/bin/bash
echo "Wait: $$"
while [ ! -e "$finf" ]; do
echo "WAIT ($$)"
sleep 1;
done
echo "Links after:"
$ip link list
# The mvln device (exported from run.sh) should exits in
# namespace after we get restored
echo "Check for $mvln:"
$ip link list $mvln && echo "PASS" || echo "FAIL"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment