generic: test for creating duplicate filenames in encrypted dir
[xfstests-dev.git] / tests / generic / 156
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. 156
6 #
7 # Ensure that fallocate on reflinked files actually CoWs the shared blocks.
8 #   - Record fs block usage (0)
9 #   - Create a file and some reflink copies
10 #   - Record fs block usage (1)
11 #   - funshare half of one of the copies
12 #   - Record fs block usage (2)
13 #   - funshare all of the copies
14 #   - Record fs block usage (3)
15 #   - rewrite the original file
16 #   - Record fs block usage (4)
17 #   - Compare fs block usage of 0-4 to ensure that block usage behaves as
18 #     we expect.
19 #
20 # "funshare" refers to fallocate copy-on-writing the shared blocks
21 #
22 seq=`basename $0`
23 seqres=$RESULT_DIR/$seq
24 echo "QA output created by $seq"
25
26 here=`pwd`
27 tmp=/tmp/$$
28 status=1    # failure is the default!
29 trap "_cleanup; exit \$status" 0 1 2 3 15
30
31 _cleanup()
32 {
33     cd /
34     rm -rf $tmp.* $testdir
35 }
36
37 # get standard environment, filters and checks
38 . ./common/rc
39 . ./common/filter
40 . ./common/attr
41 . ./common/reflink
42
43 # real QA test starts here
44 _require_test_reflink
45 _require_cp_reflink
46 _require_xfs_io_command "funshare"
47
48 rm -f $seqres.full
49
50 testdir=$TEST_DIR/test-$seq
51 rm -rf $testdir
52 mkdir $testdir
53
54 echo "Create the original file blocks"
55 blksz="$(_get_block_size $testdir)"
56 blks=2000
57 margin='15%'
58 sz=$((blksz * blks))
59 free_blocks0=$(stat -f $testdir -c '%f')
60 nr=4
61 filesize=$((blksz * nr))
62 _pwrite_byte 0x61 0 $sz $testdir/file1 >> $seqres.full
63 _test_cycle_mount
64
65 echo "Create the reflink copies"
66 for i in `seq 2 $nr`; do
67         _cp_reflink $testdir/file1 $testdir/file$i
68 done
69 _test_cycle_mount
70 free_blocks1=$(stat -f $testdir -c '%f')
71
72 echo "funshare part of a file"
73 $XFS_IO_PROG -f -c "funshare 0 $((sz / 2))" $testdir/file2
74 _test_cycle_mount
75
76 echo "funshare some of the copies"
77 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file2
78 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file3
79 _test_cycle_mount
80 free_blocks2=$(stat -f $testdir -c '%f')
81
82 echo "funshare the rest of the files"
83 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file4
84 $XFS_IO_PROG -f -c "funshare 0 $sz" $testdir/file1
85 _test_cycle_mount
86 free_blocks3=$(stat -f $testdir -c '%f')
87
88 echo "Rewrite the original file"
89 _pwrite_byte 0x65 0 $sz $testdir/file1 >> $seqres.full
90 _test_cycle_mount
91 free_blocks4=$(stat -f $testdir -c '%f')
92 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3 $free_blocks4
93
94 _within_tolerance "free blocks after reflinking" $free_blocks1 $((free_blocks0 - blks)) $margin -v
95
96 _within_tolerance "free blocks after nocow'ing some copies" $free_blocks2 $((free_blocks1 - (2 * blks))) $margin -v
97
98 _within_tolerance "free blocks after nocow'ing all copies" $free_blocks3 $((free_blocks2 - blks)) $margin -v
99
100 _within_tolerance "free blocks after overwriting original" $free_blocks4 $free_blocks3 $margin -v
101
102 _within_tolerance "free blocks after all tests" $free_blocks4 $((free_blocks0 - (4 * blks))) $margin -v
103
104 # success, all done
105 status=0
106 exit