1 |
#!/bin/sh -e |
2 |
|
3 |
pool=workshop |
4 |
|
5 |
size=60G |
6 |
vol_opt="-b 4k -s" |
7 |
#vol_opt="-b 4k -s -o compression=lz4" |
8 |
|
9 |
if [ -z "$1" ] ; then |
10 |
zfs list -r $pool/block |
11 |
echo |
12 |
test ! -z "/mnt/*" && df -h /mnt/* | grep -v aufs |
13 |
echo |
14 |
du -hcs /$pool/ganeti/export/* | cut -d/ -f1,5 |
15 |
exit 1 |
16 |
else |
17 |
instance=$1 |
18 |
fi |
19 |
|
20 |
umount /mnt/$instance || true |
21 |
zfs destroy $pool/block/$instance || true |
22 |
|
23 |
zfs create -V $size $vol_opt $pool/block/$instance |
24 |
|
25 |
test -d /mnt/$instance || mkdir /mnt/$instance |
26 |
|
27 |
wait_for() { |
28 |
echo -n "waiting for $1 " |
29 |
while [ ! -e $1 ] ; do |
30 |
echo -n . |
31 |
sleep 1 |
32 |
done |
33 |
echo " found" |
34 |
} |
35 |
|
36 |
wait_for /dev/zvol/$pool/block/$instance |
37 |
|
38 |
label=`echo $instance | cut -d. -f1` |
39 |
echo "label $label = $instance" |
40 |
|
41 |
time mkfs.ext4 -m 0 -L $label /dev/zvol/$pool/block/$instance |
42 |
|
43 |
wait_for /dev/disk/by-label/$label |
44 |
|
45 |
mount /dev/disk/by-label/$label /mnt/$instance/ |
46 |
cd /mnt/$instance/ |
47 |
dump=`ls /$pool/ganeti/export/$instance/*.disk0*.snap` |
48 |
ls -alh $dump |
49 |
zpool iostat 2 | tee /dev/shm/$instance & |
50 |
pid_iostat=$! |
51 |
( while true; do zfs list $pool/block/$instance ; sleep 10 ; done ) & |
52 |
pid_list=$! |
53 |
time restore rf $dump |
54 |
kill $pid_iostat |
55 |
kill $pid_list |
56 |
|
57 |
wc -l /dev/shm/$instance |
58 |
df -h /mnt/$instance |