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