-
Notifications
You must be signed in to change notification settings - Fork 6
/
replay-individual.sh
74 lines (64 loc) · 2.21 KB
/
replay-individual.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
. ./variables
SNAPSHOTBASE="replay-base"
SNAPSHOTCOW="replay-cow"
# Don't modify these
BLKSIZE=$(blockdev --getsz $REPLAYDEV)
ORIGIN_TABLE="0 $BLKSIZE snapshot-origin $REPLAYDEV"
COW_TABLE=
COW_LOOP_DEV=
_fail()
{
echo $1
if [ -n $SNAPDEV ]
then
dmsetup remove $SNAPSHOTCOW > /dev/null 2>&1
dmsetup remove $SNAPSHOTBASE > /dev/null 2>&1
fi
losetup -d $COW_LOOP_DEV > /dev/null 2>&1
exit 1
}
[ -z $LOGDEV ] && exit "Must set logdev and replaydev"
[ -z $REPLAYDEV ] && exit "Must set logdev and replaydev"
echo "creating snapshot base"
echo $ORIGIN_TABLE
# Create a 1tb sparse file
echo "setting up COW TABLE"
dd if=/dev/zero of=cow-dev bs=1M count=1 seek=1048576
COW_LOOP_DEV=$(losetup -f --show cow-dev)
COW_TABLE="0 $BLKSIZE snapshot /dev/mapper/$SNAPSHOTBASE $COW_LOOP_DEV N 8"
TARGET=/dev/mapper/$SNAPSHOTCOW
NUM_ENTRIES=$(./replay-log --log $LOGDEV --num-entries)
# Yes I know it's confusing, but START_MARK is where we want to start our log
# replay from, but --start-mark means start the log replay to replay-log,
# whereas we want to replay up to START_MARK and then carry on from there.
echo "replayin to mark"
ENTRY=$(./replay-log --log $LOGDEV --find --end-mark $START_MARK)
./replay-log --log $LOGDEV --replay $REPLAYDEV --limit $ENTRY || exit 1
let ENTRY+=1
while [ $ENTRY -lt $NUM_ENTRIES ];
do
echo "replaying entry $ENTRY"
./replay-log --limit 1 --log $LOGDEV --replay $REPLAYDEV \
--start $ENTRY || _fail "replay failed"
dmsetup create $SNAPSHOTBASE --table "$ORIGIN_TABLE"
if [ $? -ne 0 ]
then
# Sometimes this looping is too fast for device-mapper and
# we get a random EBUSY, so just sleep for a sec and try
# again.
sleep 1
dmsetup create $SNAPSHOTBASE --table "$ORIGIN_TABLE" || \
_fail "Couldn't dmsetup"
fi
dmsetup create $SNAPSHOTCOW --table "$COW_TABLE" || \
_fail "failed to create snapshot"
$FSCK $TARGET > /dev/null 2>&1 || _fail "fsck failed at entry $ENTRY"
mount $TARGET $TEST_MNT || _fail "mount failed at entry $ENTRY"
umount $TEST_MNT
$FSCK $TARGET > /dev/null 2>&1 || _fail "fsck failed after mount at " \
"entry $ENTRY"
dmsetup remove $SNAPSHOTCOW || _fail "failed to remove snapshot"
dmsetup remove $SNAPSHOTBASE || _fail "failed to remove base"
let ENTRY+=1
done