generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 171
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 171
6 #
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.
9 #
10 . ./common/preamble
11 _begin_fstest auto quick clone
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16     cd /
17     rm -rf $tmp.* $testdir1
18 }
19
20 # Import common functions.
21 . ./common/populate
22 . ./common/filter
23 . ./common/attr
24 . ./common/reflink
25
26 # real QA test starts here
27 _require_scratch_reflink
28 _require_cp_reflink
29
30 echo "Format and mount"
31 _scratch_mkfs > $seqres.full 2>&1
32 _scratch_mount >> $seqres.full 2>&1
33
34 testdir=$SCRATCH_MNT/test-$seq
35 mkdir $testdir
36
37 echo "Reformat with appropriate size"
38 blksz="$(_get_block_size $testdir)"
39 nr_blks=10240
40 umount $SCRATCH_MNT
41 sz_bytes=$((nr_blks * 8 * blksz))
42 if [ $sz_bytes -lt $((32 * 1048576)) ]; then
43         sz_bytes=$((32 * 1048576))
44 fi
45 _scratch_mkfs_sized $sz_bytes >> $seqres.full 2>&1
46 _scratch_mount >> $seqres.full 2>&1
47 rm -rf $testdir
48 mkdir $testdir
49
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
53 sync
54
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
58 sync
59
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
65 echo ${out}
66
67 echo "Remount and try CoW again"
68 _scratch_cycle_mount
69
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
74 echo ${out}
75
76 # success, all done
77 status=0
78 exit