generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 172
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. 172
6 #
7 # Reflink a file that uses more than half of the space, then try to observe
8 # ENOSPC 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 umount $SCRATCH_MNT
40
41 file_size=$((768 * 1024 * 1024))
42 fs_size=$((1024 * 1024 * 1024))
43 _scratch_mkfs_sized $fs_size >> $seqres.full 2>&1 || _fail "mkfs failed"
44 _scratch_mount >> $seqres.full 2>&1
45 rm -rf $testdir
46 mkdir $testdir
47
48 echo "Create a big file and reflink it"
49 _pwrite_byte 0x61 0 $file_size $testdir/bigfile >> $seqres.full 2>&1
50 _cp_reflink $testdir/bigfile $testdir/clonefile
51 sync
52
53 echo "Allocate the rest of the space"
54 _fill_fs $fs_size  $testdir/space $blksz 0 >> $seqres.full 2>&1
55 sync
56
57 echo "CoW the big file"
58 out="$(_pwrite_byte 0x62 0 $file_size $testdir/bigfile 2>&1 | \
59         _filter_xfs_io_error)"
60 echo ${out} | grep -q "No space left on device" || echo "CoW should have failed with ENOSPC"
61 echo ${out} >> $seqres.full 2>&1
62 echo ${out}
63
64 echo "Remount and try CoW again"
65 _scratch_cycle_mount
66
67 out="$(_pwrite_byte 0x62 0 $file_size $testdir/bigfile 2>&1 | \
68         _filter_xfs_io_error)"
69 echo ${out} | grep -q "No space left on device" || echo "CoW should have failed with ENOSPC"
70 echo ${out} >> $seqres.full 2>&1
71 echo ${out}
72
73 # success, all done
74 status=0
75 exit