generic: test for creating duplicate filenames in encrypted dir
[xfstests-dev.git] / tests / generic / 447
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 447
6 #
7 # See how well we handle deleting a file with a million refcount extents.
8 #
9 seq=`basename "$0"`
10 seqres="$RESULT_DIR/$seq"
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1    # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20     cd /
21     rm -f "$tmp".* $testdir/file1
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/attr
28 . ./common/reflink
29
30 # real QA test starts here
31 _require_scratch_reflink
32 _require_cp_reflink
33 _require_test_program "punch-alternating"
34 _require_xfs_io_command "fpunch"
35
36 rm -f "$seqres.full"
37
38 echo "Format and mount"
39 _scratch_mkfs > "$seqres.full" 2>&1
40 _scratch_mount >> "$seqres.full" 2>&1
41
42 testdir="$SCRATCH_MNT/test-$seq"
43 mkdir "$testdir"
44
45 # Setup for one million blocks, but we'll accept stress testing down to
46 # 2^17 blocks... that should be plenty for anyone.
47 fnr=20
48 free_blocks=$(stat -f -c '%a' "$testdir")
49 blksz=$(_get_block_size "$testdir")
50 space_avail=$((free_blocks * blksz))
51 calc_space() {
52         blocks_needed=$(( 2 ** (fnr + 1) ))
53         space_needed=$((blocks_needed * blksz * 5 / 4))
54 }
55 calc_space
56 while test $space_needed -gt $space_avail; do
57         fnr=$((fnr - 1))
58         calc_space
59 done
60 test $fnr -lt 17 && _notrun "Insufficient space for stress test; would only create $blocks_needed extents ($space_needed/$space_avail blocks)."
61
62 echo "Create a many-block file"
63 echo "creating $blocks_needed blocks..." >> "$seqres.full"
64 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b 4194304 0 $((2 ** (fnr + 1) * blksz))" "$testdir/file1" >> "$seqres.full"
65
66 echo "Reflinking file"
67 _cp_reflink $testdir/file1 $testdir/file2
68
69 echo "Punch file2"
70 echo "Punching file2..." >> "$seqres.full"
71 "$here/src/punch-alternating" "$testdir/file2" >> "$seqres.full"
72 echo "...done" >> "$seqres.full"
73 _scratch_cycle_mount
74
75 echo "Delete file1"
76 rm -rf $testdir/file1
77
78 # success, all done
79 status=0
80 exit