2015-11-17 08:39:43 +11:00
|
|
|
#! /bin/bash
|
2018-06-09 11:35:42 +10:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
|
|
|
|
|
#
|
2015-11-17 08:39:43 +11:00
|
|
|
# FS QA Test No. 156
|
|
|
|
|
#
|
|
|
|
|
# Ensure that fallocate on reflinked files actually CoWs the shared blocks.
|
|
|
|
|
# - Record fs block usage (0)
|
|
|
|
|
# - Create a file and some reflink copies
|
|
|
|
|
# - Record fs block usage (1)
|
|
|
|
|
# - funshare half of one of the copies
|
|
|
|
|
# - Record fs block usage (2)
|
|
|
|
|
# - funshare all of the copies
|
|
|
|
|
# - Record fs block usage (3)
|
|
|
|
|
# - rewrite the original file
|
|
|
|
|
# - Record fs block usage (4)
|
|
|
|
|
# - Compare fs block usage of 0-4 to ensure that block usage behaves as
|
|
|
|
|
# we expect.
|
|
|
|
|
#
|
|
|
|
|
# "funshare" refers to fallocate copy-on-writing the shared blocks
|
|
|
|
|
#
|
2016-02-10 00:33:10 -08:00
|
|
|
seq=`basename $0`
|
|
|
|
|
seqres=$RESULT_DIR/$seq
|
2015-11-17 08:39:43 +11:00
|
|
|
echo "QA output created by $seq"
|
|
|
|
|
|
|
|
|
|
here=`pwd`
|
|
|
|
|
tmp=/tmp/$$
|
|
|
|
|
status=1 # failure is the default!
|
|
|
|
|
trap "_cleanup; exit \$status" 0 1 2 3 15
|
|
|
|
|
|
|
|
|
|
_cleanup()
|
|
|
|
|
{
|
|
|
|
|
cd /
|
2016-02-10 00:33:10 -08:00
|
|
|
rm -rf $tmp.* $testdir
|
2015-11-17 08:39:43 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# get standard environment, filters and checks
|
|
|
|
|
. ./common/rc
|
|
|
|
|
. ./common/filter
|
|
|
|
|
. ./common/attr
|
|
|
|
|
. ./common/reflink
|
|
|
|
|
|
|
|
|
|
# real QA test starts here
|
|
|
|
|
_require_test_reflink
|
|
|
|
|
_require_cp_reflink
|
2016-10-17 15:09:28 -07:00
|
|
|
_require_xfs_io_command "funshare"
|
2015-11-17 08:39:43 +11:00
|
|
|
|
2016-02-10 00:33:10 -08:00
|
|
|
rm -f $seqres.full
|
2015-11-17 08:39:43 +11:00
|
|
|
|
2016-02-10 00:33:10 -08:00
|
|
|
testdir=$TEST_DIR/test-$seq
|
|
|
|
|
rm -rf $testdir
|
|
|
|
|
mkdir $testdir
|
2015-11-17 08:39:43 +11:00
|
|
|
|
|
|
|
|
echo "Create the original file blocks"
|
2017-01-04 17:04:48 -08:00
|
|
|
blksz="$(_get_block_size $testdir)"
|
2016-02-08 09:27:15 +11:00
|
|
|
blks=2000
|
2016-02-08 09:27:15 +11:00
|
|
|
margin='15%'
|
2016-02-08 09:27:15 +11:00
|
|
|
sz=$((blksz * blks))
|
2016-02-10 00:33:10 -08:00
|
|
|
free_blocks0=$(stat -f $testdir -c '%f')
|
2016-02-08 09:27:15 +11:00
|
|
|
nr=4
|
2016-02-10 00:33:10 -08:00
|
|
|
filesize=$((blksz * nr))
|
|
|
|
|
_pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
|
2016-02-19 10:45:04 +11:00
|
|
|
_test_cycle_mount
|
2015-11-17 08:39:43 +11:00
|
|
|
|
|
|
|
|
echo "Create the reflink copies"
|
2016-02-08 09:27:15 +11:00
|
|
|
for i in `seq 2 $nr`; do
|
2016-02-10 00:33:10 -08:00
|
|
|
_cp_reflink $testdir/file1 $testdir/file$i
|
2015-11-17 08:39:43 +11:00
|
|
|
done
|
2016-02-19 10:45:04 +11:00
|
|
|
_test_cycle_mount
|
2016-02-10 00:33:10 -08:00
|
|
|
free_blocks1=$(stat -f $testdir -c '%f')
|
2015-11-17 08:39:43 +11:00
|
|
|
|
|
|
|
|
echo "funshare part of a file"
|
2016-10-17 15:09:28 -07:00
|
|
|
$XFS_IO_PROG -f -c "funshare 0 $((sz / 2))" $testdir/file2
|
2016-02-19 10:45:04 +11:00
|
|
|
_test_cycle_mount
|
2015-11-17 08:39:43 +11:00
|
|
|
|
|
|
|
|
echo "funshare some of the copies"
|
2016-10-17 15:09:28 -07:00
|
|
|
$XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file2
|
|
|
|
|
$XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file3
|
2016-02-19 10:45:04 +11:00
|
|
|
_test_cycle_mount
|
2016-02-10 00:33:10 -08:00
|
|
|
free_blocks2=$(stat -f $testdir -c '%f')
|
2015-11-17 08:39:43 +11:00
|
|
|
|
|
|
|
|
echo "funshare the rest of the files"
|
2016-10-17 15:09:28 -07:00
|
|
|
$XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file4
|
|
|
|
|
$XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file1
|
2016-02-19 10:45:04 +11:00
|
|
|
_test_cycle_mount
|
2016-02-10 00:33:10 -08:00
|
|
|
free_blocks3=$(stat -f $testdir -c '%f')
|
2015-11-17 08:39:43 +11:00
|
|
|
|
|
|
|
|
echo "Rewrite the original file"
|
2016-02-10 00:33:10 -08:00
|
|
|
_pwrite_byte 0x65 0 $sz $testdir/file1 >> $seqres.full
|
2016-02-19 10:45:04 +11:00
|
|
|
_test_cycle_mount
|
2016-02-10 00:33:10 -08:00
|
|
|
free_blocks4=$(stat -f $testdir -c '%f')
|
2016-02-08 09:27:15 +11:00
|
|
|
#echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3 $free_blocks4
|
2015-11-17 08:39:43 +11:00
|
|
|
|
2016-02-08 09:27:15 +11:00
|
|
|
_within_tolerance "free blocks after reflinking" $free_blocks1 $((free_blocks0 - blks)) $margin -v
|
2015-11-17 08:39:43 +11:00
|
|
|
|
2016-02-08 09:27:15 +11:00
|
|
|
_within_tolerance "free blocks after nocow'ing some copies" $free_blocks2 $((free_blocks1 - (2 * blks))) $margin -v
|
2015-11-17 08:39:43 +11:00
|
|
|
|
2016-02-08 09:27:15 +11:00
|
|
|
_within_tolerance "free blocks after nocow'ing all copies" $free_blocks3 $((free_blocks2 - blks)) $margin -v
|
2015-11-17 08:39:43 +11:00
|
|
|
|
2016-02-08 09:27:15 +11:00
|
|
|
_within_tolerance "free blocks after overwriting original" $free_blocks4 $free_blocks3 $margin -v
|
2015-11-17 08:39:43 +11:00
|
|
|
|
2016-02-08 09:27:15 +11:00
|
|
|
_within_tolerance "free blocks after all tests" $free_blocks4 $((free_blocks0 - (4 * blks))) $margin -v
|
2015-11-17 08:39:43 +11:00
|
|
|
|
|
|
|
|
# success, all done
|
|
|
|
|
status=0
|
|
|
|
|
exit
|