4 # Reflink a file that uses more than half of the space, then try to observe
5 # ENOSPC while copy-on-writing the file via the page cache.
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #-----------------------------------------------------------------------
25 seqres="$RESULT_DIR/$seq"
26 echo "QA output created by $seq"
30 status=1 # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
36 rm -rf "$tmp".* "$TESTDIR1"
39 # get standard environment, filters and checks
45 # real QA test starts here
47 _require_scratch_reflink
52 echo "Format and mount"
53 _scratch_mkfs > "$seqres.full" 2>&1
54 _scratch_mount >> "$seqres.full" 2>&1
56 TESTDIR="$SCRATCH_MNT/test-$seq"
60 echo "Reformat with appropriate size"
61 BLKSZ="$(stat -f "$TESTDIR" -c '%S')"
64 SZ_BYTES=$((NR_BLKS * 3 / 2 * BLKSZ))
65 if [ $SZ_BYTES -lt $((32 * 1048576)) ]; then
66 SZ_BYTES=$((32 * 1048576))
68 _scratch_mkfs_sized $SZ_BYTES >> "$seqres.full" 2>&1
69 _scratch_mount >> "$seqres.full" 2>&1
73 echo "Create a big file and reflink it"
74 _pwrite_byte 0x61 0 $((BLKSZ * NR_BLKS)) "$TESTDIR/bigfile" >> "$seqres.full" 2>&1
75 _cp_reflink "$TESTDIR/bigfile" "$TESTDIR/clonefile"
78 echo "Allocate the rest of the space"
79 NR_FREE="$(stat -f -c '%f' "$TESTDIR")"
80 touch "$TESTDIR/file0" "$TESTDIR/file1"
81 _pwrite_byte 0x61 0 $((BLKSZ * NR_FREE)) "$TESTDIR/eat_my_space" >> "$seqres.full" 2>&1
84 echo "CoW the big file"
85 out="$(_pwrite_byte 0x62 0 $((BLKSZ * NR_BLKS)) "$TESTDIR/bigfile" 2>&1)"
86 echo "${out}" | grep -q "No space left on device" || echo "CoW should have failed with ENOSPC"
87 echo "${out}" >> "$seqres.full" 2>&1
90 echo "Remount and try CoW again"
93 out="$(_pwrite_byte 0x62 0 $((BLKSZ * NR_BLKS)) "$TESTDIR/bigfile" 2>&1)"
94 echo "${out}" | grep -q "No space left on device" || echo "CoW should have failed with ENOSPC"
95 echo "${out}" >> "$seqres.full" 2>&1
98 #filefrag -v $TESTDIR/bigfile
99 #filefrag -v $TESTDIR/clonefile
101 echo "Check scratch fs"
102 umount "$SCRATCH_MNT"