generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
13 _begin_fstest auto quick rename enospc
14
15 # Import common functions.
16 . ./common/filter
17 . ./common/populate
18 . ./common/renameat2
19
20 # real QA test starts here
21 _supported_fs generic
22 _require_scratch
23 _require_renameat2 whiteout
24
25 _scratch_mkfs_sized $((256 * 1024 * 1024)) >> $seqres.full 2>&1
26 _scratch_mount
27
28 # Create lots of files, to help to trigger the bug easily
29 NR_FILE=$((4 * 64))
30 for ((i=0; i<NR_FILE; i++));do
31         touch $SCRATCH_MNT/srcfile$i
32 done
33 # Try to fill the whole fs
34 nr_free=$(stat -f -c '%f' $SCRATCH_MNT)
35 blksz="$(_get_block_size $SCRATCH_MNT)"
36 _fill_fs $((nr_free * blksz)) $SCRATCH_MNT/fill_space $blksz 0 >> $seqres.full 2>&1
37 # Use empty files to fill the rest
38 for ((i=0; i<10000; i++));do
39         touch $SCRATCH_MNT/fill_file$i 2>/dev/null
40         # Until no more files can be created
41         if [ $? -ne 0 ];then
42                 break
43         fi
44 done
45 # ENOSPC is expected here
46 for ((i=0; i<NR_FILE; i++));do
47         $here/src/renameat2 -w $SCRATCH_MNT/srcfile$i $SCRATCH_MNT/dstfile$i >> $seqres.full 2>&1
48 done
49 _scratch_cycle_mount
50 # Expect no errors at here
51 for ((i=0; i<NR_FILE; i++));do
52         ls -l $SCRATCH_MNT/srcfile$i >/dev/null
53 done
54
55 echo "Silence is golden"
56 # success, all done
57 status=0
58 exit