mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
0966519543
To cover cases when fstrim arguments are not block/block group/file system size aligned, we can be a bit more random. This commit changes fstrim argument computing to use $RANDOM bash variable in order to have different minlen, start, len argument settings and change the full fs fstrim to be called randomly as well. Also make kill and wait not complain about non existent process, since it may have already finished before we attempt to kill it and wait for it. No reason to fail the test. Signed-off-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
189 lines
4.0 KiB
Bash
Executable File
189 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# FS QA Test No. 251
|
|
#
|
|
# This test was created in order to verify filesystem FITRIM implementation.
|
|
# By many concurrent copy and remove operations and checking that files
|
|
# does not change after copied into SCRATCH_MNT test if FITRIM implementation
|
|
# corrupts the filesystem (data/metadata).
|
|
#
|
|
#-----------------------------------------------------------------------
|
|
# Copyright 2010 (C) Red Hat, Inc., Lukas Czerner <lczerner@redhat.com>
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License as
|
|
# published by the Free Software Foundation.
|
|
#
|
|
# This program is distributed in the hope that it would be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write the Free Software Foundation,
|
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
#-----------------------------------------------------------------------
|
|
|
|
owner=lczerner@redhat.com
|
|
|
|
seq=`basename $0`
|
|
echo "QA output created by $seq"
|
|
|
|
here=`pwd`
|
|
tmp=`mktemp -d`
|
|
status=1 # failure is the default!
|
|
trap "_cleanup; exit \$status" 0 1 3
|
|
trap "_destroy; exit \$status" 2 15
|
|
chpid=0
|
|
mypid=$$
|
|
|
|
# get standard environment, filters and checks
|
|
. ./common.rc
|
|
. ./common.filter
|
|
|
|
# real QA test starts here
|
|
_supported_fs generic
|
|
_supported_os Linux
|
|
_require_scratch
|
|
_scratch_mkfs >/dev/null 2>&1
|
|
_scratch_mount
|
|
|
|
_cleanup()
|
|
{
|
|
rm -rf $tmp
|
|
}
|
|
|
|
_destroy()
|
|
{
|
|
kill $pids $fstrim_pid 2> /dev/null
|
|
wait $pids $fstrim_pid 2> /dev/null
|
|
rm -rf $tmp
|
|
}
|
|
|
|
_destroy_fstrim()
|
|
{
|
|
kill $fpid 2> /dev/null
|
|
wait $fpid 2> /dev/null
|
|
}
|
|
|
|
_fail()
|
|
{
|
|
echo "$1"
|
|
kill $mypid 2> /dev/null
|
|
}
|
|
|
|
_check_fstrim_support()
|
|
{
|
|
$here/src/fstrim -l 10M $SCRATCH_MNT &> /dev/null
|
|
}
|
|
|
|
_guess_max_minlen()
|
|
{
|
|
mmlen=100000
|
|
while [ $mmlen -gt 1 ]; do
|
|
$here/src/fstrim -l $(($mmlen*2))k -m ${mmlen}k $SCRATCH_MNT &> /dev/null && break
|
|
mmlen=$(($mmlen/2))
|
|
done
|
|
echo $mmlen
|
|
}
|
|
|
|
##
|
|
# Background FSTRIM loop. We are trimming the device in the loop and for
|
|
# test coverage, we are doing whole device trim followed by several smaller
|
|
# trims.
|
|
##
|
|
fstrim_loop()
|
|
{
|
|
trap "_destroy_fstrim; exit \$status" 2 15
|
|
fsize=$(df | grep $SCRATCH_MNT | grep $SCRATCH_DEV | awk '{print $2}')
|
|
mmlen=$(_guess_max_minlen)
|
|
|
|
while true ; do
|
|
step=$((RANDOM*$RANDOM))
|
|
minlen=$(((RANDOM*($RANDOM%2+1))%$mmlen))
|
|
start=$RANDOM
|
|
if [ $((RANDOM%10)) -gt 7 ]; then
|
|
$here/src/fstrim $SCRATCH_MNT &
|
|
fpid=$!
|
|
wait $fpid
|
|
fi
|
|
while [ $start -lt $fsize ] ; do
|
|
$here/src/fstrim -m ${minlen}k -s ${start}k -l ${step}k $SCRATCH_MNT &
|
|
fpid=$!
|
|
wait $fpid
|
|
start=$(( $start + $step ))
|
|
done
|
|
done
|
|
}
|
|
|
|
function check_sums() {
|
|
(
|
|
cd $SCRATCH_MNT/$p
|
|
find -P . -xdev -type f -print0 | xargs -0 md5sum | sort -o $tmp/stress.$$.$p
|
|
)
|
|
|
|
diff $tmp/content.sums $tmp/stress.$$.$p
|
|
if [ $? -ne 0 ]; then
|
|
_fail "!!!Checksums has changed - Filesystem possibly corrupted!!!\n"
|
|
fi
|
|
rm -f $tmp/stress.$$.$p
|
|
}
|
|
|
|
function run_process() {
|
|
local p=$1
|
|
repeat=10
|
|
|
|
sleep $((5*$p))s &
|
|
export chpid=$! && wait $chpid &> /dev/null
|
|
chpid=0
|
|
|
|
while [ $repeat -gt 0 ]; do
|
|
|
|
# Remove old directories.
|
|
rm -rf $SCRATCH_MNT/$p
|
|
export chpid=$! && wait $chpid &> /dev/null
|
|
|
|
# Copy content -> partition.
|
|
mkdir $SCRATCH_MNT/$p
|
|
cp -axT $content/ $SCRATCH_MNT/$p/
|
|
export chpid=$! && wait $chpid &> /dev/null
|
|
|
|
check_sums
|
|
repeat=$(( $repeat - 1 ))
|
|
done
|
|
}
|
|
|
|
nproc=20
|
|
content=$here
|
|
|
|
# Check for FITRIM support
|
|
echo -n "Checking FITRIM support: "
|
|
_check_fstrim_support || _notrun "FSTRIM is not supported"
|
|
echo "done."
|
|
|
|
mkdir -p $tmp
|
|
|
|
(
|
|
cd $content
|
|
find -P . -xdev -type f -print0 | xargs -0 md5sum | sort -o $tmp/content.sums
|
|
)
|
|
|
|
echo -n "Running the test: "
|
|
pids=""
|
|
fstrim_loop &
|
|
fstrim_pid=$!
|
|
p=1
|
|
while [ $p -le $nproc ]; do
|
|
run_process $p &
|
|
pids="$pids $!"
|
|
p=$(($p+1))
|
|
done
|
|
echo "done."
|
|
|
|
wait $pids
|
|
kill $fstrim_pid
|
|
wait $fstrim_pid
|
|
|
|
status=0
|
|
|
|
exit
|