Commit 233c5189 authored by Karol Latecki's avatar Karol Latecki Committed by Jim Harris
Browse files

test/vhost: refactor lvol test



- Removing hardcoded lvol bdevs and blk controller sizes
Lvol bdevs will now be created with roughly equal size based on
size of used NVMe backend
- Create lvol structures and VMs setup independently

Change-Id: Ib1cfe1b60033200a9896fa0c8d1b17af41ea0eb1
Signed-off-by: default avatarKarol Latecki <karol.latecki@intel.com>
Reviewed-on: https://review.gerrithub.io/390983


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 8fd2882f
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -497,5 +497,29 @@ function fio_config_add_job()
	echo "filename=$filename" >> $config_file
}

function get_lvs_free_mb()
{
	local lvs_uuid=$1
	local lvs_info=$($rpc_py get_lvol_stores)
	local fc=$(jq ".[] | select(.uuid==\"$lvs_uuid\") .free_clusters" <<< "$lvs_info")
	local cs=$(jq ".[] | select(.uuid==\"$lvs_uuid\") .cluster_size" <<< "$lvs_info")

	# Change to MB's
	free_mb=$((fc*cs/1024/1024))
	echo "$free_mb"
}

function get_bdev_size()
{
	local bdev_name=$1
	local bdev_info=$($rpc_py get_bdevs -b $bdev_name)
	local bs=$(jq ".[] .block_size" <<< "$bdev_info")
	local nb=$(jq ".[] .num_blocks" <<< "$bdev_info")

	# Change to MB's
	bdev_size=$((bs*nb/1024/1024))
	echo "$bdev_size"
}

set -o errtrace
trap "trap - ERR; print_backtrace >&2" ERR
+42 −33
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ BASE_DIR=$(readlink -f $(dirname $0))
[[ -z "$COMMON_DIR" ]] && COMMON_DIR="$(cd $BASE_DIR/../common && pwd)"

. $COMMON_DIR/common.sh

rpc_py="python $SPDK_BUILD_DIR/scripts/rpc.py "

vm_count=1
@@ -14,8 +13,6 @@ ctrl_type="vhost_scsi"
use_fs=false
nested_lvol=false
distribute_cores=false
base_bdev_size=10000
nest_bdev_size=""

function usage()
{
@@ -110,43 +107,55 @@ used_vms=""

# On each NVMe create one lvol store
for (( i=0; i<$max_disks; i++ ));do

    # Create base lvol store on NVMe
    echo "INFO: Creating lvol store on device Nvme${i}n1"
    ls_guid=$($rpc_py construct_lvol_store Nvme${i}n1 lvs_$i)
    lvol_stores+=("$ls_guid")
done

# Create lvol bdev for nested lvol stores if needed
    if $nested_lvol; then
    for lvol_store in "${lvol_stores[@]}"; do
        free_mb=$(get_lvs_free_mb "$ls_guid")
        size=$((free_mb / (vm_count+1) ))

        echo "INFO: Creating lvol bdev on lvol store $lvol_store"
        lb_name=$($rpc_py construct_lvol_bdev -u $lvol_store lbd_nest 16000)
        lvol_bdevs+=("$lb_name")
        echo "INFO: Creating lvol bdev on lvol store: $ls_guid"
        lb_name=$($rpc_py construct_lvol_bdev -u $ls_guid lbd_nest $size)

        echo "INFO: Creating nested lvol store on lvol bdev: $lb_name"
        ls_guid=$($rpc_py construct_lvol_store $lb_name lvs_n_$i)
        nest_lvol_stores+=("$ls_guid")
        nest_ls_guid=$($rpc_py construct_lvol_store $lb_name lvs_n_$i)
        nest_lvol_stores+=("$nest_ls_guid")

        for (( j=0; j<$vm_count; j++)); do
            echo "INFO: Creating nested lvol bdev for VM $i on lvol store $nest_ls_guid"
            free_mb=$(get_lvs_free_mb "$nest_ls_guid")
            nest_size=$((free_mb / (vm_count-j) ))
            lb_name=$($rpc_py construct_lvol_bdev -u $nest_ls_guid lbd_vm_$j $nest_size)
            nest_lvol_bdevs+=("$lb_name")
        done
    fi

# For each VM create one lvol bdev on each 'normal' and nested lvol store
for (( i=0; i<$vm_count; i++)); do
    bdevs=()
    echo "INFO: Creating lvol bdevs for VM $i"
    for lvol_store in "${lvol_stores[@]}"; do
        lb_name=$($rpc_py construct_lvol_bdev -u $lvol_store lbd_$i 10000)
    # Create base lvol bdevs
    for (( j=0; j<$vm_count; j++)); do
        echo "INFO: Creating lvol bdev for VM $i on lvol store $ls_guid"
        free_mb=$(get_lvs_free_mb "$ls_guid")
        size=$((free_mb / (vm_count-j) ))
        lb_name=$($rpc_py construct_lvol_bdev -u $ls_guid lbd_vm_$j $size)
        lvol_bdevs+=("$lb_name")
        bdevs+=("$lb_name")
    done

    if $nested_lvol; then
        echo "INFO: Creating nested lvol bdevs for VM $i"
        for lvol_store in "${nest_lvol_stores[@]}"; do
            lb_guid=$($rpc_py construct_lvol_bdev -u $lvol_store lbd_nest_$i 2000)
            nest_lvol_bdevs+=("$lb_guid")
            bdevs+=("$lb_guid")
done
    fi

bdev_info=$($rpc_py get_bdevs)
echo "INFO: Configuration after initial set-up:"
$rpc_py get_lvol_stores
echo "$bdev_info"

# Set up VMs
for (( i=0; i<$vm_count; i++)); do
    vm="vm_$i"

    # Get all lvol bdevs associated with this VM number
    bdevs=$(jq -r "map(select(.product_name==\"Logical Volume\") |
        select(.name | contains(\"$vm\")) | .name) | join(\" \")" <<< "$bdev_info")
    bdevs=($bdevs)

    setup_cmd="$COMMON_DIR/vm_setup.sh $x --work-dir=$TEST_DIR"
    if [[ "$ctrl_type" == "vhost_scsi" ]]; then
@@ -172,8 +181,10 @@ for (( i=0; i<$vm_count; i++)); do
    elif [[ "$ctrl_type" == "vhost_blk" ]]; then
        disk=""
        for (( j=0; j<${#bdevs[@]}; j++)); do
            blk_dev_size=$(get_bdev_size "${bdevs[$j]}")

            $rpc_py construct_vhost_blk_controller naa.$j.$i ${bdevs[$j]} $mask_arg
            disk+="${j}_size_1500M:"
            disk+="${j}_size_${blk_dev_size}M:"
        done
        disk="${disk::-1}"
        setup_cmd+=" --disk=$disk"
@@ -183,8 +194,6 @@ for (( i=0; i<$vm_count; i++)); do
    used_vms+=" $i"
done

$rpc_py get_lvol_stores
$rpc_py get_bdevs
$rpc_py get_vhost_controllers
$rpc_py get_luns