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 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
28 # get standard environment, filters and checks
32 # remove previous $seqres.full before test
35 # real QA test starts here
37 # Modify as appropriate.
40 _require_scratch_dev_pool 2
41 _scratch_dev_pool_get 2
43 # Here we use 4k node size to reduce runtime (explained near _scratch_mkfs call)
44 # To use the minimal node size (4k) we need 4K page size.
45 if [ $(get_page_size) != 4096 ]; then
46 _notrun "This test need 4k page size"
49 device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
50 device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
52 echo device_1=$device_1 device_2=$device_2 >> $seqres.full
54 # The wrong check limit is based on the max item size (BTRFS_MAX_DEVS() macro),
55 # and max item size is based on node size, so smaller node size will result
56 # much shorter runtime. So here we use minimal node size (4K) to reduce runtime.
57 _scratch_mkfs -n 4k >> $seqres.full
60 # For 4k nodesize, the wrong limit is calculated by:
61 # ((4096 - 101 - 25 - 80) / 32) + 1
62 # | | | | |- sizeof(btrfs_stripe)
63 # | | | |- sizeof(btrfs_chunk)
64 # | | |- sizeof(btrfs_item)
65 # | |- sizeof(btrfs_header)
69 # The old limit is wrong because it doesn't take devid holes into consideration.
70 # We can have large devid, but still have only 1 device.
72 # Add and remove device in a loop, each iteration will increase devid by 2.
73 # So by 64 iterations, we will definitely hit that 122 limit.
74 for (( i = 0; i < 64; i++ )); do
75 $BTRFS_UTIL_PROG device add -f $device_2 $SCRATCH_MNT
76 $BTRFS_UTIL_PROG device del $device_1 $SCRATCH_MNT
77 $BTRFS_UTIL_PROG device add -f $device_1 $SCRATCH_MNT
78 $BTRFS_UTIL_PROG device del $device_2 $SCRATCH_MNT
82 echo "Silence is golden"