summaryrefslogtreecommitdiffstats
path: root/tests/f_mmp/script
blob: f433bd5fca60921582e3a3a120cbb8d9eeb6924e (plain)
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
FSCK_OPT=-yf

echo "make the test image ..." > $test_name.log
$MKE2FS -q -F -o Linux -b 4096 -O mmp -E mmp_update_interval=1 $TMPFILE 100 >> $test_name.log 2>&1
status=$?
if [ "$status" != 0 ] ; then
	echo "mke2fs -O mmp failed" > $test_name.failed
	echo "$test_name: $test_description: failed"
	return $status
fi

kill_debugfs() {
	trap 0
	PID=$(ps -o pid,command | grep -v grep |
		grep "debugfs -w $TMPFILE" | awk "{ print \$1 }")
	[ "x$PID" != "x" ] && kill -9 $PID
}

# this will cause debugfs to create the $test_name.mark file once it has
# passed the MMP startup, then continue reading input until it is killed
MARKFILE=$test_name.new
rm -f $MARKFILE
trap kill_debugfs EXIT
echo "set mmp sequence to EXT2_MMP_SEQ_FSCK..." >> $test_name.log
( { echo dump_mmp; echo "dump_inode <2> $MARKFILE"; cat /dev/zero; } |
	$DEBUGFS -w $TMPFILE >> $test_name.log 2>&1 & ) > /dev/null 2>&1 &
echo "wait until debugfs has started ..." >> $test_name.log
while [ ! -e $MARKFILE ]; do
	sleep 1
done
rm -f $MARKFILE
echo "kill debugfs abruptly (simulates e2fsck failure) ..." >> $test_name.log
kill_debugfs

$E2MMPSTATUS $TMPFILE > $test_name.log 2>&1
status=$?
if [ "$status" != 1 ] ; then
	echo "$E2MMPSTATUS with EXT2_MMP_SEQ_FSCK passed!" > $test_name.failed
	echo "$test_name: $test_description: failed"
	return 1
fi

echo "e2fsck (should fail mmp_seq = EXT2_MMP_SEQ_FSCK) ..." >> $test_name.log
$FSCK $FSCK_OPT $TMPFILE >> $test_name.log 2>&1
status=$?
if [ "$status" = 0 ] ; then
	echo "e2fsck with MMP as EXT2_MMP_SEQ_FSCK ran!" > $test_name.failed
	echo "$test_name: $test_description: failed"
	return 1
fi

echo "clear mmp_seq with tune2fs ..." >> $test_name.log
$TUNE2FS -f -E clear_mmp $TMPFILE >> $test_name.log 2>&1
status=$?
if [ "$status" != 0 ] ; then
	echo "tune2fs clearing EXT2_MMP_SEQ_FSCK failed" > $test_name.failed
	echo "$test_name: $test_description: failed"
	return 1
fi

echo "run e2fsck again (should pass with clean mmp_seq) ..." >> $test_name.log
$FSCK $FSCK_OPT $TMPFILE >> $test_name.log 2>&1
status=$?
if [ "$status" != 0 ] ; then
	echo "e2fsck after clearing EXT2_MMP_SEQ_FSCK failed"> $test_name.failed
	echo "$test_name: $test_description: failed"
	return $status
fi

echo "$test_name: $test_description: ok"
rm -f $TMPFILE