blob: c789d8744899a087142654c74addd8e7372fdc0e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2021 Anand Jain. All Rights Reserved.
# Copyright (c) 2021 Oracle. All Rights Reserved.
#
# FS QA Test No. 254
#
# Test if the kernel can free the stale device entries.
#
. ./common/preamble
_begin_fstest auto quick volume
# Override the default cleanup function.
node=$seq-test
cleanup_dmdev()
{
_dmsetup_remove $node
}
_cleanup()
{
cd /
rm -f $tmp.*
rm -rf $seq_mnt > /dev/null 2>&1
cleanup_dmdev
}
. ./common/filter
. ./common/filter.btrfs
_supported_fs btrfs
_require_scratch_dev_pool 3
_require_block_device $SCRATCH_DEV
_require_dm_target linear
_require_btrfs_forget_or_module_loadable
_require_scratch_nocheck
_require_command "$WIPEFS_PROG" wipefs
_check_minimal_fs_size $((1024 * 1024 * 1024))
_fixed_by_kernel_commit 770c79fb6550 \
"btrfs: harden identification of a stale device"
_scratch_dev_pool_get 3
setup_dmdev()
{
# Some small size.
size=$((1024 * 1024 * 1024))
size_in_sector=$((size / 512))
table="0 $size_in_sector linear $SCRATCH_DEV 0"
_dmsetup_create $node --table "$table" || \
_fail "setup dm device failed"
}
# Use a known it is much easier to debug.
lvdev=/dev/mapper/$node
seq_mnt=$TEST_DIR/$seq.mnt
mkdir -p $seq_mnt
test_forget()
{
setup_dmdev
dmdev=$(realpath $lvdev)
_mkfs_dev $dmdev
# Check if we can un-scan using the mapper device path.
$BTRFS_UTIL_PROG device scan --forget $lvdev
# Cleanup
$WIPEFS_PROG -a $lvdev > /dev/null 2>&1
$BTRFS_UTIL_PROG device scan --forget
cleanup_dmdev
}
test_add_device()
{
setup_dmdev
dmdev=$(realpath $lvdev)
scratch_dev2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
scratch_dev3=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $3}')
_mkfs_dev $scratch_dev3
_mount $scratch_dev3 $seq_mnt
_mkfs_dev -draid1 -mraid1 $lvdev $scratch_dev2
# Added device should free the stale device in the kernel.
$BTRFS_UTIL_PROG device add -f $dmdev $seq_mnt > /dev/null 2>&1
_mount -o degraded $scratch_dev2 $SCRATCH_MNT
# Check if the missing device is shown.
$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
_filter_btrfs_filesystem_show
$UMOUNT_PROG $seq_mnt
_scratch_unmount
cleanup_dmdev
}
test_forget
test_add_device
_scratch_dev_pool_put
status=0
exit
|