2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test if btrfs can handle large device ids.
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"
14 _begin_fstest auto volume
16 # Import common functions.
19 # real QA test starts here
21 # Modify as appropriate.
23 _require_scratch_dev_pool 2
24 _scratch_dev_pool_get 2
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"
32 device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
33 device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
35 echo device_1=$device_1 device_2=$device_2 >> $seqres.full
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
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)
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.
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 >> $seqres.full
59 $BTRFS_UTIL_PROG device del $device_1 $SCRATCH_MNT
60 $BTRFS_UTIL_PROG device add -f $device_1 $SCRATCH_MNT >> $seqres.full
61 $BTRFS_UTIL_PROG device del $device_2 $SCRATCH_MNT
62 done | grep -v 'Resetting device zone'
65 echo "Silence is golden"