1FSCK_OPT=-yf 2 3# use current directory instead of /tmp becase tmpfs doesn't support DIO 4rm -f $TMPFILE 5TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX) 6 7stat -f $TMPFILE | grep -q "Type: tmpfs" 8if [ $? = 0 ]; then 9 rm -f $TMPFILE 10 echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)" 11 return 0 12fi 13 14echo "make the test image ..." > $test_name.log 15$MKE2FS -q -F -o Linux -b 4096 -O mmp -E mmp_update_interval=1 $TMPFILE 100 >> $test_name.log 2>&1 16status=$? 17if [ "$status" != 0 ] ; then 18 echo "mke2fs -O mmp failed" > $test_name.failed 19 echo "$test_name: $test_description: failed" 20 return $status 21fi 22 23kill_debugfs() { 24 trap 0 25 PID=$(ps -o pid,command | grep -v grep | 26 grep "debugfs -w $TMPFILE" | awk "{ print \$1 }") 27 [ "x$PID" != "x" ] && kill -9 $PID 28} 29 30# this will cause debugfs to create the $test_name.mark file once it has 31# passed the MMP startup, then continue reading input until it is killed 32MARKFILE=$test_name.new 33rm -f $MARKFILE 34trap kill_debugfs EXIT 35echo "set mmp sequence to EXT2_MMP_SEQ_FSCK..." >> $test_name.log 36( { echo dump_mmp; echo "dump_inode <2> $MARKFILE"; cat /dev/zero; } | 37 $DEBUGFS -w $TMPFILE >> $test_name.log 2>&1 & ) > /dev/null 2>&1 & 38echo "wait until debugfs has started ..." >> $test_name.log 39while [ ! -e $MARKFILE ]; do 40 sleep 1 41done 42rm -f $MARKFILE 43echo "kill debugfs abruptly (simulates e2fsck failure) ..." >> $test_name.log 44kill_debugfs 45 46 47echo "e2fsck (should fail mmp_seq = EXT2_MMP_SEQ_FSCK) ..." >> $test_name.log 48$FSCK $FSCK_OPT $TMPFILE >> $test_name.log 2>&1 49status=$? 50if [ "$status" = 0 ] ; then 51 echo "e2fsck with MMP as EXT2_MMP_SEQ_FSCK ran!" > $test_name.failed 52 echo "$test_name: $test_description: failed" 53 return 1 54fi 55 56echo "clear mmp_seq with tune2fs ..." >> $test_name.log 57$TUNE2FS -f -E clear_mmp $TMPFILE >> $test_name.log 2>&1 58status=$? 59if [ "$status" != 0 ] ; then 60 echo "tune2fs clearing EXT2_MMP_SEQ_FSCK failed" > $test_name.failed 61 echo "$test_name: $test_description: failed" 62 return 1 63fi 64 65echo "run e2fsck again (should pass with clean mmp_seq) ..." >> $test_name.log 66$FSCK $FSCK_OPT $TMPFILE >> $test_name.log 2>&1 67status=$? 68if [ "$status" != 0 ] ; then 69 echo "e2fsck after clearing EXT2_MMP_SEQ_FSCK failed"> $test_name.failed 70 echo "$test_name: $test_description: failed" 71 return $status 72fi 73 74echo "$test_name: $test_description: ok" 75rm -f $TMPFILE 76