btrfs/139: require 2GB scratch dev
[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 _supported_os Linux
40 _require_scratch_dev_pool 2
41 _scratch_dev_pool_get 2
42
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"
47 fi
48
49 device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
50 device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
51
52 echo device_1=$device_1 device_2=$device_2 >> $seqres.full
53
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
58 _scratch_mount
59
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)
66 #    |- node size
67 # Which is 122.
68 #
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.
71 #
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
79 done
80 _scratch_dev_pool_put
81
82 echo "Silence is golden"
83
84 # success, all done
85 status=0
86 exit