Commit fe1c16a5 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

test: generate a random tree of mounts

Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 5f18aa4d
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)
[ -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
#!/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
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