-
Notifications
You must be signed in to change notification settings - Fork 6
/
replay-fsck-wrapper.sh
executable file
·67 lines (57 loc) · 1.47 KB
/
replay-fsck-wrapper.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
#!/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"
# Create a 1tb sparse file
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
dmsetup create $SNAPSHOTBASE --table "$ORIGIN_TABLE"
if [ $? -ne 0 ]
then
sleep 1
dmsetup create $SNAPSHOTBASE --table "$ORIGIN_TABLE" || \
_fail "failed to create snapshot base"
fi
dmsetup create $SNAPSHOTCOW --table "$COW_TABLE"
if [ $? -ne 0 ]
then
sleep 1
dmsetup create $SNAPSHOTCOW --table "$COW_TABLE" || \
_fail "failed to create snapshot"
fi
mount $TARGET $TEST_MNT || _fail "mount failed at entry $ENTRY"
umount $TEST_MNT
$FSCK -n $TARGET > fsck-output 2>&1 || _fail "fsck failed after mount"
dmsetup remove $SNAPSHOTCOW
if [ $? -ne 0 ]
then
sleep 1
dmsetup remove $SNAPSHOTCOW || _fail "failed to remove snapshot"
fi
dmsetup remove $SNAPSHOTBASE
if [ $? -ne 0 ]
then
sleep 1
dmsetup remove $SNAPSHOTBASE || _fail "failed to remove base"
fi
losetup -d $COW_LOOP_DEV
exit 0