2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2021 Anand Jain. All Rights Reserved.
4 # Copyright (c) 2021 Oracle. All Rights Reserved.
8 # Test if the kernel can free the stale device entries.
10 # Tests bug fixed by the kernel patch:
11 # btrfs: harden identification of the stale device
14 _begin_fstest auto quick
16 # Override the default cleanup function.
27 rm -rf $seq_mnt > /dev/null 2>&1
31 # Import common functions.
33 . ./common/filter.btrfs
35 # real QA test starts here
37 _require_scratch_dev_pool 3
38 _require_block_device $SCRATCH_DEV
39 _require_dm_target linear
40 _require_btrfs_forget_or_module_loadable
41 _require_scratch_nocheck
42 _require_command "$WIPEFS_PROG" wipefs
44 _scratch_dev_pool_get 3
49 size=$((1024 * 1024 * 1024))
50 size_in_sector=$((size / 512))
52 table="0 $size_in_sector linear $SCRATCH_DEV 0"
53 _dmsetup_create $node --table "$table" || \
54 _fail "setup dm device failed"
57 # Use a known it is much easier to debug.
58 uuid="--uuid 12345678-1234-1234-1234-123456789abc"
59 lvdev=/dev/mapper/$node
61 seq_mnt=$TEST_DIR/$seq.mnt
67 dmdev=$(realpath $lvdev)
69 _mkfs_dev $uuid $dmdev
71 # Check if we can un-scan using the mapper device path.
72 $BTRFS_UTIL_PROG device scan --forget $lvdev
75 $WIPEFS_PROG -a $lvdev > /dev/null 2>&1
76 $BTRFS_UTIL_PROG device scan --forget
84 dmdev=$(realpath $lvdev)
85 scratch_dev2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
86 scratch_dev3=$(echo $SCRATCH_DEV_POOL | awk '{print $3}')
88 _mkfs_dev $scratch_dev3
89 _mount $scratch_dev3 $seq_mnt
91 _mkfs_dev $uuid -draid1 -mraid1 $lvdev $scratch_dev2
93 # Add device should free the device under $uuid in the kernel.
94 $BTRFS_UTIL_PROG device add -f $dmdev $seq_mnt > /dev/null 2>&1
96 _mount -o degraded $scratch_dev2 $SCRATCH_MNT
98 # Check if the missing device is shown.
99 $BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
100 _filter_btrfs_filesystem_show
102 $UMOUNT_PROG $seq_mnt
110 _scratch_dev_pool_put