1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2019 Intel Corporation 4# All rights reserved. 5# 6testdir=$(readlink -f $(dirname $0)) 7rootdir=$(readlink -f $testdir/../..) 8source $rootdir/test/common/autotest_common.sh 9source $rootdir/test/lvol/common.sh 10source "$rootdir/test/bdev/nbd_common.sh" 11 12# create empty lvol store and verify its parameters 13function test_construct_lvs() { 14 # create a malloc bdev 15 malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 16 17 # create a valid lvs 18 lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test) 19 lvs=$(rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid") 20 21 # try to destroy inexistent lvs, this should obviously fail 22 dummy_uuid="00000000-0000-0000-0000-000000000000" 23 NOT rpc_cmd bdev_lvol_delete_lvstore -u "$dummy_uuid" 24 # our lvs should not be impacted 25 rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" 26 27 # verify it's there 28 [ "$(jq -r '.[0].uuid' <<< "$lvs")" = "$lvs_uuid" ] 29 [ "$(jq -r '.[0].name' <<< "$lvs")" = "lvs_test" ] 30 [ "$(jq -r '.[0].base_bdev' <<< "$lvs")" = "$malloc_name" ] 31 32 # verify some of its parameters 33 cluster_size=$(jq -r '.[0].cluster_size' <<< "$lvs") 34 [ "$cluster_size" = "$LVS_DEFAULT_CLUSTER_SIZE" ] 35 total_clusters=$(jq -r '.[0].total_data_clusters' <<< "$lvs") 36 [ "$(jq -r '.[0].free_clusters' <<< "$lvs")" = "$total_clusters" ] 37 [ "$((total_clusters * cluster_size))" = "$LVS_DEFAULT_CAPACITY" ] 38 39 # remove the lvs and verify it's gone 40 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" 41 NOT rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" 42 # make sure we can't delete the same lvs again 43 NOT rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" 44 45 rpc_cmd bdev_malloc_delete "$malloc_name" 46 check_leftover_devices 47} 48 49# call bdev_lvol_create_lvstore with base bdev name which does not 50# exist in configuration 51function test_construct_lvs_nonexistent_bdev() { 52 # make sure we can't create lvol store on nonexistent bdev 53 rpc_cmd bdev_lvol_create_lvstore NotMalloc lvs_test && false 54 return 0 55} 56 57# try to create two lvol stores on the same bdev 58function test_construct_two_lvs_on_the_same_bdev() { 59 # create an lvol store 60 malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 61 lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test) 62 63 # try to create another lvs on the same malloc bdev 64 rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test2 && false 65 66 # clean up 67 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" 68 rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" && false 69 rpc_cmd bdev_malloc_delete "$malloc_name" 70 rpc_cmd bdev_get_bdevs -b "$malloc_name" && false 71 check_leftover_devices 72} 73 74# try to create two lvs with conflicting aliases 75function test_construct_lvs_conflict_alias() { 76 # create first bdev and lvs 77 malloc1_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 78 lvs1_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc1_name" lvs_test) 79 80 # create second bdev and lvs with the same name as previously 81 malloc2_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 82 rpc_cmd bdev_lvol_create_lvstore "$malloc2_name" lvs_test && false 83 84 # clean up 85 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs1_uuid" 86 rpc_cmd bdev_lvol_get_lvstores -u "$lvs1_uuid" && false 87 rpc_cmd bdev_malloc_delete "$malloc1_name" 88 rpc_cmd bdev_malloc_delete "$malloc2_name" 89 check_leftover_devices 90} 91 92# call bdev_lvol_create_lvstore with cluster size equals to malloc bdev size + 1B 93# call bdev_lvol_create_lvstore with cluster size smaller than minimal value of 8192 94function test_construct_lvs_different_cluster_size() { 95 # create the first lvs 96 malloc1_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 97 lvs1_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc1_name" lvs_test) 98 99 # make sure we've got 1 lvs 100 lvol_stores=$(rpc_cmd bdev_lvol_get_lvstores) 101 [ "$(jq length <<< "$lvol_stores")" == "1" ] 102 103 # use the second malloc for some more lvs creation negative tests 104 malloc2_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 105 # capacity bigger than malloc's 106 rpc_cmd bdev_lvol_create_lvstore "$malloc2_name" lvs2_test -c $((MALLOC_SIZE + 1)) && false 107 # capacity equal to malloc's (no space left for metadata) 108 rpc_cmd bdev_lvol_create_lvstore "$malloc2_name" lvs2_test -c $MALLOC_SIZE && false 109 # capacity smaller than malloc's, but still no space left for metadata 110 rpc_cmd bdev_lvol_create_lvstore "$malloc2_name" lvs2_test -c $((MALLOC_SIZE - 1)) && false 111 # cluster size smaller than the minimum (8192) 112 rpc_cmd bdev_lvol_create_lvstore "$malloc2_name" lvs2_test -c 8191 && false 113 114 # no additional lvol stores should have been created 115 lvol_stores=$(rpc_cmd bdev_lvol_get_lvstores) 116 [ "$(jq length <<< "$lvol_stores")" == "1" ] 117 118 # this one should be fine 119 lvs2_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc2_name" lvs2_test -c 8192) 120 # we should have one more lvs 121 lvol_stores=$(rpc_cmd bdev_lvol_get_lvstores) 122 [ "$(jq length <<< "$lvol_stores")" == "2" ] 123 124 # clean up 125 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs1_uuid" 126 rpc_cmd bdev_lvol_get_lvstores -u "$lvs1_uuid" && false 127 128 # delete the second lvs (using its name only) 129 rpc_cmd bdev_lvol_delete_lvstore -l lvs2_test 130 rpc_cmd bdev_lvol_get_lvstores -l lvs2_test && false 131 rpc_cmd bdev_lvol_get_lvstores -u "$lvs2_uuid" && false 132 133 rpc_cmd bdev_malloc_delete "$malloc1_name" 134 rpc_cmd bdev_malloc_delete "$malloc2_name" 135 check_leftover_devices 136} 137 138# test different methods of clearing the disk on lvolstore creation 139function test_construct_lvs_clear_methods() { 140 malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 141 142 # first try to provide invalid clear method 143 rpc_cmd bdev_lvol_create_lvstore "$malloc2_name" lvs2_test --clear-method invalid123 && false 144 145 # no lvs should be created 146 lvol_stores=$(rpc_cmd bdev_lvol_get_lvstores) 147 [ "$(jq length <<< "$lvol_stores")" == "0" ] 148 149 methods="none unmap write_zeroes" 150 for clear_method in $methods; do 151 lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test --clear-method $clear_method) 152 153 # create an lvol on top 154 lvol_uuid=$(rpc_cmd bdev_lvol_create -u "$lvs_uuid" lvol_test "$LVS_DEFAULT_CAPACITY_MB") 155 lvol=$(rpc_cmd bdev_get_bdevs -b "$lvol_uuid") 156 [ "$(jq -r '.[0].name' <<< "$lvol")" = "$lvol_uuid" ] 157 [ "$(jq -r '.[0].uuid' <<< "$lvol")" = "$lvol_uuid" ] 158 [ "$(jq -r '.[0].aliases[0]' <<< "$lvol")" = "lvs_test/lvol_test" ] 159 [ "$(jq -r '.[0].block_size' <<< "$lvol")" = "$MALLOC_BS" ] 160 [ "$(jq -r '.[0].num_blocks' <<< "$lvol")" = "$((LVS_DEFAULT_CAPACITY / MALLOC_BS))" ] 161 162 # clean up 163 rpc_cmd bdev_lvol_delete "$lvol_uuid" 164 rpc_cmd bdev_get_bdevs -b "$lvol_uuid" && false 165 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" 166 rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" && false 167 done 168 rpc_cmd bdev_malloc_delete "$malloc_name" 169 check_leftover_devices 170} 171 172# Test for clear_method equals to none 173function test_construct_lvol_fio_clear_method_none() { 174 local nbd_name=/dev/nbd0 175 local clear_method=none 176 177 local lvstore_name=lvs_test lvstore_uuid 178 local lvol_name=lvol_test lvol_uuid 179 local malloc_dev 180 181 malloc_dev=$(rpc_cmd bdev_malloc_create 256 "$MALLOC_BS") 182 lvstore_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_dev" "$lvstore_name") 183 184 get_lvs_jq bdev_lvol_get_lvstores -u "$lvstore_uuid" 185 186 lvol_uuid=$(rpc_cmd bdev_lvol_create \ 187 -c "$clear_method" \ 188 -u "$lvstore_uuid" \ 189 "$lvol_name" \ 190 $((jq_out["cluster_size"] / 1024 ** 2))) 191 192 nbd_start_disks "$DEFAULT_RPC_ADDR" "$lvol_uuid" "$nbd_name" 193 run_fio_test "$nbd_name" 0 "${jq_out["cluster_size"]}" write 0xdd 194 nbd_stop_disks "$DEFAULT_RPC_ADDR" "$nbd_name" 195 196 rpc_cmd bdev_lvol_delete "$lvol_uuid" 197 rpc_cmd bdev_lvol_delete_lvstore -u "$lvstore_uuid" 198 nbd_start_disks "$DEFAULT_RPC_ADDR" "$malloc_dev" "$nbd_name" 199 200 local metadata_pages 201 local last_metadata_lba 202 local offset_metadata_end 203 local last_cluster_of_metadata 204 local offset 205 local size_metadata_end 206 207 metadata_pages=$(calc "1 + ${jq_out["total_data_clusters"]} + ceil(5 + ceil(${jq_out["total_data_clusters"]} / 8) / 4096) * 3") 208 209 last_metadata_lba=$((metadata_pages * 4096 / MALLOC_BS)) 210 offset_metadata_end=$((last_metadata_lba * MALLOC_BS)) 211 last_cluster_of_metadata=$(calc "ceil($metadata_pages / ${jq_out["cluster_size"]} / 4096)") 212 last_cluster_of_metadata=$((last_cluster_of_metadata == 0 ? 1 : last_cluster_of_metadata)) 213 offset=$((last_cluster_of_metadata * jq_out["cluster_size"])) 214 size_metadata_end=$((offset - offset_metadata_end)) 215 216 # Check if data on area between end of metadata and first cluster of lvol bdev remained unchanged. 217 run_fio_test "$nbd_name" "$offset_metadata_end" "$size_metadata_end" "read" 0x00 218 # Check if data on first lvol bdevs remains unchanged. 219 run_fio_test "$nbd_name" "$offset" "${jq_out["cluster_size"]}" "read" 0xdd 220 221 nbd_stop_disks "$DEFAULT_RPC_ADDR" "$nbd_name" 222 rpc_cmd bdev_malloc_delete "$malloc_dev" 223 224 check_leftover_devices 225} 226 227# Test for clear_method equals to unmap 228function test_construct_lvol_fio_clear_method_unmap() { 229 local nbd_name=/dev/nbd0 230 local clear_method=unmap 231 232 local lvstore_name=lvs_test lvstore_uuid 233 local lvol_name=lvol_test lvol_uuid 234 local malloc_dev 235 236 malloc_dev=$(rpc_cmd bdev_malloc_create 256 "$MALLOC_BS") 237 238 nbd_start_disks "$DEFAULT_RPC_ADDR" "$malloc_dev" "$nbd_name" 239 run_fio_test "$nbd_name" 0 $((256 * 1024 ** 2)) write 0xdd 240 nbd_stop_disks "$DEFAULT_RPC_ADDR" "$nbd_name" 241 242 lvstore_uuid=$(rpc_cmd bdev_lvol_create_lvstore --clear-method none "$malloc_dev" "$lvstore_name") 243 get_lvs_jq bdev_lvol_get_lvstores -u "$lvstore_uuid" 244 245 lvol_uuid=$(rpc_cmd bdev_lvol_create \ 246 -c "$clear_method" \ 247 -u "$lvstore_uuid" \ 248 "$lvol_name" \ 249 $((jq_out["cluster_size"] / 1024 ** 2))) 250 251 nbd_start_disks "$DEFAULT_RPC_ADDR" "$lvol_uuid" "$nbd_name" 252 run_fio_test "$nbd_name" 0 "${jq_out["cluster_size"]}" read 0xdd 253 nbd_stop_disks "$DEFAULT_RPC_ADDR" "$nbd_name" 254 255 rpc_cmd bdev_lvol_delete "$lvol_uuid" 256 rpc_cmd bdev_lvol_delete_lvstore -u "$lvstore_uuid" 257 nbd_start_disks "$DEFAULT_RPC_ADDR" "$malloc_dev" "$nbd_name" 258 259 local metadata_pages 260 local last_metadata_lba 261 local offset_metadata_end 262 local last_cluster_of_metadata 263 local offset 264 local size_metadata_end 265 266 metadata_pages=$(calc "1 + ${jq_out["total_data_clusters"]} + ceil(5 + ceil(${jq_out["total_data_clusters"]} / 8) / 4096) * 3") 267 268 last_metadata_lba=$((metadata_pages * 4096 / MALLOC_BS)) 269 offset_metadata_end=$((last_metadata_lba * MALLOC_BS)) 270 last_cluster_of_metadata=$(calc "ceil($metadata_pages / ${jq_out["cluster_size"]} / 4096)") 271 last_cluster_of_metadata=$((last_cluster_of_metadata == 0 ? 1 : last_cluster_of_metadata)) 272 offset=$((last_cluster_of_metadata * jq_out["cluster_size"])) 273 size_metadata_end=$((offset - offset_metadata_end)) 274 275 # Check if data on area between end of metadata and first cluster of lvol bdev remained unchanged. 276 run_fio_test "$nbd_name" "$offset_metadata_end" "$size_metadata_end" "read" 0xdd 277 # Check if data on lvol bdev was zeroed. Malloc bdev should zero any data that is unmapped. 278 run_fio_test "$nbd_name" "$offset" "${jq_out["cluster_size"]}" "read" 0x00 279 280 nbd_stop_disks "$DEFAULT_RPC_ADDR" "$nbd_name" 281 rpc_cmd bdev_malloc_delete "$malloc_dev" 282 283 check_leftover_devices 284} 285 286# create lvs + lvol on top, verify lvol's parameters 287function test_construct_lvol() { 288 # create an lvol store 289 malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 290 lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test) 291 292 # create an lvol on top 293 lvol_uuid=$(rpc_cmd bdev_lvol_create -u "$lvs_uuid" lvol_test "$LVS_DEFAULT_CAPACITY_MB") 294 lvol=$(rpc_cmd bdev_get_bdevs -b "$lvol_uuid") 295 296 [ "$(jq -r '.[0].name' <<< "$lvol")" = "$lvol_uuid" ] 297 [ "$(jq -r '.[0].uuid' <<< "$lvol")" = "$lvol_uuid" ] 298 [ "$(jq -r '.[0].aliases[0]' <<< "$lvol")" = "lvs_test/lvol_test" ] 299 [ "$(jq -r '.[0].block_size' <<< "$lvol")" = "$MALLOC_BS" ] 300 [ "$(jq -r '.[0].num_blocks' <<< "$lvol")" = "$((LVS_DEFAULT_CAPACITY / MALLOC_BS))" ] 301 [ "$(jq -r '.[0].driver_specific.lvol.lvol_store_uuid' <<< "$lvol")" = "$lvs_uuid" ] 302 303 # clean up and create another lvol, this time use lvs alias instead of uuid 304 rpc_cmd bdev_lvol_delete "$lvol_uuid" 305 rpc_cmd bdev_get_bdevs -b "$lvol_uuid" && false 306 lvol_uuid=$(rpc_cmd bdev_lvol_create -l lvs_test lvol_test "$LVS_DEFAULT_CAPACITY_MB") 307 lvol=$(rpc_cmd bdev_get_bdevs -b "$lvol_uuid") 308 309 [ "$(jq -r '.[0].name' <<< "$lvol")" = "$lvol_uuid" ] 310 [ "$(jq -r '.[0].uuid' <<< "$lvol")" = "$lvol_uuid" ] 311 [ "$(jq -r '.[0].aliases[0]' <<< "$lvol")" = "lvs_test/lvol_test" ] 312 [ "$(jq -r '.[0].block_size' <<< "$lvol")" = "$MALLOC_BS" ] 313 [ "$(jq -r '.[0].num_blocks' <<< "$lvol")" = "$((LVS_DEFAULT_CAPACITY / MALLOC_BS))" ] 314 [ "$(jq -r '.[0].driver_specific.lvol.lvol_store_uuid' <<< "$lvol")" = "$lvs_uuid" ] 315 316 # clean up 317 rpc_cmd bdev_lvol_delete "$lvol_uuid" 318 rpc_cmd bdev_get_bdevs -b "$lvol_uuid" && false 319 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" 320 rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" && false 321 rpc_cmd bdev_malloc_delete "$malloc_name" 322 check_leftover_devices 323} 324 325# create lvs + multiple lvols, verify their params 326function test_construct_multi_lvols() { 327 # create an lvol store 328 malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 329 lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test) 330 331 # create 4 lvols 332 lvol_size_mb=$((LVS_DEFAULT_CAPACITY_MB / 4)) 333 # round down lvol size to the nearest cluster size boundary 334 lvol_size_mb=$((lvol_size_mb / LVS_DEFAULT_CLUSTER_SIZE_MB * LVS_DEFAULT_CLUSTER_SIZE_MB)) 335 lvol_size=$((lvol_size_mb * 1024 * 1024)) 336 for i in $(seq 1 4); do 337 lvol_uuid=$(rpc_cmd bdev_lvol_create -u "$lvs_uuid" "lvol_test${i}" "$lvol_size_mb") 338 lvol=$(rpc_cmd bdev_get_bdevs -b "$lvol_uuid") 339 340 [ "$(jq -r '.[0].name' <<< "$lvol")" = "$lvol_uuid" ] 341 [ "$(jq -r '.[0].uuid' <<< "$lvol")" = "$lvol_uuid" ] 342 [ "$(jq -r '.[0].aliases[0]' <<< "$lvol")" = "lvs_test/lvol_test${i}" ] 343 [ "$(jq -r '.[0].block_size' <<< "$lvol")" = "$MALLOC_BS" ] 344 [ "$(jq -r '.[0].num_blocks' <<< "$lvol")" = "$((lvol_size / MALLOC_BS))" ] 345 done 346 347 lvols=$(rpc_cmd bdev_get_bdevs | jq -r '[ .[] | select(.product_name == "Logical Volume") ]') 348 [ "$(jq length <<< "$lvols")" == "4" ] 349 350 # remove all lvols 351 for i in $(seq 0 3); do 352 lvol_uuid=$(jq -r ".[$i].name" <<< "$lvols") 353 rpc_cmd bdev_lvol_delete "$lvol_uuid" 354 done 355 lvols=$(rpc_cmd bdev_get_bdevs | jq -r '[ .[] | select(.product_name == "Logical Volume") ]') 356 [ "$(jq length <<< "$lvols")" == "0" ] 357 358 # create the same 4 lvols again and perform the same checks 359 for i in $(seq 1 4); do 360 lvol_uuid=$(rpc_cmd bdev_lvol_create -u "$lvs_uuid" "lvol_test${i}" "$lvol_size_mb") 361 lvol=$(rpc_cmd bdev_get_bdevs -b "$lvol_uuid") 362 363 [ "$(jq -r '.[0].name' <<< "$lvol")" = "$lvol_uuid" ] 364 [ "$(jq -r '.[0].uuid' <<< "$lvol")" = "$lvol_uuid" ] 365 [ "$(jq -r '.[0].aliases[0]' <<< "$lvol")" = "lvs_test/lvol_test${i}" ] 366 [ "$(jq -r '.[0].block_size' <<< "$lvol")" = "$MALLOC_BS" ] 367 [ "$(jq -r '.[0].num_blocks' <<< "$lvol")" = "$((lvol_size / MALLOC_BS))" ] 368 done 369 370 lvols=$(rpc_cmd bdev_get_bdevs | jq -r '[ .[] | select(.product_name == "Logical Volume") ]') 371 [ "$(jq length <<< "$lvols")" == "4" ] 372 373 # clean up 374 for i in $(seq 0 3); do 375 lvol_uuid=$(jq -r ".[$i].name" <<< "$lvols") 376 rpc_cmd bdev_lvol_delete "$lvol_uuid" 377 done 378 lvols=$(rpc_cmd bdev_get_bdevs | jq -r '[ .[] | select(.product_name == "Logical Volume") ]') 379 [ "$(jq length <<< "$lvols")" == "0" ] 380 381 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" 382 rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" && false 383 rpc_cmd bdev_malloc_delete "$malloc_name" 384 check_leftover_devices 385} 386 387# create 2 lvolstores, each with a single lvol on top. 388# use a single alias for both lvols, there should be no conflict 389# since they're in different lvolstores 390function test_construct_lvols_conflict_alias() { 391 # create an lvol store 1 392 malloc1_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 393 lvs1_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc1_name" lvs_test1) 394 395 # create an lvol on lvs1 396 lvol1_uuid=$(rpc_cmd bdev_lvol_create -l lvs_test1 lvol_test "$LVS_DEFAULT_CAPACITY_MB") 397 lvol1=$(rpc_cmd bdev_get_bdevs -b "$lvol1_uuid") 398 399 # use a different size for second malloc to keep those differentiable 400 malloc2_size_mb=$((MALLOC_SIZE_MB / 2)) 401 402 # create an lvol store 2 403 malloc2_name=$(rpc_cmd bdev_malloc_create $malloc2_size_mb $MALLOC_BS) 404 lvs2_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc2_name" lvs_test2) 405 406 lvol2_size_mb=$(round_down $((LVS_DEFAULT_CAPACITY_MB / 2))) 407 408 # create an lvol on lvs2 409 lvol2_uuid=$(rpc_cmd bdev_lvol_create -l lvs_test2 lvol_test "$lvol2_size_mb") 410 lvol2=$(rpc_cmd bdev_get_bdevs -b "$lvol2_uuid") 411 412 [ "$(jq -r '.[0].name' <<< "$lvol1")" = "$lvol1_uuid" ] 413 [ "$(jq -r '.[0].uuid' <<< "$lvol1")" = "$lvol1_uuid" ] 414 [ "$(jq -r '.[0].aliases[0]' <<< "$lvol1")" = "lvs_test1/lvol_test" ] 415 [ "$(jq -r '.[0].driver_specific.lvol.lvol_store_uuid' <<< "$lvol1")" = "$lvs1_uuid" ] 416 417 [ "$(jq -r '.[0].name' <<< "$lvol2")" = "$lvol2_uuid" ] 418 [ "$(jq -r '.[0].uuid' <<< "$lvol2")" = "$lvol2_uuid" ] 419 [ "$(jq -r '.[0].aliases[0]' <<< "$lvol2")" = "lvs_test2/lvol_test" ] 420 [ "$(jq -r '.[0].driver_specific.lvol.lvol_store_uuid' <<< "$lvol2")" = "$lvs2_uuid" ] 421 422 # clean up 423 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs1_uuid" 424 rpc_cmd bdev_lvol_get_lvstores -u "$lvs1_uuid" && false 425 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs2_uuid" 426 rpc_cmd bdev_lvol_get_lvstores -u "$lvs2_uuid" && false 427 rpc_cmd bdev_malloc_delete "$malloc1_name" 428 rpc_cmd bdev_get_bdevs -b "$malloc1_name" && false 429 rpc_cmd bdev_malloc_delete "$malloc2_name" 430 check_leftover_devices 431} 432 433# try to create an lvol on inexistent lvs uuid 434function test_construct_lvol_inexistent_lvs() { 435 # create an lvol store 436 malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 437 lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test) 438 439 # try to create an lvol on inexistent lvs 440 dummy_uuid="00000000-0000-0000-0000-000000000000" 441 rpc_cmd bdev_lvol_create -u "$dummy_uuid" lvol_test "$LVS_DEFAULT_CAPACITY_MB" && false 442 443 lvols=$(rpc_cmd bdev_get_bdevs | jq -r '[ .[] | select(.product_name == "Logical Volume") ]') 444 [ "$(jq length <<< "$lvols")" == "0" ] 445 446 # clean up 447 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" 448 rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" && false 449 rpc_cmd bdev_malloc_delete "$malloc_name" 450 check_leftover_devices 451} 452 453# try to create lvol on full lvs 454function test_construct_lvol_full_lvs() { 455 # create an lvol store 456 malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 457 lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test) 458 459 # create valid lvol 460 lvol1_uuid=$(rpc_cmd bdev_lvol_create -l lvs_test lvol_test1 "$LVS_DEFAULT_CAPACITY_MB") 461 lvol1=$(rpc_cmd bdev_get_bdevs -b "$lvol1_uuid") 462 463 # try to create an lvol on lvs without enough free clusters 464 rpc_cmd bdev_lvol_create -l lvs_test lvol_test2 1 && false 465 466 # clean up 467 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" 468 rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" && false 469 rpc_cmd bdev_malloc_delete "$malloc_name" 470 check_leftover_devices 471} 472 473# try to create two lvols with conflicting aliases 474function test_construct_lvol_alias_conflict() { 475 # create an lvol store 476 malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 477 lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test) 478 479 # create valid lvol 480 lvol_size_mb=$(round_down $((LVS_DEFAULT_CAPACITY_MB / 2))) 481 lvol1_uuid=$(rpc_cmd bdev_lvol_create -l lvs_test lvol_test "$lvol_size_mb") 482 lvol1=$(rpc_cmd bdev_get_bdevs -b "$lvol1_uuid") 483 484 # try to create another lvol with a name that's already taken 485 rpc_cmd bdev_lvol_create -l lvs_test lvol_test "$lvol_size_mb" && false 486 487 # clean up 488 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" 489 rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" && false 490 rpc_cmd bdev_malloc_delete "$malloc_name" 491 rpc_cmd bdev_get_bdevs -b "$malloc_name" && false 492 check_leftover_devices 493} 494 495# create an lvs+lvol, create another lvs on lvol and then a nested lvol 496function test_construct_nested_lvol() { 497 # create an lvol store 498 malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 499 lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test) 500 501 # create an lvol on top 502 lvol_uuid=$(rpc_cmd bdev_lvol_create -u "$lvs_uuid" lvol_test "$LVS_DEFAULT_CAPACITY_MB") 503 # create a nested lvs 504 nested_lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$lvol_uuid" nested_lvs) 505 506 nested_lvol_size_mb=$((LVS_DEFAULT_CAPACITY_MB - LVS_DEFAULT_CLUSTER_SIZE_MB)) 507 nested_lvol_size=$((nested_lvol_size_mb * 1024 * 1024)) 508 509 # create a nested lvol 510 nested_lvol1_uuid=$(rpc_cmd bdev_lvol_create -u "$nested_lvs_uuid" nested_lvol1 "$nested_lvol_size_mb") 511 nested_lvol1=$(rpc_cmd bdev_get_bdevs -b "$nested_lvol1_uuid") 512 513 [ "$(jq -r '.[0].name' <<< "$nested_lvol1")" = "$nested_lvol1_uuid" ] 514 [ "$(jq -r '.[0].uuid' <<< "$nested_lvol1")" = "$nested_lvol1_uuid" ] 515 [ "$(jq -r '.[0].aliases[0]' <<< "$nested_lvol1")" = "nested_lvs/nested_lvol1" ] 516 [ "$(jq -r '.[0].block_size' <<< "$nested_lvol1")" = "$MALLOC_BS" ] 517 [ "$(jq -r '.[0].num_blocks' <<< "$nested_lvol1")" = "$((nested_lvol_size / MALLOC_BS))" ] 518 [ "$(jq -r '.[0].driver_specific.lvol.lvol_store_uuid' <<< "$nested_lvol1")" = "$nested_lvs_uuid" ] 519 520 # try to create another nested lvol on a lvs that's already full 521 rpc_cmd bdev_lvol_create -u "$nested_lvs_uuid" nested_lvol2 "$nested_lvol_size_mb" && false 522 523 # clean up 524 rpc_cmd bdev_lvol_delete "$nested_lvol1_uuid" 525 rpc_cmd bdev_get_bdevs -b "$nested_lvol1_uuid" && false 526 rpc_cmd bdev_lvol_delete_lvstore -u "$nested_lvs_uuid" 527 rpc_cmd bdev_lvol_get_lvstores -u "$nested_lvs_uuid" && false 528 rpc_cmd bdev_lvol_delete "$lvol_uuid" 529 rpc_cmd bdev_get_bdevs -b "$lvol_uuid" && false 530 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" 531 rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" && false 532 rpc_cmd bdev_malloc_delete "$malloc_name" 533 check_leftover_devices 534} 535 536# List lvols without going through the bdev layer. 537function test_lvol_list() { 538 # create an lvol store 539 malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 540 lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test) 541 542 # An empty lvolstore is not listed by bdev_lvol_get_lvols 543 lvols=$(rpc_cmd bdev_lvol_get_lvols) 544 [ "$(jq -r '. | length' <<< "$lvols")" == "0" ] 545 546 # Create an lvol, it should appear in the list 547 lvol_uuid=$(rpc_cmd bdev_lvol_create -u "$lvs_uuid" lvol_test "$LVS_DEFAULT_CAPACITY_MB") 548 lvols=$(rpc_cmd bdev_lvol_get_lvols) 549 [ "$(jq -r '. | length' <<< "$lvols")" == "1" ] 550 [ "$(jq -r '.[0].uuid' <<< "$lvols")" == "$lvol_uuid" ] 551 [ "$(jq -r '.[0].name' <<< "$lvols")" == "lvol_test" ] 552 [ "$(jq -r '.[0].alias' <<< "$lvols")" == "lvs_test/lvol_test" ] 553 [ "$(jq -r '.[0].lvs.name' <<< "$lvols")" == "lvs_test" ] 554 [ "$(jq -r '.[0].lvs.uuid' <<< "$lvols")" == "$lvs_uuid" ] 555 556 rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" 557 rpc_cmd bdev_malloc_delete "$malloc_name" 558 check_leftover_devices 559} 560 561# Send SIGTERM after creating lvol store 562function test_sigterm() { 563 # create an lvol store 564 malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) 565 lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test) 566 567 # Send SIGTERM signal to the application 568 killprocess $spdk_pid 569} 570 571$SPDK_BIN_DIR/spdk_tgt & 572spdk_pid=$! 573trap 'killprocess "$spdk_pid"; exit 1' SIGINT SIGTERM EXIT 574waitforlisten $spdk_pid 575 576run_test "test_construct_lvs" test_construct_lvs 577run_test "test_construct_lvs_nonexistent_bdev" test_construct_lvs_nonexistent_bdev 578run_test "test_construct_two_lvs_on_the_same_bdev" test_construct_two_lvs_on_the_same_bdev 579run_test "test_construct_lvs_conflict_alias" test_construct_lvs_conflict_alias 580run_test "test_construct_lvs_different_cluster_size" test_construct_lvs_different_cluster_size 581run_test "test_construct_lvs_clear_methods" test_construct_lvs_clear_methods 582run_test "test_construct_lvol_fio_clear_method_none" test_construct_lvol_fio_clear_method_none 583run_test "test_construct_lvol_fio_clear_method_unmap" test_construct_lvol_fio_clear_method_unmap 584run_test "test_construct_lvol" test_construct_lvol 585run_test "test_construct_multi_lvols" test_construct_multi_lvols 586run_test "test_construct_lvols_conflict_alias" test_construct_lvols_conflict_alias 587run_test "test_construct_lvol_inexistent_lvs" test_construct_lvol_inexistent_lvs 588run_test "test_construct_lvol_full_lvs" test_construct_lvol_full_lvs 589run_test "test_construct_lvol_alias_conflict" test_construct_lvol_alias_conflict 590run_test "test_construct_nested_lvol" test_construct_nested_lvol 591run_test "test_lvol_list" test_lvol_list 592run_test "test_sigterm" test_sigterm 593 594trap - SIGINT SIGTERM EXIT 595if ps -p $spdk_pid; then 596 killprocess $spdk_pid 597fi 598