generic: Verify the inheritance behavior of FS_XFLAG_DAX flag in various combinations
[xfstests-dev.git] / tests / generic / 173
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. 173
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 mmap.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1    # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21     cd /
22     rm -rf $tmp.* $testdir1
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/populate
28 . ./common/filter
29 . ./common/attr
30 . ./common/reflink
31
32 # real QA test starts here
33 _supported_os Linux
34 _require_scratch_reflink
35 _require_cp_reflink
36
37 rm -f $seqres.full
38
39 echo "Format and mount"
40 _scratch_mkfs > $seqres.full 2>&1
41 _scratch_mount >> $seqres.full 2>&1
42
43 testdir=$SCRATCH_MNT/test-$seq
44 mkdir $testdir
45
46 echo "Reformat with appropriate size"
47 blksz="$(_get_block_size $testdir)"
48 nr_blks=10240
49 umount $SCRATCH_MNT
50 sz_bytes=$((nr_blks * 8 * blksz))
51 if [ $sz_bytes -lt $((32 * 1048576)) ]; then
52         sz_bytes=$((32 * 1048576))
53 fi
54 _scratch_mkfs_sized $sz_bytes >> $seqres.full 2>&1
55 _scratch_mount >> $seqres.full 2>&1
56 rm -rf $testdir
57 mkdir $testdir
58
59 echo "Create a big file and reflink it"
60 _pwrite_byte 0x61 0 $((blksz * nr_blks)) $testdir/bigfile >> $seqres.full 2>&1
61 _cp_reflink $testdir/bigfile $testdir/clonefile
62 sync
63
64 echo "Allocate the rest of the space"
65 nr_free=$(stat -f -c '%f' $testdir)
66 _fill_fs $((blksz * nr_free)) $testdir/space $blksz 0 >> $seqres.full 2>&1
67 sync
68
69 echo "mmap CoW the big file"
70 core_ulimit="$(ulimit -c)"
71 ulimit -c 0
72 out="$(_mwrite_byte 0x62 0 $((blksz * nr_blks)) $((blksz * nr_blks)) $testdir/bigfile 2>&1)"
73 err="$?"
74 if [ $err -lt 128 ]; then
75         echo "mmap CoW should have failed with SIGBUS, got SIG$(kill -l $err)"
76 fi
77
78 echo "Remount and try CoW again"
79 _scratch_cycle_mount
80
81 out="$(_mwrite_byte 0x62 0 $((blksz * nr_blks)) $((blksz * nr_blks)) $testdir/bigfile 2>&1)"
82 err="$?"
83 if [ $err -lt 128 ]; then
84         echo "mmap CoW should have failed with SIGBUS, got SIG$(kill -l $err)"
85 fi
86 ulimit -c "${core_ulimit}"
87
88 # success, all done
89 status=0
90 exit