echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
}
+# Do the actual mkfs work on SCRATCH_DEV. Firstly mkfs with both MKFS_OPTIONS
+# and user specified mkfs options, if that fails (due to conflicts between mkfs
+# options), do a second mkfs with only user provided mkfs options.
+#
+# First param is the mkfs command without any mkfs options and device.
+# Second param is the filter to remove unnecessary messages from mkfs stderr.
+# Other extra mkfs options are followed.
+_scratch_do_mkfs()
+{
+ local mkfs_cmd=$1
+ local mkfs_filter=$2
+ shift 2
+ local extra_mkfs_options=$*
+ local mkfs_status
+ local tmp=`mktemp`
+
+ # save mkfs output in case conflict means we need to run again.
+ # only the output for the mkfs that applies should be shown
+ eval "$mkfs_cmd $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV" \
+ 2>$tmp.mkfserr 1>$tmp.mkfsstd
+ mkfs_status=$?
+
+ # a mkfs failure may be caused by conflicts between $MKFS_OPTIONS and
+ # $extra_mkfs_options
+ if [ $mkfs_status -ne 0 -a -n "$extra_mkfs_options" ]; then
+ (
+ echo -n "** mkfs failed with extra mkfs options "
+ echo "added to \"$MKFS_OPTIONS\" by test $seq **"
+ echo -n "** attempting to mkfs using only test $seq "
+ echo "options: $extra_mkfs_options **"
+ ) >> $seqres.full
+
+ # running mkfs again. overwrite previous mkfs output files
+ eval "$mkfs_cmd $extra_mkfs_options $SCRATCH_DEV" \
+ 2>$tmp.mkfserr 1>$tmp.mkfsstd
+ mkfs_status=$?
+ fi
+
+ # output stored mkfs output, filtering unnecessary output from stderr
+ cat $tmp.mkfsstd
+ eval "cat $tmp.mkfserr | $mkfs_filter" >&2
+
+ rm -f $tmp*
+ return $mkfs_status
+}
+
_scratch_metadump()
{
dumpfile=$1
_scratch_mkfs_ext4()
{
- # extra mkfs options can be added by tests
- local extra_mkfs_options=$*
+ local mkfs_cmd="$MKFS_EXT4_PROG -F"
+ local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
+ local tmp=`mktemp`
+ local mkfs_status
- local tmp_dir=/tmp/
-
- $MKFS_EXT4_PROG -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
- 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
- local mkfs_status=$?
-
- # a mkfs failure may be caused by conflicts between
- # $MKFS_OPTIONS and $extra_mkfs_options
- if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
- (
- echo -n "** mkfs failed with extra mkfs options "
- echo "added to \"$MKFS_OPTIONS\" by test $seq **"
- echo -n "** attempting to mkfs using only test $seq "
- echo "options: $extra_mkfs_options **"
- ) >> $seqres.full
- # running mkfs again. overwrite previous mkfs output files
- $MKFS_EXT4_PROG -F $extra_mkfs_options $SCRATCH_DEV \
- 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
- local mkfs_status=$?
- fi
+ _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
+ mkfs_status=$?
if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
# manually parse the mkfs output to get the fs size in bytes
- fs_size=`cat $tmp_dir.mkfsstd | awk ' \
+ fs_size=`cat $tmp.mkfsstd | awk ' \
/^Block size/ { split($2, a, "="); bs = a[2] ; } \
/ inodes, / { blks = $3 } \
/reserved for the super user/ { resv = $1 } \
mkfs_status=$?
fi
- # output stored mkfs output
- grep -v -e ^Warning: -e "^mke2fs " $tmp_dir.mkfserr >&2
- cat $tmp_dir.mkfsstd
- rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
+ # output mkfs stdout and stderr
+ cat $tmp.mkfsstd
+ cat $tmp.mkfserr >&2
return $mkfs_status
}
_scratch_mkfs()
{
- case $FSTYP in
- xfs)
- _scratch_mkfs_xfs $*
- ;;
- nfs*)
- # unable to re-create NFS, just remove all files in $SCRATCH_MNT to
- # avoid EEXIST caused by the leftover files created in previous runs
- _scratch_cleanup_files
- ;;
- cifs)
- # unable to re-create CIFS, just remove all files in $SCRATCH_MNT to
- # avoid EEXIST caused by the leftover files created in previous runs
- _scratch_cleanup_files
- ;;
- ceph)
- # Don't re-create CephFS, just remove all files
- _scratch_cleanup_files
- ;;
- overlay)
- # unable to re-create overlay, remove all files in $SCRATCH_MNT to
- # avoid EEXIST caused by the leftover files created in previous runs
- _scratch_cleanup_files
- ;;
- udf)
- $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
- ;;
- btrfs)
- $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
- ;;
- ext2|ext3)
- $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV
- ;;
- ext4)
- _scratch_mkfs_ext4 $*
- ;;
- tmpfs)
- # do nothing for tmpfs
- ;;
- f2fs)
- $MKFS_F2FS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
- ;;
- *)
- yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
- ;;
- esac
+ local mkfs_cmd=""
+ local mkfs_filter=""
+ local mkfs_status
+
+ case $FSTYP in
+ nfs*|cifs|ceph|overlay)
+ # unable to re-create this fstyp, just remove all files in
+ # $SCRATCH_MNT to avoid EEXIST caused by the leftover files
+ # created in previous runs
+ _scratch_cleanup_files
+ return 0
+ ;;
+ tmpfs)
+ # do nothing for tmpfs
+ return 0
+ ;;
+ ext4)
+ _scratch_mkfs_ext4 $*
+ return $?
+ ;;
+ xfs)
+ _scratch_mkfs_xfs $*
+ return $?
+ ;;
+ udf)
+ mkfs_cmd="$MKFS_UDF_PROG"
+ mkfs_filter="cat"
+ ;;
+ btrfs)
+ mkfs_cmd="$MKFS_BTRFS_PROG"
+ mkfs_filter="cat"
+ ;;
+ ext2|ext3)
+ mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
+ mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
+ ;;
+ f2fs)
+ mkfs_cmd="$MKFS_F2FS_PROG"
+ mkfs_filter="cat"
+ ;;
+ ocfs2)
+ mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
+ mkfs_filter="grep -v -e ^mkfs\.ocfs2"
+ ;;
+ *)
+ mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
+ mkfs_filter="cat"
+ ;;
+ esac
+
+ _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $*
+ return $?
}
# Helper function to get a spare or replace-target device from
_scratch_options mkfs
- $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
+ echo "$MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts"
}
_scratch_mkfs_xfs()
{
- # extra mkfs options can be added by tests
- local extra_mkfs_options=$*
+ local mkfs_cmd="`_scratch_mkfs_xfs_opts`"
+ local mkfs_filter="sed -e '/less than device physical sector/d' \
+ -e '/switching to logical sector/d'"
+ local tmp=`mktemp`
+ local mkfs_status
- local tmp_dir=/tmp/
-
- # save mkfs output in case conflict means we need to run again.
- # only the output for the mkfs that applies should be shown
- _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
- 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
- local mkfs_status=$?
+ _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
+ mkfs_status=$?
- # a mkfs failure may be caused by conflicts between
- # $MKFS_OPTIONS and $extra_mkfs_options
- if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
- (
- echo -n "** mkfs failed with extra mkfs options "
- echo "added to \"$MKFS_OPTIONS\" by test $seq **"
- echo -n "** attempting to mkfs using only test $seq "
- echo "options: $extra_mkfs_options **"
- ) >> $seqres.full
-
- # running mkfs again. overwrite previous mkfs output files
- _scratch_mkfs_xfs_opts $extra_mkfs_options \
- 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
- local mkfs_status=$?
- fi
-
if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
# manually parse the mkfs output to get the fs size in bytes
local fs_size
- fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
+ fs_size=`cat $tmp.mkfsstd | perl -ne '
if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
my $size = $1 * $2;
print STDOUT "$size\n";
mkfs_status=$?
fi
- # output stored mkfs output, filtering unnecessary warnings from stderr
- cat $tmp_dir.mkfsstd
- cat $tmp_dir.mkfserr | sed \
- -e '/less than device physical sector/d' \
- -e '/switching to logical sector/d' \
- >&2
- rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
+ # output mkfs stdout and stderr
+ cat $tmp.mkfsstd
+ cat $tmp.mkfserr >&2
+ rm -f $tmp*
return $mkfs_status
}