2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Reflink a file, use up the rest of the space, then try to observe ENOSPC
8 # while copy-on-writing the file via the page cache.
11 _begin_fstest auto quick clone
13 # Override the default cleanup function.
17 rm -rf $tmp.* $testdir1
20 # Import common functions.
26 # real QA test starts here
27 _require_scratch_reflink
30 echo "Format and mount"
31 _scratch_mkfs > $seqres.full 2>&1
32 _scratch_mount >> $seqres.full 2>&1
34 testdir=$SCRATCH_MNT/test-$seq
37 echo "Reformat with appropriate size"
38 blksz="$(_get_block_size $testdir)"
41 sz_bytes=$((nr_blks * 8 * blksz))
42 if [ $sz_bytes -lt $((32 * 1048576)) ]; then
43 sz_bytes=$((32 * 1048576))
45 _scratch_mkfs_sized $sz_bytes >> $seqres.full 2>&1
46 _scratch_mount >> $seqres.full 2>&1
50 echo "Create a big file and reflink it"
51 _pwrite_byte 0x61 0 $((blksz * nr_blks)) $testdir/bigfile >> $seqres.full 2>&1
52 _cp_reflink $testdir/bigfile $testdir/clonefile
55 echo "Allocate the rest of the space"
56 nr_free=$(stat -f -c '%f' $testdir)
57 _fill_fs $((nr_free * blksz)) $testdir/space $blksz 0 >> $seqres.full 2>&1
60 echo "CoW the big file"
61 out="$(_pwrite_byte 0x62 0 $((blksz * nr_blks)) $testdir/bigfile 2>&1 | \
62 _filter_xfs_io_error)"
63 echo ${out} | grep -q "No space left on device" || echo "CoW should have failed with ENOSPC"
64 echo ${out} >> $seqres.full 2>&1
67 echo "Remount and try CoW again"
70 out="$(_pwrite_byte 0x62 0 $((blksz * nr_blks)) $testdir/bigfile 2>&1 | \
71 _filter_xfs_io_error)"
72 echo ${out} | grep -q "No space left on device" || echo "CoW should have failed with ENOSPC"
73 echo ${out} >> $seqres.full 2>&1