generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / btrfs / 194
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test 194
6 #
7 # Test if btrfs can handle large device ids.
8 #
9 # The regression is introduced by kernel commit ab4ba2e13346 ("btrfs:
10 # tree-checker: Verify dev item").
11 # The fix is titled: "btrfs: tree-checker: Fix wrong check on max devid"
12 #
13 . ./common/preamble
14 _begin_fstest auto volume
15
16 # Import common functions.
17 . ./common/filter
18
19 # real QA test starts here
20
21 # Modify as appropriate.
22 _supported_fs btrfs
23 _require_scratch_dev_pool 2
24 _scratch_dev_pool_get 2
25
26 # Here we use 4k node size to reduce runtime (explained near _scratch_mkfs call)
27 # To use the minimal node size (4k) we need 4K page size.
28 if [ $(get_page_size) != 4096 ]; then
29         _notrun "This test need 4k page size"
30 fi
31
32 device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
33 device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
34
35 echo device_1=$device_1 device_2=$device_2 >> $seqres.full
36
37 # The wrong check limit is based on the max item size (BTRFS_MAX_DEVS() macro),
38 # and max item size is based on node size, so smaller node size will result
39 # much shorter runtime. So here we use minimal node size (4K) to reduce runtime.
40 _scratch_mkfs -n 4k >> $seqres.full
41 _scratch_mount
42
43 # For 4k nodesize, the wrong limit is calculated by:
44 # ((4096 - 101 - 25 - 80) / 32) + 1
45 #    |      |    |    |     |- sizeof(btrfs_stripe)
46 #    |      |    |    |- sizeof(btrfs_chunk)
47 #    |      |    |- sizeof(btrfs_item)
48 #    |      |- sizeof(btrfs_header)
49 #    |- node size
50 # Which is 122.
51 #
52 # The old limit is wrong because it doesn't take devid holes into consideration.
53 # We can have large devid, but still have only 1 device.
54 #
55 # Add and remove device in a loop, each iteration will increase devid by 2.
56 # So by 64 iterations, we will definitely hit that 122 limit.
57 for (( i = 0; i < 64; i++ )); do
58         $BTRFS_UTIL_PROG device add -f $device_2 $SCRATCH_MNT
59         $BTRFS_UTIL_PROG device del $device_1 $SCRATCH_MNT
60         $BTRFS_UTIL_PROG device add -f $device_1 $SCRATCH_MNT
61         $BTRFS_UTIL_PROG device del $device_2 $SCRATCH_MNT
62 done | grep -v 'Resetting device zone'
63 _scratch_dev_pool_put
64
65 echo "Silence is golden"
66
67 # success, all done
68 status=0
69 exit