mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 14:25:49 +00:00
test: generate a random tree of mounts
Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
5f18aa4ddf
commit
fe1c16a502
31
test/mounts/mounts.py
Executable file
31
test/mounts/mounts.py
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
import os
|
||||||
|
import tempfile, random
|
||||||
|
|
||||||
|
def mount(src, dst, shared, private, slave):
|
||||||
|
cmd = "mount"
|
||||||
|
if shared:
|
||||||
|
cmd += " --make-shared"
|
||||||
|
if private:
|
||||||
|
cmd += " --make-private"
|
||||||
|
if slave:
|
||||||
|
cmd += " --make-slave"
|
||||||
|
if src:
|
||||||
|
cmd += " --bind '%s' '%s'" % (src, dst)
|
||||||
|
else:
|
||||||
|
cmd += " -t tmpfs none '%s'" % (dst)
|
||||||
|
|
||||||
|
print cmd
|
||||||
|
ret = os.system(cmd)
|
||||||
|
if ret:
|
||||||
|
print "failed"
|
||||||
|
|
||||||
|
root = tempfile.mkdtemp(prefix = "root.mount", dir = "/tmp")
|
||||||
|
mount(None, root, 1, 0, 0)
|
||||||
|
mounts = [root]
|
||||||
|
|
||||||
|
for i in xrange(10):
|
||||||
|
dstdir = random.choice(mounts)
|
||||||
|
dst = tempfile.mkdtemp(prefix = "mount", dir = dstdir)
|
||||||
|
src = random.choice(mounts + [None])
|
||||||
|
mount(src, dst, random.randint(0,100) > 50, random.randint(0,100) > 90, random.randint(0,100) > 50)
|
||||||
|
mounts.append(dst)
|
27
test/mounts/mounts.sh
Executable file
27
test/mounts/mounts.sh
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
[ -z "$INMNTNS" ] && {
|
||||||
|
export INMNTNS=`pwd`
|
||||||
|
export INMNTNS_PID=$$
|
||||||
|
unshare -m -- setsid bash -x "$0" "$@" < /dev/null &> mounts.log &
|
||||||
|
echo $! > mounts.pid
|
||||||
|
while :; do
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
cd $INMNTNS
|
||||||
|
|
||||||
|
mount --make-rprivate /
|
||||||
|
|
||||||
|
for i in `cat /proc/self/mounts | awk '{ print $2 }'`; do
|
||||||
|
[ '/' = "$i" ] && continue
|
||||||
|
[ '/proc' = "$i" ] && continue
|
||||||
|
[ '/dev' = "$i" ] && continue
|
||||||
|
echo $i
|
||||||
|
umount -l $i
|
||||||
|
done
|
||||||
|
|
||||||
|
python mounts.py
|
||||||
|
kill $INMNTNS_PID
|
||||||
|
while :; do
|
||||||
|
sleep 10
|
||||||
|
done
|
24
test/mounts/run.sh
Executable file
24
test/mounts/run.sh
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
CRIU=../../criu
|
||||||
|
set -x
|
||||||
|
|
||||||
|
mkdir -p dump
|
||||||
|
|
||||||
|
./mounts.sh
|
||||||
|
pid=`cat mounts.pid`
|
||||||
|
kill -0 $pid || exit
|
||||||
|
|
||||||
|
cat /proc/$pid/mountinfo | sort -k 4
|
||||||
|
echo "Suspend server"
|
||||||
|
${CRIU} dump -D dump -o dump.log -t $pid -v4 || {
|
||||||
|
cat dump/dump.log | grep Error
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
echo "Resume server"
|
||||||
|
${CRIU} restore -d -D dump -o restore.log -v4 || {
|
||||||
|
cat dump/dump.log | grep Error
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
cat /proc/$pid/mountinfo | sort -k 4
|
||||||
|
kill $pid
|
Reference in New Issue
Block a user