1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2016 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/vhost/common.sh 10 11ctrl_type="spdk_vhost_scsi" 12vm_fs="ext4" 13 14function usage() { 15 [[ -n $2 ]] && ( 16 echo "$2" 17 echo "" 18 ) 19 echo "Shortcut script for doing automated test" 20 echo "Usage: $(basename $1) [OPTIONS]" 21 echo 22 echo "-h, --help Print help and exit" 23 echo " --ctrl-type=TYPE Controller type to use for test:" 24 echo " spdk_vhost_scsi - use spdk vhost scsi" 25 echo " --fs=FS_LIST Filesystems to use for test in VM:" 26 echo " Example: --fs=\"ext4 ntfs ext2\"" 27 echo " Default: ext4" 28 echo " spdk_vhost_blk - use spdk vhost block" 29 echo "-x set -x for script debug" 30 exit 0 31} 32 33function clean_lvol_cfg() { 34 notice "Removing lvol bdev and lvol store" 35 $rpc_py bdev_lvol_delete lvol_store/lvol_bdev 36 $rpc_py bdev_lvol_delete_lvstore -l lvol_store 37} 38 39while getopts 'xh-:' optchar; do 40 case "$optchar" in 41 -) 42 case "$OPTARG" in 43 help) usage $0 ;; 44 ctrl-type=*) ctrl_type="${OPTARG#*=}" ;; 45 fs=*) vm_fs="${OPTARG#*=}" ;; 46 *) usage $0 "Invalid argument '$OPTARG'" ;; 47 esac 48 ;; 49 h) usage $0 ;; 50 x) 51 set -x 52 x="-x" 53 ;; 54 *) usage $0 "Invalid argument '$OPTARG'" ;; 55 esac 56done 57 58vhosttestinit 59 60. $(readlink -e "$(dirname $0)/../common.sh") || exit 1 61rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" 62 63trap 'error_exit "${FUNCNAME}" "${LINENO}"' SIGTERM SIGABRT ERR 64 65# Try to kill if any VM remains from previous runs 66vm_kill_all 67 68notice "Starting SPDK vhost" 69vhost_run -n 0 70notice "..." 71 72# Set up lvols and vhost controllers 73trap 'clean_lvol_cfg; error_exit "${FUNCNAME}" "${LINENO}"' SIGTERM SIGABRT ERR 74notice "Creating lvol store and lvol bdev on top of Nvme0n1" 75lvs_uuid=$($rpc_py bdev_lvol_create_lvstore Nvme0n1 lvol_store) 76$rpc_py bdev_lvol_create lvol_bdev 10000 -l lvol_store 77 78if [[ "$ctrl_type" == "spdk_vhost_scsi" ]]; then 79 $rpc_py vhost_create_scsi_controller naa.Nvme0n1.0 80 $rpc_py vhost_scsi_controller_add_target naa.Nvme0n1.0 0 lvol_store/lvol_bdev 81elif [[ "$ctrl_type" == "spdk_vhost_blk" ]]; then 82 $rpc_py vhost_create_blk_controller naa.Nvme0n1.0 lvol_store/lvol_bdev 83fi 84 85# Set up and run VM 86setup_cmd="vm_setup --disk-type=$ctrl_type --force=0" 87setup_cmd+=" --os=$VM_IMAGE" 88setup_cmd+=" --disks=Nvme0n1" 89$setup_cmd 90 91# Run VM 92vm_run 0 93vm_wait_for_boot 300 0 94 95# Run tests on VM 96vm_scp 0 $testdir/integrity_vm.sh root@127.0.0.1:/root/integrity_vm.sh 97vm_exec 0 "/root/integrity_vm.sh $ctrl_type \"$vm_fs\"" 98 99notice "Shutting down virtual machine..." 100vm_shutdown_all 101 102clean_lvol_cfg 103 104$rpc_py bdev_nvme_detach_controller Nvme0 105 106notice "Shutting down SPDK vhost app..." 107vhost_kill 0 108 109vhosttestfini 110