linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Liu Bo <liubo2009@cn.fujitsu.com>
Cc: xfs@oss.sgi.com, hch@infradead.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 3/3 v2] xfstests: add btrfs online defragments QA test
Date: Mon, 13 Feb 2012 12:53:44 -0500	[thread overview]
Message-ID: <20120213175344.GA15040@infradead.org> (raw)
In-Reply-To: <1328766034-1324-1-git-send-email-liubo2009@cn.fujitsu.com>

This still needs a bit more work:

> +test_path="`pwd`"
> +progs_dir="$test_path/src/btrfs_online_defragment/"

this isn't actually used.


> +tmp=tmp/$$
> +defrag_args="$test_path/${seq}.args"

Just hardcode the arguments, preferably without the args file
indirection.

> +_create_file()
> +{
> +	CNT=11999
> +	FILESIZE=48000
> +	if [ "$DEFRAG_TARGET" = "1" ];then
> +		for i in `seq $CNT -1 0`; do
> +			dd if=/dev/zero of=$SCRATCH_MNT/tmp_file bs=4k count=1 \
> +			 conv=notrunc seek=$i oflag=sync &>/dev/null
> +		done
> +		# get md5sum
> +		md5sum $SCRATCH_MNT/tmp_file > /tmp/checksum
> +	elif [ "$DEFRAG_TARGET" = "2" ];then
> +		mkdir $SCRATCH_MNT/tmp_dir
> +		for i in `seq $CNT -1 0`; do
> +			dd if=/dev/zero of=$SCRATCH_MNT/tmp_dir/tmp_file bs=4k \
> +			count=1 conv=notrunc seek=$i oflag=sync &>/dev/null
> +		done
> +		# get md5sum
> +		md5sum $SCRATCH_MNT/tmp_dir/tmp_file > /tmp/checksum
> +	elif [ "$DEFRAG_TARGET" = "3" ];then
> +		for i in `seq $CNT -1 0`; do
> +			dd if=/dev/zero of=$SCRATCH_MNT/tmp_file bs=4k count=1 \
> +			conv=notrunc seek=$i oflag=sync &>/dev/null
> +		done
> +		# get md5sum
> +		md5sum $SCRATCH_MNT/tmp_file > /tmp/checksum
> +	fi
> +}

It seems like each of these cases should be a different function.

> +_btrfs_online_defrag()
> +{
> +	str=""
> +	if [ "$FILE_RANGE" = "2" ];then
> +		str="$str -s -1 -l $((FILESIZE / 2)) "
> +	elif [ "$FILE_RANGE" = "3" ];then
> +		str="$str -s $((FILESIZE + 1)) -l $((FILESIZE / 2)) "
> +		HAVE_DEFRAG=1
> +	elif [ "$FILE_RANGE" = "4" ];then
> +		str="$str -l -1 "
> +	elif [ "$FILE_RANGE" = "5" ];then
> +		str="$str -l $((FILESIZE + 1)) "
> +	elif [ "$FILE_RANGE" = "6" ];then
> +		str="$str -l $((FILESIZE / 2)) "
> +	fi
> +
> +	if [ "$DEFRAG_COMPRESS" = "2" ];then
> +		str="$str -c "
> +	fi
> +
> +	if [ "$FLUSH" = "2" ];then
> +		str="$str -f "
> +	fi
> +
> +	if [ "$THRESH" = "2" ];then
> +		str="$str -t -1 "
> +	elif [ "$THRESH" = "3" ];then
> +		str="$str -t $PAGESIZE "
> +	fi
> +
> +	if [ "$str" != "" ]; then
> +		btrfs filesystem defragment $str $SCRATCH_MNT/tmp_file
> +	else
> +		if [ "$DEFRAG_TARGET" = "1" ];then
> +			btrfs filesystem defragment $SCRATCH_MNT/tmp_file
> +		elif [ "$DEFRAG_TARGET" = "2" ];then
> +			btrfs filesystem defragment $SCRATCH_MNT/tmp_dir
> +		elif [ "$DEFRAG_TARGET" = "3" ];then
> +			btrfs filesystem defragment $SCRATCH_MNT
> +		fi
> +	fi
> +	ret_val=$?
> +	sync
> +	if [ $ret_val -ne 20 ];then
> +		echo "btrfs filesystem defragment failed! err is $ret_val"
> +	fi
> +}

> +_fsck()
> +{
> +	btrfsck $SCRATCH_DEV > /dev/null 2>&1
> +	ret_val=$?
> +	if [ $ret_val -ne 0 ]; then
> +		echo "btrfsck _FAIL_! err is $ret_val"
> +	fi
> +}

This should use the generic xfstests fsck invocation wrappers.

> +_parse_options()

Please don't use an option parser but just call the low-level file
creation functions directly.

> +_cleanup_defrag()
> +{
> +	rm -fr $SCRATCH_MNT/*
> +	umount $SCRATCH_MNT > /dev/null 2>&1
> +}

No need to remove everything as the scratch filesystem gets recreated
every time.


  reply	other threads:[~2012-02-13 17:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-09  5:40 [PATCH 3/3 v2] xfstests: add btrfs online defragments QA test Liu Bo
2012-02-13 17:53 ` Christoph Hellwig [this message]
2012-02-14  1:20   ` Liu Bo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120213175344.GA15040@infradead.org \
    --to=hch@infradead.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=liubo2009@cn.fujitsu.com \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).