fstests: rename RENAME_WHITEOUT test on fs no enough space
[xfstests-dev.git] / tests / generic / 626
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2021 HUAWEI.  All Rights Reserved.
4 # Copyright (c) 2021 Red Hat Inc.  All Rights Reserved.
5 #
6 # FS QA Test No. 626
7 #
8 # Test RENAME_WHITEOUT on filesystem without space to create one more inodes.
9 # This is a regression test for kernel commit:
10 #   6b4b8e6b4ad8 ("ext4: ext4: fix bug for rename with RENAME_WHITEOUT")
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/populate
31 . ./common/renameat2
32
33 # remove previous $seqres.full before test
34 rm -f $seqres.full
35
36 # real QA test starts here
37 _supported_fs generic
38 _require_scratch
39 _require_renameat2 whiteout
40
41 _scratch_mkfs_sized $((256 * 1024 * 1024)) >> $seqres.full 2>&1
42 _scratch_mount
43
44 # Create lots of files, to help to trigger the bug easily
45 NR_FILE=$((4 * 64))
46 for ((i=0; i<NR_FILE; i++));do
47         touch $SCRATCH_MNT/srcfile$i
48 done
49 # Try to fill the whole fs
50 nr_free=$(stat -f -c '%f' $SCRATCH_MNT)
51 blksz="$(_get_block_size $SCRATCH_MNT)"
52 _fill_fs $((nr_free * blksz)) $SCRATCH_MNT/fill_space $blksz 0 >> $seqres.full 2>&1
53 # Use empty files to fill the rest
54 for ((i=0; i<10000; i++));do
55         touch $SCRATCH_MNT/fill_file$i 2>/dev/null
56         # Until no more files can be created
57         if [ $? -ne 0 ];then
58                 break
59         fi
60 done
61 # ENOSPC is expected here
62 for ((i=0; i<NR_FILE; i++));do
63         $here/src/renameat2 -w $SCRATCH_MNT/srcfile$i $SCRATCH_MNT/dstfile$i >> $seqres.full 2>&1
64 done
65 _scratch_cycle_mount
66 # Expect no errors at here
67 for ((i=0; i<NR_FILE; i++));do
68         ls -l $SCRATCH_MNT/srcfile$i >/dev/null
69 done
70
71 echo "Silence is golden"
72 # success, all done
73 status=0
74 exit