blob: 8306b301cde1d629d3edc55a01ed8bddd6f4feb7 (
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
#!/usr/bin/env bash
testdir=$(readlink -f $(dirname $0))
rootdir=$(readlink -f $testdir/../..)
source $rootdir/test/common/autotest_common.sh
source $rootdir/test/lvol/common.sh
# create an lvol on lvs, then remove the lvs
function test_hotremove_lvol_store() {
# create lvs + lvol on top
malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS)
lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test)
lvol_uuid=$(rpc_cmd bdev_lvol_create -u "$lvs_uuid" lvol_test "$LVS_DEFAULT_CAPACITY_MB")
# remove lvs (with one lvol open)
rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid"
rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" && false
lvolstores=$(rpc_cmd bdev_lvol_get_lvstores)
[ "$(jq length <<< "$lvolstores")" == "0" ]
# make sure we can't destroy the lvs again
rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" && false
# make sure the lvol is also gone
rpc_cmd bdev_get_bdevs -b "$lvol_uuid" && false
lvols=$(rpc_cmd bdev_get_bdevs | jq -r '[ .[] | select(.product_name == "Logical Volume") ]')
[ "$(jq length <<< "$lvols")" == "0" ]
# clean up
rpc_cmd bdev_malloc_delete "$malloc_name"
check_leftover_devices
}
# destroy lvs with 4 lvols on top
function test_hotremove_lvol_store_multiple_lvols() {
# create lvs
malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS)
lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test)
# calculate lvol size
lvol_size_mb=$(round_down $(((MALLOC_SIZE_MB - LVS_DEFAULT_CLUSTER_SIZE_MB) / 4)))
# create 4 lvols
for i in $(seq 1 4); do
rpc_cmd bdev_lvol_create -u "$lvs_uuid" "lvol_test${i}" "$lvol_size_mb"
done
lvols=$(rpc_cmd bdev_get_bdevs | jq -r '[ .[] | select(.product_name == "Logical Volume") ]')
[ "$(jq length <<< "$lvols")" == "4" ]
# remove lvs (with 4 lvols open)
rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid"
rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" && false
# make sure all lvols are gone
lvols=$(rpc_cmd bdev_get_bdevs | jq -r '[ .[] | select(.product_name == "Logical Volume") ]')
[ "$(jq length <<< "$lvols")" == "0" ]
# clean up
rpc_cmd bdev_malloc_delete "$malloc_name"
check_leftover_devices
}
# create an lvs on malloc, then remove just the malloc
function test_hotremove_lvol_store_base() {
# create lvs + lvol on top
malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS)
lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test)
# clean up
rpc_cmd bdev_malloc_delete "$malloc_name"
# make sure the lvs is gone
rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" && false
# make sure we can't delete the lvs again
rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" && false
check_leftover_devices
}
# create an lvs on malloc, then an lvol, then remove just the malloc
function test_hotremove_lvol_store_base_with_lvols() {
# create lvs + lvol on top
malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS)
lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test)
lvol_uuid=$(rpc_cmd bdev_lvol_create -u "$lvs_uuid" lvol_test "$LVS_DEFAULT_CAPACITY_MB")
rpc_cmd bdev_get_bdevs -b "$lvol_uuid"
# clean up
rpc_cmd bdev_malloc_delete "$malloc_name"
# make sure the lvol is gone
rpc_cmd bdev_get_bdevs -b "$lvol_uuid" && false
# make sure the lvs is gone as well
rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" && false
# make sure we can't delete the lvs again
rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" && false
check_leftover_devices
}
function test_bdev_lvol_delete_lvstore_with_clones() {
local snapshot_name1=snapshot1 snapshot_uuid1
local snapshot_name2=snapshot2 snapshot_uuid2
local clone_name=clone clone_uuid
local lbd_name=lbd_test
local bdev_uuid
local lvstore_name=lvs_name lvstore_uuid
local malloc_dev
malloc_dev=$(rpc_cmd bdev_malloc_create 256 "$MALLOC_BS")
lvstore_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_dev" "$lvstore_name")
get_lvs_jq bdev_lvol_get_lvstores -u "$lvstore_uuid"
[[ ${jq_out["uuid"]} == "$lvstore_uuid" ]]
[[ ${jq_out["name"]} == "$lvstore_name" ]]
[[ ${jq_out["base_bdev"]} == "$malloc_dev" ]]
size=$((jq_out["free_clusters"] * jq_out["cluster_size"] / 4 / 1024 ** 2))
bdev_uuid=$(rpc_cmd bdev_lvol_create -u "$lvstore_uuid" "$lbd_name" "$size")
get_bdev_jq bdev_get_bdevs -b "$bdev_uuid"
snapshot_uuid1=$(rpc_cmd bdev_lvol_snapshot "${jq_out["name"]}" "$snapshot_name1")
get_bdev_jq bdev_get_bdevs -b "$lvstore_name/$snapshot_name1"
[[ ${jq_out["name"]} == "$snapshot_uuid1" ]]
[[ ${jq_out["product_name"]} == "Logical Volume" ]]
[[ ${jq_out["aliases[0]"]} == "$lvstore_name/$snapshot_name1" ]]
clone_uuid=$(rpc_cmd bdev_lvol_clone "$lvstore_name/$snapshot_name1" "$clone_name")
get_bdev_jq bdev_get_bdevs -b "$lvstore_name/$clone_name"
[[ ${jq_out["name"]} == "$clone_uuid" ]]
[[ ${jq_out["product_name"]} == "Logical Volume" ]]
[[ ${jq_out["aliases[0]"]} == "$lvstore_name/$clone_name" ]]
snapshot_uuid2=$(rpc_cmd bdev_lvol_snapshot "${jq_out["name"]}" "$snapshot_name2")
get_bdev_jq bdev_get_bdevs -b "$lvstore_name/$snapshot_name2"
[[ ${jq_out["name"]} == "$snapshot_uuid2" ]]
[[ ${jq_out["product_name"]} == "Logical Volume" ]]
[[ ${jq_out["aliases[0]"]} == "$lvstore_name/$snapshot_name2" ]]
rpc_cmd bdev_lvol_delete "$snapshot_uuid1" && false
rpc_cmd bdev_lvol_delete_lvstore -u "$lvstore_uuid"
rpc_cmd bdev_malloc_delete "$malloc_dev"
check_leftover_devices
}
# Test for unregistering the lvol bdevs. Removing malloc bdev under an lvol
# store triggers unregister of all lvol bdevs. Verify it with clones present.
function test_unregister_lvol_bdev() {
local snapshot_name1=snapshot1 snapshot_uuid1
local snapshot_name2=snapshot2 snapshot_uuid2
local clone_name=clone clone_uuid
local lbd_name=lbd_test
local bdev_uuid
local lvstore_name=lvs_name lvstore_uuid
local malloc_dev
malloc_dev=$(rpc_cmd bdev_malloc_create 256 "$MALLOC_BS")
lvstore_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_dev" "$lvstore_name")
get_lvs_jq bdev_lvol_get_lvstores -u "$lvstore_uuid"
[[ ${jq_out["uuid"]} == "$lvstore_uuid" ]]
[[ ${jq_out["name"]} == "$lvstore_name" ]]
[[ ${jq_out["base_bdev"]} == "$malloc_dev" ]]
size=$((jq_out["free_clusters"] * jq_out["cluster_size"] / 4 / 1024 ** 2))
bdev_uuid=$(rpc_cmd bdev_lvol_create -u "$lvstore_uuid" "$lbd_name" "$size")
get_bdev_jq bdev_get_bdevs -b "$bdev_uuid"
snapshot_uuid1=$(rpc_cmd bdev_lvol_snapshot "${jq_out["name"]}" "$snapshot_name1")
get_bdev_jq bdev_get_bdevs -b "$lvstore_name/$snapshot_name1"
[[ ${jq_out["name"]} == "$snapshot_uuid1" ]]
[[ ${jq_out["product_name"]} == "Logical Volume" ]]
[[ ${jq_out["aliases[0]"]} == "$lvstore_name/$snapshot_name1" ]]
clone_uuid=$(rpc_cmd bdev_lvol_clone "$lvstore_name/$snapshot_name1" "$clone_name")
get_bdev_jq bdev_get_bdevs -b "$lvstore_name/$clone_name"
[[ ${jq_out["name"]} == "$clone_uuid" ]]
[[ ${jq_out["product_name"]} == "Logical Volume" ]]
[[ ${jq_out["aliases[0]"]} == "$lvstore_name/$clone_name" ]]
snapshot_uuid2=$(rpc_cmd bdev_lvol_snapshot "${jq_out["name"]}" "$snapshot_name2")
get_bdev_jq bdev_get_bdevs -b "$lvstore_name/$snapshot_name2"
[[ ${jq_out["name"]} == "$snapshot_uuid2" ]]
[[ ${jq_out["product_name"]} == "Logical Volume" ]]
[[ ${jq_out["aliases[0]"]} == "$lvstore_name/$snapshot_name2" ]]
rpc_cmd bdev_malloc_delete "$malloc_dev"
check_leftover_devices
}
$SPDK_BIN_DIR/spdk_tgt &
spdk_pid=$!
trap 'killprocess "$spdk_pid"; exit 1' SIGINT SIGTERM EXIT
waitforlisten $spdk_pid
run_test "test_hotremove_lvol_store" test_hotremove_lvol_store
run_test "test_hotremove_lvol_store_multiple_lvols" test_hotremove_lvol_store_multiple_lvols
run_test "test_hotremove_lvol_store_base" test_hotremove_lvol_store_base
run_test "test_hotremove_lvol_store_base_with_lvols" test_hotremove_lvol_store_base_with_lvols
run_test "test_bdev_lvol_delete_lvstore_with_clones" test_bdev_lvol_delete_lvstore_with_clones
run_test "test_unregister_lvol_bdev" test_unregister_lvol_bdev
trap - SIGINT SIGTERM EXIT
killprocess $spdk_pid
|