generic/563: use a loop device to avoid partition incompatibility
[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 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31
32 # remove previous $seqres.full before test
33 rm -f $seqres.full
34
35 # real QA test starts here
36
37 # Modify as appropriate.
38 _supported_fs btrfs
39 _require_scratch_dev_pool 2
40 _scratch_dev_pool_get 2
41
42 # Here we use 4k node size to reduce runtime (explained near _scratch_mkfs call)
43 # To use the minimal node size (4k) we need 4K page size.
44 if [ $(get_page_size) != 4096 ]; then
45         _notrun "This test need 4k page size"
46 fi
47
48 device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
49 device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
50
51 echo device_1=$device_1 device_2=$device_2 >> $seqres.full
52
53 # The wrong check limit is based on the max item size (BTRFS_MAX_DEVS() macro),
54 # and max item size is based on node size, so smaller node size will result
55 # much shorter runtime. So here we use minimal node size (4K) to reduce runtime.
56 _scratch_mkfs -n 4k >> $seqres.full
57 _scratch_mount
58
59 # For 4k nodesize, the wrong limit is calculated by:
60 # ((4096 - 101 - 25 - 80) / 32) + 1
61 #    |      |    |    |     |- sizeof(btrfs_stripe)
62 #    |      |    |    |- sizeof(btrfs_chunk)
63 #    |      |    |- sizeof(btrfs_item)
64 #    |      |- sizeof(btrfs_header)
65 #    |- node size
66 # Which is 122.
67 #
68 # The old limit is wrong because it doesn't take devid holes into consideration.
69 # We can have large devid, but still have only 1 device.
70 #
71 # Add and remove device in a loop, each iteration will increase devid by 2.
72 # So by 64 iterations, we will definitely hit that 122 limit.
73 for (( i = 0; i < 64; i++ )); do
74         $BTRFS_UTIL_PROG device add -f $device_2 $SCRATCH_MNT
75         $BTRFS_UTIL_PROG device del $device_1 $SCRATCH_MNT
76         $BTRFS_UTIL_PROG device add -f $device_1 $SCRATCH_MNT
77         $BTRFS_UTIL_PROG device del $device_2 $SCRATCH_MNT
78 done
79 _scratch_dev_pool_put
80
81 echo "Silence is golden"
82
83 # success, all done
84 status=0
85 exit