From c0db2b6d6a706891c0ce247beff55d272056d5fb Mon Sep 17 00:00:00 2001 From: Pawel Kaminski Date: Mon, 16 Dec 2019 07:52:15 -0500 Subject: [PATCH] test/lvol: rewrite thin_provisioning_check_space to bash Change-Id: I4a6fcad56c3e97995440262a3bdc0930408eaf68 Signed-off-by: Pawel Kaminski Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/703 Tested-by: SPDK CI Jenkins Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris --- test/lvol/lvol.sh | 1 - test/lvol/lvol2.sh | 1 + test/lvol/test_cases.py | 82 ---------------------------------- test/lvol/thin_provisioning.sh | 71 +++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 83 deletions(-) create mode 100755 test/lvol/thin_provisioning.sh diff --git a/test/lvol/lvol.sh b/test/lvol/lvol.sh index 7a42aec9b2..326db232e5 100755 --- a/test/lvol/lvol.sh +++ b/test/lvol/lvol.sh @@ -29,7 +29,6 @@ function usage() { 552: 'bdev_lvol_delete_lvstore_with_clones', 553: 'unregister_lvol_bdev', 602: 'bdev_lvol_create_lvstore_with_all_clear_methods', - 650: 'thin_provisioning_check_space', 651: 'thin_provisioning_read_empty_bdev', 652: 'thin_provisioning_data_integrity_test', 653: 'thin_provisioning_resize', diff --git a/test/lvol/lvol2.sh b/test/lvol/lvol2.sh index 439142c3b4..3c33ca64b3 100755 --- a/test/lvol/lvol2.sh +++ b/test/lvol/lvol2.sh @@ -13,6 +13,7 @@ run_test "lvol_hotremove" test/lvol/hotremove.sh run_test "lvol_tasting" test/lvol/tasting.sh run_test "lvol_snapshot_clone" test/lvol/snapshot_clone.sh run_test "lvol_rename" test/lvol/rename.sh +run_test "lvol_provisioning" test/lvol/thin_provisioning.sh timing_exit basic timing_exit lvol diff --git a/test/lvol/test_cases.py b/test/lvol/test_cases.py index ac580433d5..57f8c75de5 100644 --- a/test/lvol/test_cases.py +++ b/test/lvol/test_cases.py @@ -119,7 +119,6 @@ def case_message(func): 553: 'unregister_lvol_bdev', 602: 'bdev_lvol_create_lvstore_with_all_clear_methods', # Provisioning - 650: 'thin_provisioning_check_space', 651: 'thin_provisioning_read_empty_bdev', 652: 'thin_provisioning_data_integrity_test', 653: 'thin_provisioning_resize', @@ -583,87 +582,6 @@ class TestCases(object): # - Error code response printed to stdout return fail_count - @case_message - def test_case650(self): - """ - thin_provisioning_check_space - - Check if free clusters number on lvol store decreases - if we write to created thin provisioned lvol bdev - """ - # create malloc bdev - base_name = self.c.bdev_malloc_create(self.total_size, - self.block_size) - # create lvol store on mamloc bdev - uuid_store = self.c.bdev_lvol_create_lvstore(base_name, - self.lvs_name) - fail_count = self.c.check_bdev_lvol_get_lvstores(base_name, uuid_store, - self.cluster_size) - lvs = self.c.bdev_lvol_get_lvstores(self.lvs_name)[0] - free_clusters_start = int(lvs['free_clusters']) - bdev_size = self.get_lvs_size() - # create thin provisioned lvol bdev with size equals to lvol store free space - bdev_name = self.c.bdev_lvol_create(uuid_store, self.lbd_name, - bdev_size, thin=True) - lvs = self.c.bdev_lvol_get_lvstores(self.lvs_name)[0] - free_clusters_create_lvol = int(lvs['free_clusters']) - # check and save number of free clusters for lvol store - if free_clusters_start != free_clusters_create_lvol: - fail_count += 1 - lvol_bdev = self.c.get_lvol_bdev_with_name(bdev_name) - nbd_name = "/dev/nbd0" - fail_count += self.c.nbd_start_disk(bdev_name, nbd_name) - - size = int(lvs['cluster_size']) - # write data (lvs cluster size) to created lvol bdev starting from offset 0. - fail_count += self.run_fio_test("/dev/nbd0", 0, size, "write", "0xcc") - lvs = self.c.bdev_lvol_get_lvstores(self.lvs_name)[0] - free_clusters_first_fio = int(lvs['free_clusters']) - # check that free clusters on lvol store was decremented by 1 - if free_clusters_start != free_clusters_first_fio + 1: - fail_count += 1 - - size = int(lvs['cluster_size']) - # calculate size of one and half cluster - offset = int((int(lvol_bdev['num_blocks']) * int(lvol_bdev['block_size']) / - free_clusters_create_lvol) * 1.5) - # write data (lvs cluster size) to lvol bdev with offset set to one and half of cluster size - fail_count += self.run_fio_test(nbd_name, offset, size, "write", "0xcc") - lvs = self.c.bdev_lvol_get_lvstores(self.lvs_name)[0] - free_clusters_second_fio = int(lvs['free_clusters']) - # check that free clusters on lvol store was decremented by 2 - if free_clusters_start != free_clusters_second_fio + 3: - fail_count += 1 - - size = (free_clusters_create_lvol - 3) * int(lvs['cluster_size']) - offset = int(int(lvol_bdev['num_blocks']) * int(lvol_bdev['block_size']) / - free_clusters_create_lvol * 3) - # write data to lvol bdev to the end of its size - fail_count += self.run_fio_test(nbd_name, offset, size, "write", "0xcc") - lvs = self.c.bdev_lvol_get_lvstores(self.lvs_name)[0] - free_clusters_third_fio = int(lvs['free_clusters']) - # check that lvol store free clusters number equals to 0 - if free_clusters_third_fio != 0: - fail_count += 1 - - fail_count += self.c.nbd_stop_disk(nbd_name) - # destroy thin provisioned lvol bdev - fail_count += self.c.bdev_lvol_delete(lvol_bdev['name']) - lvs = self.c.bdev_lvol_get_lvstores(self.lvs_name)[0] - free_clusters_end = int(lvs['free_clusters']) - # check that saved number of free clusters equals to current free clusters - if free_clusters_start != free_clusters_end: - fail_count += 1 - # destroy lvol store - fail_count += self.c.bdev_lvol_delete_lvstore(uuid_store) - # destroy malloc bdev - fail_count += self.c.bdev_malloc_delete(base_name) - # Expected result: - # - calls successful, return code = 0 - # - no other operation fails - return fail_count - - @case_message def test_case651(self): """ thin_provisioning_read_empty_bdev diff --git a/test/lvol/thin_provisioning.sh b/test/lvol/thin_provisioning.sh new file mode 100755 index 0000000000..95fce655f6 --- /dev/null +++ b/test/lvol/thin_provisioning.sh @@ -0,0 +1,71 @@ +#!/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 +source $rootdir/test/bdev/nbd_common.sh + +# Check if number of free clusters on lvol store decreases +# if we write to created thin provisioned lvol bdev +function test_thin_lvol_check_space() { + malloc_name=$(rpc_cmd bdev_malloc_create $MALLOC_SIZE_MB $MALLOC_BS) + lvs_uuid=$(rpc_cmd bdev_lvol_create_lvstore "$malloc_name" lvs_test) + lvs=$(rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid") + free_clusters_start="$(jq -r '.[0].free_clusters' <<< "$lvs")" + + # Create thin provision lvol bdev with size equals to lvol store space + lvol_size_mb=$( round_down $(( LVS_DEFAULT_CAPACITY_MB )) ) + lvol_uuid=$(rpc_cmd bdev_lvol_create -u "$lvs_uuid" lvol_test "$lvol_size_mb" -t) + + lvs=$(rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid") + free_clusters_create_lvol="$(jq -r '.[0].free_clusters' <<< "$lvs")" + [ $free_clusters_start == $free_clusters_create_lvol ] + + # Write data (lvs cluster size) to created lvol bdev starting from offset 0. + size=$LVS_DEFAULT_CLUSTER_SIZE + nbd_start_disks "$DEFAULT_RPC_ADDR" "$lvol_uuid" /dev/nbd0 + run_fio_test /dev/nbd0 0 $size "write" "0xcc" + lvs=$(rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid") + free_clusters_first_fio="$(jq -r '.[0].free_clusters' <<< "$lvs")" + [ $(( free_clusters_first_fio + 1 )) == $free_clusters_start ] + + # Write data (lvs cluster size) to lvol bdev with offset set to one and half of cluster size + offset=$(( LVS_DEFAULT_CLUSTER_SIZE * 3 / 2 )) + size=$LVS_DEFAULT_CLUSTER_SIZE + run_fio_test /dev/nbd0 $offset $size "write" "0xcc" + lvs=$(rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid") + free_clusters_second_fio="$(jq -r '.[0].free_clusters' <<< "$lvs")" + [ $(( free_clusters_second_fio + 3 )) == $free_clusters_start ] + + # write data to lvol bdev to the end of its size + size=$(( LVS_DEFAULT_CLUSTER_SIZE * free_clusters_first_fio )) + offset=$(( 3 * LVS_DEFAULT_CLUSTER_SIZE )) + run_fio_test /dev/nbd0 $offset $size "write" "0xcc" + lvs=$(rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid") + # Check that lvol store free clusters number equals to 0 + free_clusters_third_fio="$(jq -r '.[0].free_clusters' <<< "$lvs")" + [ $(( free_clusters_third_fio )) == 0 ] + + nbd_stop_disks "$DEFAULT_RPC_ADDR" /dev/nbd0 + rpc_cmd bdev_lvol_delete "$lvol_uuid" + rpc_cmd bdev_get_bdevs -b "$lvol_uuid" && false + lvs=$(rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid") + free_clusters_end="$(jq -r '.[0].free_clusters' <<< "$lvs")" + [ $(( free_clusters_end )) == $free_clusters_start ] + + # Clean up + rpc_cmd bdev_lvol_delete_lvstore -u "$lvs_uuid" + rpc_cmd bdev_lvol_get_lvstores -u "$lvs_uuid" && false + rpc_cmd bdev_malloc_delete "$malloc_name" +} + +$rootdir/app/spdk_tgt/spdk_tgt & +spdk_pid=$! +trap 'killprocess "$spdk_pid"; exit 1' SIGINT SIGTERM EXIT +waitforlisten $spdk_pid + +run_test "test_thin_lvol_check_space" test_thin_lvol_check_space + +trap - SIGINT SIGTERM EXIT +killprocess $spdk_pid