Home | History | Annotate | Download | only in f_mmp
      1 FSCK_OPT=-yf
      2 
      3 # use current directory instead of /tmp becase tmpfs doesn't support DIO
      4 rm -f $TMPFILE
      5 TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX)
      6 
      7 stat -f $TMPFILE | grep -q "Type: tmpfs"
      8 if [ $? = 0 ]; then
      9 	rm -f $TMPFILE
     10 	echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)"
     11 	return 0
     12 fi
     13 
     14 echo "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
     16 status=$?
     17 if [ "$status" != 0 ] ; then
     18 	echo "mke2fs -O mmp failed" > $test_name.failed
     19 	echo "$test_name: $test_description: failed"
     20 	return $status
     21 fi
     22 
     23 kill_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
     32 MARKFILE=$test_name.new
     33 rm -f $MARKFILE
     34 trap kill_debugfs EXIT
     35 echo "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 &
     38 echo "wait until debugfs has started ..." >> $test_name.log
     39 while [ ! -e $MARKFILE ]; do
     40 	sleep 1
     41 done
     42 rm -f $MARKFILE
     43 echo "kill debugfs abruptly (simulates e2fsck failure) ..." >> $test_name.log
     44 kill_debugfs
     45 
     46 $E2MMPSTATUS $TMPFILE > $test_name.log 2>&1
     47 status=$?
     48 if [ "$status" != 1 ] ; then
     49 	echo "$E2MMPSTATUS with EXT2_MMP_SEQ_FSCK passed!" > $test_name.failed
     50 	echo "$test_name: $test_description: failed"
     51 	return 1
     52 fi
     53 
     54 echo "e2fsck (should fail mmp_seq = EXT2_MMP_SEQ_FSCK) ..." >> $test_name.log
     55 $FSCK $FSCK_OPT $TMPFILE >> $test_name.log 2>&1
     56 status=$?
     57 if [ "$status" = 0 ] ; then
     58 	echo "e2fsck with MMP as EXT2_MMP_SEQ_FSCK ran!" > $test_name.failed
     59 	echo "$test_name: $test_description: failed"
     60 	return 1
     61 fi
     62 
     63 echo "clear mmp_seq with tune2fs ..." >> $test_name.log
     64 $TUNE2FS -f -E clear_mmp $TMPFILE >> $test_name.log 2>&1
     65 status=$?
     66 if [ "$status" != 0 ] ; then
     67 	echo "tune2fs clearing EXT2_MMP_SEQ_FSCK failed" > $test_name.failed
     68 	echo "$test_name: $test_description: failed"
     69 	return 1
     70 fi
     71 
     72 echo "run e2fsck again (should pass with clean mmp_seq) ..." >> $test_name.log
     73 $FSCK $FSCK_OPT $TMPFILE >> $test_name.log 2>&1
     74 status=$?
     75 if [ "$status" != 0 ] ; then
     76 	echo "e2fsck after clearing EXT2_MMP_SEQ_FSCK failed"> $test_name.failed
     77 	echo "$test_name: $test_description: failed"
     78 	return $status
     79 fi
     80 
     81 echo "$test_name: $test_description: ok"
     82 rm -f $TMPFILE
     83