[Ocfs2-tools-devel] ocfs2-test patch for testing backup superblocks.

tao.ma tao.ma at oracle.com
Wed Dec 13 01:10:29 PST 2006


tao.ma wrote:
> Hi all,
>     I write a script for testing the implementations of backup 
> superblocks. Any suggestions, please let me know.
>
> ------------------------------------------------------------------------
>
> Index: programs/backup_super/test.sh
> ===================================================================
> --- programs/backup_super/test.sh	(revision 0)
> +++ programs/backup_super/test.sh	(revision 0)
> @@ -0,0 +1,267 @@
> +#!/bin/bash
> +
> +MKFS_OLD=./mkfs.ocfs2.old
> +MKFS=./mkfs.ocfs2
> +FSCK=./fsck.ocfs2
> +DEBUGFS=./debugfs.ocfs2
> +TUNEFS=./tunefs.ocfs2
> +
> +DEVICE=$1
> +FIRST_BACKUP_OFF=1073741824	#1G
> +MAX_NUM=6
> +
> +if [ -z "$DEVICE" ]; then
> +    echo "$0 device"
> +    exit 1
> +fi
> +
> +echo "checking the programs we need in the test..."
> +for PROGRAM in	$MKFS_OLD $MKFS $FSCK $DEBUGFS $TUNEFS
> +do
> +	type $PROGRAM
> +	if [ $? != "0" ]; then
> +	#if [ -x $PROGRAM ]; then
> +		echo "$PROGRAM not exist"
> +		exit 1
> +	fi
> +done
> +
> +exec 3>&1
> +exec 2>/dev/null
> +exec 1>/dev/null
> +
> +#$1 is the result to check
> +#$2 is the result we want
> +#$3 is the error messge
> +#$4 is the line num of the error
> +check_result()
> +{
> +	if [ $1 != $2 ]; then
> +		echo $3" at line "$4 >&3
> +		exit 1
> +	fi
> +}
> +
> +#clear all the backup blocks in the device
> +clear_backup_blocks()
> +{
> +	backup_off=$FIRST_BACKUP_OFF
> +
> +	while [ `expr $backup_off + 512` -le `expr $byte_total` ];
> +	do
> +		#clear the last blocksize
> +		seek_block=`expr $backup_off / 512`
> +		dd if=/dev/zero of=$DEVICE bs=512 count=1 seek=$seek_block
> +
> +		backup_off=`expr $backup_off \* 4`
> +	done
> +}
> +
> +test_mkfs()
> +{
> +	echo "testing mkfs.ocfs2..." >&3
> +	#mkfs and debugfs test.
> +	#vol_byte_size is always set to be one of the backup
> +	#superblock offset, say 1G, 4G, 16G...
> +	#see the main loop for more details.
> +
> +	#in order to speed up the process of mkfs,
> +	#we empty the first block first.
> +	#we also need to clear all the backup blocks in the device
> +	#in case they are written by prevoius format.
> +	dd if=/dev/zero of=$DEVICE bs=4096 count=3
> +	clear_backup_blocks
> +
> +	msg="debugfs shouldn't be sucess"
> +	msg1="debugfs should be sucess"
> +
> +	blkcount=`expr $vol_byte_size / $blocksize`
> +	$MKFS -b $blocksize -C $clustersize -N 4 $DEVICE $blkcount
> +	#first check whether mkfs is success
> +	echo "ls //"|$DEBUGFS $DEVICE|grep global_bitmap
> +	check_result $? 0 $msg $LINENO
> +
> +	#this time there is the block represented by the last_backup_num isn't
> +	#in the volume, so we can't open the device by the num.
> +	echo "ls //"|$DEBUGFS $DEVICE -s $last_backup_num|grep global_bitmap
> +	check_result $? 1 $msg1 $LINENO
> +
> +	#increase the blkcount so that the blocks represented by the last_backup_num
> +	#can be used to store the backup block.
> +	bpc=`expr $clustersize / $blocksize`
> +	blkcount=`expr $blkcount + $bpc`
> +
> +	dd if=/dev/zero of=$DEVICE bs=4096 count=3
> +	clear_backup_blocks
> +	$MKFS -b $blocksize -C $clustersize -N 4 $DEVICE $blkcount
> +	#first check whether mkfs is success
> +	echo "ls //"|$DEBUGFS $DEVICE|grep global_bitmap
> +	check_result $? 0 $msg1 $LINENO
> +
> +	#check whether all the backup blocks including last_backup_num
> +	#can be opened.
> +	i=1
> +	while [ `expr $i` -le `expr $last_backup_num` ];
> +	do
> +		cmd="$DEBUGFS $DEVICE -s $i"
> +		echo "ls //"|$cmd|grep global_bitmap
> +		check_result $? 0 $msg1 $LINENO
> +		echo $cmd " is ok." >&3
> +		i=`expr $i + 1`
> +	done
> +}
> +
> +#test fsck.ocfs2 -r
> +test_fsck()
> +{
> +	echo "testing fsck.ocfs2..." >&3
> +
> +	dd if=/dev/zero of=$DEVICE bs=4096 count=3
> +	clear_backup_blocks
> +
> +	$MKFS -b $blocksize -C $clustersize -N 4 $DEVICE $blkcount
> +	#corrupt the superblock
> +	dd if=/dev/zero of=$DEVICE bs=$blocksize count=3
> +	$FSCK $DEVICE	#This should failed.
> +	check_result $? 8 "fsck.ocfs2" $LINENO
> +
> +	#recover the superblock
> +	cmd="$FSCK -y -r $last_backup_num $DEVICE"
> +	$cmd
> +	check_result $? 0 "fsck.ocfs2" $LINENO
> +	echo $cmd "is ok" >&3
> +
> +	#go on the normal process to see whether the recovery is sucess.
> +	$FSCK -f $DEVICE	#This should failed.
> +	check_result $? 0 "fsck.ocfs2" $LINENO
> +}
> +
> +#test whether tunefs will add new backup superblocks during resizing
> +test_tunefs_resize()
> +{
> +	dd if=/dev/zero of=$DEVICE bs=4096 count=3
> +	clear_backup_blocks
> +
> +	#mkfs a volume with no backup superblock
> +	$MKFS -b $blocksize -C $clustersize -N 4 $DEVICE $blkcount
> +
> +	bpc=`expr $clustersize / $blocksize`
> +	blkcount=`expr $blkcount + $bpc`
> +	#tunefs a volume to add a cluster which will have a backup superblock.
> +	cmd="$TUNEFS -S $DEVICE $blkcount"
> +	echo "y"|$cmd
> +	check_result $? 0 "tunefs.ocfs2" $LINENO
> +	echo $cmd "is ok" >&3
> +	cmd="$DEBUGFS $DEVICE -s $last_backup_num"
> +	echo "ls //"|$cmd|grep global_bitmap
> +	check_result $? 0 "tunefs.ocfs2" $LINENO	#we can open with a backup block
> +	echo $cmd "is ok." >&3
> +}
> +
> +#test whether tunefs will add backup superblocks for an old ocfs2 volume
> +test_tunefs_add_backup()
> +{
> +	dd if=/dev/zero of=$DEVICE bs=4096 count=3
> +	clear_backup_blocks
> +
> +	#mkfs a volume with no backup superblock supported
> +	$MKFS_OLD -b $blocksize -C $clustersize -N 4 $DEVICE $blkcount
> +
> +	#tunefs a volume to add backup superblocks
> +	$TUNEFS -b -L "test" $DEVICE	#we don't allow change volume with backup
> +	check_result $? 1 "tunefs.ocfs2" $LINENO
> +	$TUNEFS -b -N 8 $DEVICE	#we don't allow change slots with backup
> +	check_result $? 1 "tunefs.ocfs2" $LINENO
> +
> +	cmd="$TUNEFS -b $DEVICE"
> +	echo "y"|$cmd
> +	check_result $? 0 "tunefs.ocfs2" LINENO
> +	echo $cmd "is ok" >&3
> +	echo "ls //"|$DEBUGFS $DEVICE -s 1|grep global_bitmap
> +	check_result $? 0 "tunefs.ocfs2" $LINENO	#we can open with a backup block
> +}
> +
> +check_vol()
> +{
> +	fsck_result=`$FSCK $DEVICE|grep label`
> +	label_name=`echo $fsck_result | awk '{print $2}'`
> +
> +	if [ $label_name != $1 ]; then
> +		echo "check volume name [$1]failed">&3
> +		exit 1
> +	fi
> +}
> +
> +#test whether tunefs will refresh backup block when updating the superblock
> +test_tunefs_refresh()
> +{
> +	dd if=/dev/zero of=$DEVICE bs=4096 count=3
> +	clear_backup_blocks
> +
> +	old_vol_name="old_ocfs2"
> +	new_vol_name="new_ocfs2"
> +	$MKFS -b $blocksize -C $clustersize -N 4 -L $old_vol_name $DEVICE $blkcount
> +	check_vol $old_vol_name
> +
> +	#change the volume name
> +	echo "y"|$TUNEFS -L $new_vol_name $DEVICE
> +	#corrupt the superblock
> +	dd if=/dev/zero of=$DEVICE bs=$blocksize count=3
> +	cmd="$FSCK -fy -r $last_backup_num $DEVICE"
> +	check_result $? 0 $cmd $LINENO
> +	echo $cmd " is ok" >&3
> +	#check whether the recover superblock has the new vol name
> +	check_vol $new_vol_name
> +}
> +
> +for blocksize in 512 #1024 2048 4096
> +do
> +	for clustersize in \
> +		4096 #8192 16384 32768 65536 131072 262144 524288 1048576
> +	do
> +		sect_total=`blockdev --getsize $DEVICE`
> +		byte_total=`expr $sect_total \* 512`
> +
> +		vol_byte_size=$FIRST_BACKUP_OFF
> +		#last_backup_num is set according to the vol_byte_size
> +		#for 1 for 1G, and 2 for 4G, 3 for 16G etc.
> +		last_backup_num=1
> +
> +		while [ `expr $vol_byte_size` -le `expr $byte_total` ] ;
> +		do
> +			echo "vol_size = $vol_byte_size, blocksize = $blocksize,"	\
> +			     " clustersize = $clustersize" >&3
> +
> +			bpc=`expr $clustersize / $blocksize`
> +
> +			test_mkfs
> +
> +			#for fsck, we must increase vol_byte_size to include
> +			#the backup block.
> +			blkcount=`expr $vol_byte_size / $blocksize + $bpc`
> +			test_fsck
> +
> +			#for resize, the initial blkcount should not include
> +			#the backup block.
> +			blkcount=`expr $vol_byte_size / $blocksize`
> +			test_tunefs_resize
> +
> +			#for add backup blocks, we must increase vol_byte_size
> +			#to include the backup block.
> +			blkcount=`expr $vol_byte_size / $blocksize + $bpc`
> +			#test_tunefs_add_backup
>   
Sorry, I forget to remove this '#'. This is also a test function.
> +
> +			#for refresh backup blocks, we must increase
> +			#vol_byte_size to include the backup block.
> +			blkcount=`expr $vol_byte_size / $blocksize + $bpc`
> +			test_tunefs_refresh
> +
> +		        vol_byte_size=`expr $vol_byte_size \* 4`
> +			last_backup_num=`expr $last_backup_num + 1`
> +
> +			if [ `expr $last_backup_num` -gt `expr $MAX_NUM` ]; then
> +				break
> +			fi
> +		done
> +	done
> +done
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Ocfs2-tools-devel mailing list
> Ocfs2-tools-devel at oss.oracle.com
> http://oss.oracle.com/mailman/listinfo/ocfs2-tools-devel
>   


-- 
* **     Tao Ma
*     Member of Techincal Staff *

Oracle Asia Research & Development Center
Open Source Technologies Development
*
Tel:        +86 10 8278 6026
Mobile:   +86 13701237602         
URL:       OARDC Intranet <http://cdc.oraclecorp.com/>, Oracle.com/cdc 
<http://www.oracle.com/cdc/>



More information about the Ocfs2-tools-devel mailing list