2017-12-18 19:45:33 +00:00
|
|
|
: ${SPDK_VHOST_VERBOSE=false}
|
2019-06-04 20:29:27 +00:00
|
|
|
: ${VHOST_DIR="$HOME/vhost_test"}
|
2019-12-12 10:36:39 +00:00
|
|
|
: ${QEMU_BIN="qemu-system-x86_64"}
|
|
|
|
: ${QEMU_IMG_BIN="qemu-img"}
|
2017-12-18 19:45:33 +00:00
|
|
|
|
2019-05-10 18:57:39 +00:00
|
|
|
TEST_DIR=$(readlink -f $rootdir/..)
|
2019-06-04 20:29:27 +00:00
|
|
|
VM_DIR=$VHOST_DIR/vms
|
|
|
|
TARGET_DIR=$VHOST_DIR/vhost
|
2019-08-26 15:37:41 +00:00
|
|
|
VM_PASSWORD="root"
|
2019-06-04 20:29:27 +00:00
|
|
|
|
2020-10-07 14:16:34 +00:00
|
|
|
VM_IMAGE=$HOME/spdk_test_image.qcow2
|
2019-05-17 18:20:35 +00:00
|
|
|
|
2019-12-12 10:36:39 +00:00
|
|
|
if ! hash $QEMU_IMG_BIN $QEMU_BIN; then
|
2019-06-04 19:15:46 +00:00
|
|
|
error 'QEMU is not installed on this system. Unable to run vhost tests.'
|
2019-06-06 14:25:52 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-06-04 20:29:27 +00:00
|
|
|
mkdir -p $VHOST_DIR
|
|
|
|
mkdir -p $VM_DIR
|
|
|
|
mkdir -p $TARGET_DIR
|
2019-05-10 18:10:28 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Source config describing QEMU and VHOST cores and NUMA
|
|
|
|
#
|
2019-05-10 18:23:54 +00:00
|
|
|
source $rootdir/test/vhost/common/autotest.config
|
2019-05-10 18:10:28 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vhosttestinit() {
|
2019-05-01 22:18:05 +00:00
|
|
|
if [ "$TEST_MODE" == "iso" ]; then
|
|
|
|
$rootdir/scripts/setup.sh
|
2019-06-03 22:24:27 +00:00
|
|
|
|
|
|
|
# Look for the VM image
|
|
|
|
if [[ ! -f $VM_IMAGE ]]; then
|
|
|
|
echo "VM image not found at $VM_IMAGE"
|
|
|
|
echo "Download to $HOME? [yn]"
|
2019-10-21 10:14:41 +00:00
|
|
|
read -r download
|
2019-06-03 22:24:27 +00:00
|
|
|
if [ "$download" = "y" ]; then
|
2020-01-28 20:11:38 +00:00
|
|
|
curl https://ci.spdk.io/download/test_resources/vhost_vm_image.tar.gz | tar xz -C $HOME
|
2019-06-03 22:24:27 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Look for the VM image
|
2020-10-14 12:55:16 +00:00
|
|
|
if [[ "$1" != "--no_vm" ]] && [[ ! -f $VM_IMAGE ]]; then
|
2019-06-03 22:24:27 +00:00
|
|
|
error "VM image not found at $VM_IMAGE"
|
|
|
|
exit 1
|
2019-05-01 22:18:05 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vhosttestfini() {
|
2019-05-01 22:18:05 +00:00
|
|
|
if [ "$TEST_MODE" == "iso" ]; then
|
|
|
|
$rootdir/scripts/setup.sh reset
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function message() {
|
2019-10-24 13:58:04 +00:00
|
|
|
local verbose_out
|
2017-12-18 19:45:33 +00:00
|
|
|
if ! $SPDK_VHOST_VERBOSE; then
|
2019-10-24 13:58:04 +00:00
|
|
|
verbose_out=""
|
2017-12-18 19:45:33 +00:00
|
|
|
elif [[ ${FUNCNAME[2]} == "source" ]]; then
|
2019-10-24 13:58:04 +00:00
|
|
|
verbose_out=" (file $(basename ${BASH_SOURCE[1]}):${BASH_LINENO[1]})"
|
2017-12-18 19:45:33 +00:00
|
|
|
else
|
2019-10-24 13:58:04 +00:00
|
|
|
verbose_out=" (function ${FUNCNAME[2]}:${BASH_LINENO[1]})"
|
2017-12-18 19:45:33 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
local msg_type="$1"
|
|
|
|
shift
|
2019-10-10 09:55:04 +00:00
|
|
|
echo -e "${msg_type}${verbose_out}: $*"
|
2017-12-18 19:45:33 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function fail() {
|
2017-12-18 19:45:33 +00:00
|
|
|
echo "===========" >&2
|
|
|
|
message "FAIL" "$@" >&2
|
|
|
|
echo "===========" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function error() {
|
2017-12-18 19:45:33 +00:00
|
|
|
echo "===========" >&2
|
|
|
|
message "ERROR" "$@" >&2
|
|
|
|
echo "===========" >&2
|
|
|
|
# Don't 'return 1' since the stack trace will be incomplete (why?) missing upper command.
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function warning() {
|
2017-12-18 19:45:33 +00:00
|
|
|
message "WARN" "$@" >&2
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function notice() {
|
2017-12-18 19:45:33 +00:00
|
|
|
message "INFO" "$@"
|
|
|
|
}
|
|
|
|
|
2020-06-01 11:05:32 +00:00
|
|
|
function check_qemu_packedring_support() {
|
|
|
|
qemu_version=$($QEMU_BIN -version | grep -Po "(?<=version )\d+.\d+.\d+")
|
|
|
|
if [[ "$qemu_version" < "4.2.0" ]]; then
|
|
|
|
error "This qemu binary does not support packed ring"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function get_vhost_dir() {
|
2019-06-04 20:55:21 +00:00
|
|
|
local vhost_name="$1"
|
2018-02-01 14:32:21 +00:00
|
|
|
|
2019-06-04 20:55:21 +00:00
|
|
|
if [[ -z "$vhost_name" ]]; then
|
|
|
|
error "vhost name must be provided to get_vhost_dir"
|
|
|
|
return 1
|
2018-02-01 14:32:21 +00:00
|
|
|
fi
|
2019-06-04 20:55:21 +00:00
|
|
|
|
|
|
|
echo "$TARGET_DIR/${vhost_name}"
|
2018-02-01 14:32:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vhost_run() {
|
2019-06-04 20:55:21 +00:00
|
|
|
local vhost_name="$1"
|
2019-08-08 15:21:44 +00:00
|
|
|
local run_gen_nvme=true
|
2018-02-01 14:32:21 +00:00
|
|
|
|
2019-06-04 20:55:21 +00:00
|
|
|
if [[ -z "$vhost_name" ]]; then
|
|
|
|
error "vhost name must be provided to vhost_run"
|
|
|
|
return 1
|
|
|
|
fi
|
2019-10-29 09:20:23 +00:00
|
|
|
shift
|
|
|
|
|
2019-08-08 15:21:44 +00:00
|
|
|
if [[ "$1" == "--no-gen-nvme" ]]; then
|
|
|
|
notice "Skipping gen_nvmf.sh NVMe bdev configuration"
|
|
|
|
run_gen_nvme=false
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2019-10-24 13:58:04 +00:00
|
|
|
local vhost_dir
|
|
|
|
vhost_dir="$(get_vhost_dir $vhost_name)"
|
2020-05-11 21:15:03 +00:00
|
|
|
local vhost_app="$SPDK_BIN_DIR/vhost"
|
2018-02-01 14:32:21 +00:00
|
|
|
local vhost_log_file="$vhost_dir/vhost.log"
|
|
|
|
local vhost_pid_file="$vhost_dir/vhost.pid"
|
|
|
|
local vhost_socket="$vhost_dir/usvhost"
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "starting vhost app in background"
|
2019-09-12 06:59:10 +00:00
|
|
|
[[ -r "$vhost_pid_file" ]] && vhost_kill $vhost_name
|
2018-02-01 14:32:21 +00:00
|
|
|
[[ -d $vhost_dir ]] && rm -f $vhost_dir/*
|
|
|
|
mkdir -p $vhost_dir
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2017-11-15 13:56:07 +00:00
|
|
|
if [[ ! -x $vhost_app ]]; then
|
|
|
|
error "application not found: $vhost_app"
|
2017-03-02 14:12:20 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-11-05 12:06:34 +00:00
|
|
|
local cmd="$vhost_app -r $vhost_dir/rpc.sock $*"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "Loging to: $vhost_log_file"
|
|
|
|
notice "Socket: $vhost_socket"
|
|
|
|
notice "Command: $cmd"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2018-02-01 21:14:58 +00:00
|
|
|
timing_enter vhost_start
|
2020-05-07 11:27:06 +00:00
|
|
|
cd $vhost_dir
|
|
|
|
$cmd &
|
2017-07-13 16:02:19 +00:00
|
|
|
vhost_pid=$!
|
|
|
|
echo $vhost_pid > $vhost_pid_file
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "waiting for app to run..."
|
2018-02-01 14:32:21 +00:00
|
|
|
waitforlisten "$vhost_pid" "$vhost_dir/rpc.sock"
|
2018-06-04 17:15:48 +00:00
|
|
|
#do not generate nvmes if pci access is disabled
|
2019-08-08 15:21:44 +00:00
|
|
|
if [[ "$cmd" != *"--no-pci"* ]] && [[ "$cmd" != *"-u"* ]] && $run_gen_nvme; then
|
2020-10-21 10:59:09 +00:00
|
|
|
$rootdir/scripts/gen_nvme.sh | $rootdir/scripts/rpc.py -s $vhost_dir/rpc.sock load_subsystem_config
|
2018-05-16 19:45:39 +00:00
|
|
|
fi
|
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "vhost started - pid=$vhost_pid"
|
2018-02-01 21:14:58 +00:00
|
|
|
timing_exit vhost_start
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vhost_kill() {
|
2018-02-01 21:14:58 +00:00
|
|
|
local rc=0
|
2019-06-04 20:55:21 +00:00
|
|
|
local vhost_name="$1"
|
|
|
|
|
|
|
|
if [[ -z "$vhost_name" ]]; then
|
|
|
|
error "Must provide vhost name to vhost_kill"
|
|
|
|
return 0
|
2018-02-01 14:32:21 +00:00
|
|
|
fi
|
|
|
|
|
2019-10-24 13:58:04 +00:00
|
|
|
local vhost_dir
|
|
|
|
vhost_dir="$(get_vhost_dir $vhost_name)"
|
2019-06-05 22:17:04 +00:00
|
|
|
local vhost_pid_file="$vhost_dir/vhost.pid"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
|
|
|
if [[ ! -r $vhost_pid_file ]]; then
|
2017-12-18 19:45:33 +00:00
|
|
|
warning "no vhost pid file found"
|
2017-03-02 14:12:20 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2018-02-01 21:14:58 +00:00
|
|
|
timing_enter vhost_kill
|
2019-10-24 13:58:04 +00:00
|
|
|
local vhost_pid
|
|
|
|
vhost_pid="$(cat $vhost_pid_file)"
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "killing vhost (PID $vhost_pid) app"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2019-06-05 22:17:04 +00:00
|
|
|
if kill -INT $vhost_pid > /dev/null; then
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "sent SIGINT to vhost app - waiting 60 seconds to exit"
|
2020-05-07 11:27:06 +00:00
|
|
|
for ((i = 0; i < 60; i++)); do
|
2019-06-05 22:17:04 +00:00
|
|
|
if kill -0 $vhost_pid; then
|
2017-05-10 18:25:46 +00:00
|
|
|
echo "."
|
|
|
|
sleep 1
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
2017-03-02 14:12:20 +00:00
|
|
|
done
|
2019-06-05 22:17:04 +00:00
|
|
|
if kill -0 $vhost_pid; then
|
2017-12-18 19:45:33 +00:00
|
|
|
error "ERROR: vhost was NOT killed - sending SIGABRT"
|
2019-06-05 22:17:04 +00:00
|
|
|
kill -ABRT $vhost_pid
|
2017-05-10 18:25:46 +00:00
|
|
|
rm $vhost_pid_file
|
2018-02-01 21:14:58 +00:00
|
|
|
rc=1
|
|
|
|
else
|
2018-02-21 14:09:16 +00:00
|
|
|
while kill -0 $vhost_pid; do
|
|
|
|
echo "."
|
|
|
|
done
|
2017-05-10 18:25:46 +00:00
|
|
|
fi
|
2019-06-05 22:17:04 +00:00
|
|
|
elif kill -0 $vhost_pid; then
|
2017-03-02 14:12:20 +00:00
|
|
|
error "vhost NOT killed - you need to kill it manually"
|
2018-02-01 21:14:58 +00:00
|
|
|
rc=1
|
2017-03-02 14:12:20 +00:00
|
|
|
else
|
2019-06-05 22:17:04 +00:00
|
|
|
notice "vhost was not running"
|
2017-03-02 14:12:20 +00:00
|
|
|
fi
|
|
|
|
|
2018-02-01 21:14:58 +00:00
|
|
|
timing_exit vhost_kill
|
|
|
|
if [[ $rc == 0 ]]; then
|
|
|
|
rm $vhost_pid_file
|
|
|
|
fi
|
|
|
|
|
2019-06-05 22:17:04 +00:00
|
|
|
rm -rf "$vhost_dir"
|
|
|
|
|
2018-02-01 21:14:58 +00:00
|
|
|
return $rc
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vhost_rpc() {
|
2019-06-04 20:55:21 +00:00
|
|
|
local vhost_name="$1"
|
|
|
|
|
|
|
|
if [[ -z "$vhost_name" ]]; then
|
|
|
|
error "vhost name must be provided to vhost_rpc"
|
|
|
|
return 1
|
2019-06-03 21:46:52 +00:00
|
|
|
fi
|
|
|
|
shift
|
|
|
|
|
2019-11-25 11:21:54 +00:00
|
|
|
$rootdir/scripts/rpc.py -s $(get_vhost_dir $vhost_name)/rpc.sock "$@"
|
2019-06-03 21:46:52 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 14:12:20 +00:00
|
|
|
###
|
|
|
|
# Mgmt functions
|
|
|
|
###
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function assert_number() {
|
2017-03-02 14:12:20 +00:00
|
|
|
[[ "$1" =~ [0-9]+ ]] && return 0
|
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
error "Invalid or missing paramter: need number but got '$1'"
|
2020-05-07 11:27:06 +00:00
|
|
|
return 1
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
|
2019-04-07 21:05:55 +00:00
|
|
|
# Run command on vm with given password
|
|
|
|
# First argument - vm number
|
|
|
|
# Second argument - ssh password for vm
|
|
|
|
#
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_sshpass() {
|
2019-04-07 21:05:55 +00:00
|
|
|
vm_num_is_valid $1 || return 1
|
|
|
|
|
2019-10-24 13:58:04 +00:00
|
|
|
local ssh_cmd
|
|
|
|
ssh_cmd="sshpass -p $2 ssh \
|
2019-04-07 21:05:55 +00:00
|
|
|
-o UserKnownHostsFile=/dev/null \
|
|
|
|
-o StrictHostKeyChecking=no \
|
|
|
|
-o User=root \
|
|
|
|
-p $(vm_ssh_socket $1) $VM_SSH_OPTIONS 127.0.0.1"
|
|
|
|
|
|
|
|
shift 2
|
|
|
|
$ssh_cmd "$@"
|
|
|
|
}
|
|
|
|
|
2017-03-02 14:12:20 +00:00
|
|
|
# Helper to validate VM number
|
|
|
|
# param $1 VM number
|
|
|
|
#
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_num_is_valid() {
|
2017-11-16 14:33:09 +00:00
|
|
|
[[ "$1" =~ ^[0-9]+$ ]] && return 0
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
error "Invalid or missing paramter: vm number '$1'"
|
2020-05-07 11:27:06 +00:00
|
|
|
return 1
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Print network socket for given VM number
|
|
|
|
# param $1 virtual machine number
|
|
|
|
#
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_ssh_socket() {
|
2017-03-02 14:12:20 +00:00
|
|
|
vm_num_is_valid $1 || return 1
|
2019-06-04 20:29:27 +00:00
|
|
|
local vm_dir="$VM_DIR/$1"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
|
|
|
cat $vm_dir/ssh_socket
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_fio_socket() {
|
2017-03-02 14:12:20 +00:00
|
|
|
vm_num_is_valid $1 || return 1
|
2019-06-04 20:29:27 +00:00
|
|
|
local vm_dir="$VM_DIR/$1"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
|
|
|
cat $vm_dir/fio_socket
|
|
|
|
}
|
|
|
|
|
2019-06-04 22:00:09 +00:00
|
|
|
# Execute command on given VM
|
2017-08-02 17:13:48 +00:00
|
|
|
# param $1 virtual machine number
|
|
|
|
#
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_exec() {
|
2017-08-02 17:13:48 +00:00
|
|
|
vm_num_is_valid $1 || return 1
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2019-06-04 22:00:09 +00:00
|
|
|
local vm_num="$1"
|
2017-03-02 14:12:20 +00:00
|
|
|
shift
|
2019-06-04 22:00:09 +00:00
|
|
|
|
2019-08-26 15:37:41 +00:00
|
|
|
sshpass -p "$VM_PASSWORD" ssh \
|
2019-06-04 22:00:09 +00:00
|
|
|
-o UserKnownHostsFile=/dev/null \
|
|
|
|
-o StrictHostKeyChecking=no \
|
|
|
|
-o User=root \
|
|
|
|
-p $(vm_ssh_socket $vm_num) $VM_SSH_OPTIONS 127.0.0.1 \
|
|
|
|
"$@"
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 17:13:48 +00:00
|
|
|
# Execute scp command on given VM
|
|
|
|
# param $1 virtual machine number
|
|
|
|
#
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_scp() {
|
2017-08-02 17:13:48 +00:00
|
|
|
vm_num_is_valid $1 || return 1
|
|
|
|
|
2019-06-04 22:00:09 +00:00
|
|
|
local vm_num="$1"
|
2017-08-02 17:13:48 +00:00
|
|
|
shift
|
2019-06-04 22:00:09 +00:00
|
|
|
|
2019-08-26 15:37:41 +00:00
|
|
|
sshpass -p "$VM_PASSWORD" scp \
|
2019-06-04 22:00:09 +00:00
|
|
|
-o UserKnownHostsFile=/dev/null \
|
|
|
|
-o StrictHostKeyChecking=no \
|
|
|
|
-o User=root \
|
|
|
|
-P $(vm_ssh_socket $vm_num) $VM_SSH_OPTIONS \
|
|
|
|
"$@"
|
2017-08-02 17:13:48 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 14:12:20 +00:00
|
|
|
# check if specified VM is running
|
|
|
|
# param $1 VM num
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_is_running() {
|
2017-03-02 14:12:20 +00:00
|
|
|
vm_num_is_valid $1 || return 1
|
2019-06-04 20:29:27 +00:00
|
|
|
local vm_dir="$VM_DIR/$1"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
|
|
|
if [[ ! -r $vm_dir/qemu.pid ]]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-10-24 13:58:04 +00:00
|
|
|
local vm_pid
|
|
|
|
vm_pid="$(cat $vm_dir/qemu.pid)"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
|
|
|
if /bin/kill -0 $vm_pid; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
2017-12-18 19:45:33 +00:00
|
|
|
warning "not root - assuming VM running since can't be checked"
|
2017-03-02 14:12:20 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# not running - remove pid file
|
|
|
|
rm $vm_dir/qemu.pid
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# check if specified VM is running
|
|
|
|
# param $1 VM num
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_os_booted() {
|
2017-03-02 14:12:20 +00:00
|
|
|
vm_num_is_valid $1 || return 1
|
2019-06-04 20:29:27 +00:00
|
|
|
local vm_dir="$VM_DIR/$1"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
|
|
|
if [[ ! -r $vm_dir/qemu.pid ]]; then
|
|
|
|
error "VM $1 is not running"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
if ! VM_SSH_OPTIONS="-o ControlMaster=no" vm_exec $1 "true" 2> /dev/null; then
|
2018-08-09 10:26:36 +00:00
|
|
|
# Shutdown existing master. Ignore errors as it might not exist.
|
2020-05-07 11:27:06 +00:00
|
|
|
VM_SSH_OPTIONS="-O exit" vm_exec $1 "true" 2> /dev/null
|
2017-03-02 14:12:20 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Shutdown given VM
|
|
|
|
# param $1 virtual machine number
|
|
|
|
# return non-zero in case of error.
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_shutdown() {
|
2017-03-02 14:12:20 +00:00
|
|
|
vm_num_is_valid $1 || return 1
|
2019-06-04 20:29:27 +00:00
|
|
|
local vm_dir="$VM_DIR/$1"
|
2017-03-02 14:12:20 +00:00
|
|
|
if [[ ! -d "$vm_dir" ]]; then
|
|
|
|
error "VM$1 ($vm_dir) not exist - setup it first"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! vm_is_running $1; then
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "VM$1 ($vm_dir) is not running"
|
2017-03-02 14:12:20 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2017-06-19 11:19:51 +00:00
|
|
|
# Temporarily disabling exit flag for next ssh command, since it will
|
|
|
|
# "fail" due to shutdown
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "Shutting down virtual machine $vm_dir"
|
2017-06-19 11:19:51 +00:00
|
|
|
set +e
|
2019-06-04 22:00:09 +00:00
|
|
|
vm_exec $1 "nohup sh -c 'shutdown -h -P now'" || true
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "VM$1 is shutting down - wait a while to complete"
|
2017-06-19 11:19:51 +00:00
|
|
|
set -e
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Kill given VM
|
|
|
|
# param $1 virtual machine number
|
|
|
|
#
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_kill() {
|
2017-03-02 14:12:20 +00:00
|
|
|
vm_num_is_valid $1 || return 1
|
2019-06-04 20:29:27 +00:00
|
|
|
local vm_dir="$VM_DIR/$1"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
|
|
|
if [[ ! -r $vm_dir/qemu.pid ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2019-10-24 13:58:04 +00:00
|
|
|
local vm_pid
|
|
|
|
vm_pid="$(cat $vm_dir/qemu.pid)"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "Killing virtual machine $vm_dir (pid=$vm_pid)"
|
2017-03-02 14:12:20 +00:00
|
|
|
# First kill should fail, second one must fail
|
|
|
|
if /bin/kill $vm_pid; then
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "process $vm_pid killed"
|
2017-03-02 14:12:20 +00:00
|
|
|
rm $vm_dir/qemu.pid
|
2019-05-17 18:20:35 +00:00
|
|
|
rm -rf $vm_dir
|
2017-03-02 14:12:20 +00:00
|
|
|
elif vm_is_running $1; then
|
2017-11-16 14:33:09 +00:00
|
|
|
error "Process $vm_pid NOT killed"
|
2017-03-02 14:12:20 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-06-04 20:29:27 +00:00
|
|
|
# List all VM numbers in VM_DIR
|
2018-01-30 14:18:17 +00:00
|
|
|
#
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_list_all() {
|
2019-10-24 13:58:04 +00:00
|
|
|
local vms
|
2020-05-07 11:27:06 +00:00
|
|
|
vms="$(
|
|
|
|
shopt -s nullglob
|
|
|
|
echo $VM_DIR/[0-9]*
|
|
|
|
)"
|
2019-07-25 13:01:09 +00:00
|
|
|
if [[ -n "$vms" ]]; then
|
2018-01-30 14:18:17 +00:00
|
|
|
basename --multiple $vms
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-06-04 20:29:27 +00:00
|
|
|
# Kills all VM in $VM_DIR
|
2017-03-02 14:12:20 +00:00
|
|
|
#
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_kill_all() {
|
2018-01-30 14:18:17 +00:00
|
|
|
local vm
|
|
|
|
for vm in $(vm_list_all); do
|
|
|
|
vm_kill $vm
|
2017-03-02 14:12:20 +00:00
|
|
|
done
|
2019-05-17 18:20:35 +00:00
|
|
|
|
2019-06-04 20:29:27 +00:00
|
|
|
rm -rf $VM_DIR
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 20:29:27 +00:00
|
|
|
# Shutdown all VM in $VM_DIR
|
2017-03-02 14:12:20 +00:00
|
|
|
#
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_shutdown_all() {
|
2019-12-13 16:20:12 +00:00
|
|
|
# XXX: temporarily disable to debug shutdown issue
|
|
|
|
# xtrace_disable
|
2018-01-05 18:55:37 +00:00
|
|
|
|
2019-10-24 13:58:04 +00:00
|
|
|
local vms
|
|
|
|
vms=$(vm_list_all)
|
2018-01-30 14:18:17 +00:00
|
|
|
local vm
|
|
|
|
|
|
|
|
for vm in $vms; do
|
2018-02-14 21:52:23 +00:00
|
|
|
vm_shutdown $vm
|
2017-03-02 14:12:20 +00:00
|
|
|
done
|
2017-06-19 11:19:51 +00:00
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "Waiting for VMs to shutdown..."
|
2018-03-30 14:55:46 +00:00
|
|
|
local timeo=30
|
2017-06-19 11:19:51 +00:00
|
|
|
while [[ $timeo -gt 0 ]]; do
|
2018-03-05 14:21:21 +00:00
|
|
|
local all_vms_down=1
|
2018-01-30 14:18:17 +00:00
|
|
|
for vm in $vms; do
|
2018-03-20 13:27:51 +00:00
|
|
|
if vm_is_running $vm; then
|
2017-06-19 11:19:51 +00:00
|
|
|
all_vms_down=0
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ $all_vms_down == 1 ]]; then
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "All VMs successfully shut down"
|
2019-12-13 16:20:12 +00:00
|
|
|
xtrace_restore
|
2017-06-19 11:19:51 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
((timeo -= 1))
|
2017-06-19 11:19:51 +00:00
|
|
|
sleep 1
|
|
|
|
done
|
2018-01-30 14:18:17 +00:00
|
|
|
|
2019-06-04 20:29:27 +00:00
|
|
|
rm -rf $VM_DIR
|
2019-05-17 18:20:35 +00:00
|
|
|
|
2019-12-13 16:20:12 +00:00
|
|
|
xtrace_restore
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_setup() {
|
2019-12-13 16:20:12 +00:00
|
|
|
xtrace_disable
|
2018-01-03 13:24:38 +00:00
|
|
|
local OPTIND optchar vm_num
|
2017-03-02 14:12:20 +00:00
|
|
|
|
|
|
|
local os=""
|
2018-01-03 13:24:38 +00:00
|
|
|
local os_mode=""
|
2020-04-23 08:56:36 +00:00
|
|
|
local qemu_args=()
|
2018-01-23 18:19:23 +00:00
|
|
|
local disk_type_g=NOT_DEFINED
|
2018-03-06 07:30:06 +00:00
|
|
|
local read_only="false"
|
2020-04-23 09:22:39 +00:00
|
|
|
# List created of a strings separated with a ":"
|
|
|
|
local disks=()
|
2017-03-02 14:12:20 +00:00
|
|
|
local raw_cache=""
|
2018-01-03 13:24:38 +00:00
|
|
|
local vm_incoming=""
|
|
|
|
local vm_migrate_to=""
|
2017-03-02 14:12:20 +00:00
|
|
|
local force_vm=""
|
2018-01-10 19:57:13 +00:00
|
|
|
local guest_memory=1024
|
|
|
|
local queue_number=""
|
2019-10-24 13:58:04 +00:00
|
|
|
local vhost_dir
|
2020-06-01 11:05:32 +00:00
|
|
|
local packed=false
|
2019-10-24 13:58:04 +00:00
|
|
|
vhost_dir="$(get_vhost_dir 0)"
|
2017-03-02 14:12:20 +00:00
|
|
|
while getopts ':-:' optchar; do
|
|
|
|
case "$optchar" in
|
|
|
|
-)
|
2020-05-07 11:27:06 +00:00
|
|
|
case "$OPTARG" in
|
|
|
|
os=*) os="${OPTARG#*=}" ;;
|
|
|
|
os-mode=*) os_mode="${OPTARG#*=}" ;;
|
|
|
|
qemu-args=*) qemu_args+=("${OPTARG#*=}") ;;
|
|
|
|
disk-type=*) disk_type_g="${OPTARG#*=}" ;;
|
|
|
|
read-only=*) read_only="${OPTARG#*=}" ;;
|
|
|
|
disks=*) IFS=":" read -ra disks <<< "${OPTARG#*=}" ;;
|
|
|
|
raw-cache=*) raw_cache=",cache${OPTARG#*=}" ;;
|
|
|
|
force=*) force_vm=${OPTARG#*=} ;;
|
|
|
|
memory=*) guest_memory=${OPTARG#*=} ;;
|
|
|
|
queue_num=*) queue_number=${OPTARG#*=} ;;
|
|
|
|
incoming=*) vm_incoming="${OPTARG#*=}" ;;
|
|
|
|
migrate-to=*) vm_migrate_to="${OPTARG#*=}" ;;
|
|
|
|
vhost-name=*) vhost_dir="$(get_vhost_dir ${OPTARG#*=})" ;;
|
|
|
|
spdk-boot=*) local boot_from="${OPTARG#*=}" ;;
|
2020-06-01 11:05:32 +00:00
|
|
|
packed) packed=true ;;
|
2020-05-07 11:27:06 +00:00
|
|
|
*)
|
|
|
|
error "unknown argument $OPTARG"
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2017-03-02 14:12:20 +00:00
|
|
|
*)
|
|
|
|
error "vm_create Unknown param $OPTARG"
|
|
|
|
return 1
|
2020-05-07 11:27:06 +00:00
|
|
|
;;
|
2017-03-02 14:12:20 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Find next directory we can use
|
2019-07-25 13:01:09 +00:00
|
|
|
if [[ -n $force_vm ]]; then
|
2017-03-02 14:12:20 +00:00
|
|
|
vm_num=$force_vm
|
|
|
|
|
|
|
|
vm_num_is_valid $vm_num || return 1
|
2019-06-04 20:29:27 +00:00
|
|
|
local vm_dir="$VM_DIR/$vm_num"
|
2017-12-18 19:45:33 +00:00
|
|
|
[[ -d $vm_dir ]] && warning "removing existing VM in '$vm_dir'"
|
2017-03-02 14:12:20 +00:00
|
|
|
else
|
|
|
|
local vm_dir=""
|
2018-01-05 18:55:37 +00:00
|
|
|
|
|
|
|
set +x
|
2020-05-07 11:27:06 +00:00
|
|
|
for ((i = 0; i <= 256; i++)); do
|
2019-06-04 20:29:27 +00:00
|
|
|
local vm_dir="$VM_DIR/$i"
|
2017-03-02 14:12:20 +00:00
|
|
|
[[ ! -d $vm_dir ]] && break
|
|
|
|
done
|
2019-12-13 16:20:12 +00:00
|
|
|
xtrace_restore
|
2017-03-02 14:12:20 +00:00
|
|
|
|
|
|
|
vm_num=$i
|
|
|
|
fi
|
|
|
|
|
2019-12-16 15:25:06 +00:00
|
|
|
if [[ $vm_num -eq 256 ]]; then
|
2017-03-02 14:12:20 +00:00
|
|
|
error "no free VM found. do some cleanup (256 VMs created, are you insane?)"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-07-25 13:01:09 +00:00
|
|
|
if [[ -n "$vm_migrate_to" && -n "$vm_incoming" ]]; then
|
2018-01-03 13:24:38 +00:00
|
|
|
error "'--incoming' and '--migrate-to' cannot be used together"
|
|
|
|
return 1
|
2019-07-25 13:01:09 +00:00
|
|
|
elif [[ -n "$vm_incoming" ]]; then
|
2019-10-25 08:49:18 +00:00
|
|
|
if [[ -n "$os_mode" || -n "$os" ]]; then
|
2018-01-03 13:24:38 +00:00
|
|
|
error "'--incoming' can't be used together with '--os' nor '--os-mode'"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
os_mode="original"
|
2019-06-04 20:29:27 +00:00
|
|
|
os="$VM_DIR/$vm_incoming/os.qcow2"
|
2019-07-25 13:01:09 +00:00
|
|
|
elif [[ -n "$vm_migrate_to" ]]; then
|
2018-01-03 13:24:38 +00:00
|
|
|
[[ "$os_mode" != "backing" ]] && warning "Using 'backing' mode for OS since '--migrate-to' is used"
|
|
|
|
os_mode=backing
|
|
|
|
fi
|
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "Creating new VM in $vm_dir"
|
2017-03-02 14:12:20 +00:00
|
|
|
mkdir -p $vm_dir
|
2018-01-03 13:24:38 +00:00
|
|
|
|
|
|
|
if [[ "$os_mode" == "backing" ]]; then
|
|
|
|
notice "Creating backing file for OS image file: $os"
|
2019-12-12 10:36:39 +00:00
|
|
|
if ! $QEMU_IMG_BIN create -f qcow2 -b $os $vm_dir/os.qcow2; then
|
2018-01-03 13:24:38 +00:00
|
|
|
error "Failed to create OS backing file in '$vm_dir/os.qcow2' using '$os'"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local os=$vm_dir/os.qcow2
|
|
|
|
elif [[ "$os_mode" == "original" ]]; then
|
|
|
|
warning "Using original OS image file: $os"
|
|
|
|
elif [[ "$os_mode" != "snapshot" ]]; then
|
|
|
|
if [[ -z "$os_mode" ]]; then
|
|
|
|
notice "No '--os-mode' parameter provided - using 'snapshot'"
|
|
|
|
os_mode="snapshot"
|
|
|
|
else
|
|
|
|
error "Invalid '--os-mode=$os_mode'"
|
|
|
|
return 1
|
|
|
|
fi
|
2017-03-02 14:12:20 +00:00
|
|
|
fi
|
2017-04-27 16:34:55 +00:00
|
|
|
|
|
|
|
local qemu_mask_param="VM_${vm_num}_qemu_mask"
|
|
|
|
local qemu_numa_node_param="VM_${vm_num}_qemu_numa_node"
|
|
|
|
|
|
|
|
if [[ -z "${!qemu_mask_param}" ]] || [[ -z "${!qemu_numa_node_param}" ]]; then
|
|
|
|
error "Parameters ${qemu_mask_param} or ${qemu_numa_node_param} not found in autotest.config file"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local task_mask=${!qemu_mask_param}
|
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "TASK MASK: $task_mask"
|
2020-04-23 08:56:36 +00:00
|
|
|
local cmd=(taskset -a -c "$task_mask" "$QEMU_BIN")
|
2020-05-07 11:27:06 +00:00
|
|
|
local vm_socket_offset=$((10000 + 100 * vm_num))
|
|
|
|
|
|
|
|
local ssh_socket=$((vm_socket_offset + 0))
|
|
|
|
local fio_socket=$((vm_socket_offset + 1))
|
|
|
|
local monitor_port=$((vm_socket_offset + 2))
|
|
|
|
local migration_port=$((vm_socket_offset + 3))
|
|
|
|
local gdbserver_socket=$((vm_socket_offset + 4))
|
|
|
|
local vnc_socket=$((100 + vm_num))
|
2017-03-02 14:12:20 +00:00
|
|
|
local qemu_pid_file="$vm_dir/qemu.pid"
|
|
|
|
local cpu_num=0
|
|
|
|
|
2018-01-05 18:55:37 +00:00
|
|
|
set +x
|
2018-06-15 11:43:55 +00:00
|
|
|
# cpu list for taskset can be comma separated or range
|
|
|
|
# or both at the same time, so first split on commas
|
|
|
|
cpu_list=$(echo $task_mask | tr "," "\n")
|
|
|
|
queue_number=0
|
|
|
|
for c in $cpu_list; do
|
|
|
|
# if range is detected - count how many cpus
|
|
|
|
if [[ $c =~ [0-9]+-[0-9]+ ]]; then
|
2020-05-07 11:27:06 +00:00
|
|
|
val=$((c - 1))
|
2018-06-15 11:43:55 +00:00
|
|
|
val=${val#-}
|
|
|
|
else
|
|
|
|
val=1
|
|
|
|
fi
|
2020-05-07 11:27:06 +00:00
|
|
|
cpu_num=$((cpu_num + val))
|
|
|
|
queue_number=$((queue_number + val))
|
2017-03-02 14:12:20 +00:00
|
|
|
done
|
2018-01-10 19:57:13 +00:00
|
|
|
|
|
|
|
if [ -z $queue_number ]; then
|
|
|
|
queue_number=$cpu_num
|
|
|
|
fi
|
|
|
|
|
2019-12-13 16:20:12 +00:00
|
|
|
xtrace_restore
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2017-04-27 16:34:55 +00:00
|
|
|
local node_num=${!qemu_numa_node_param}
|
2018-08-09 17:14:38 +00:00
|
|
|
local boot_disk_present=false
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "NUMA NODE: $node_num"
|
2020-04-23 08:56:36 +00:00
|
|
|
cmd+=(-m "$guest_memory" --enable-kvm -cpu host -smp "$cpu_num" -vga std -vnc ":$vnc_socket" -daemonize)
|
|
|
|
cmd+=(-object "memory-backend-file,id=mem,size=${guest_memory}M,mem-path=/dev/hugepages,share=on,prealloc=yes,host-nodes=$node_num,policy=bind")
|
|
|
|
[[ $os_mode == snapshot ]] && cmd+=(-snapshot)
|
|
|
|
[[ -n "$vm_incoming" ]] && cmd+=(-incoming "tcp:0:$migration_port")
|
|
|
|
cmd+=(-monitor "telnet:127.0.0.1:$monitor_port,server,nowait")
|
|
|
|
cmd+=(-numa "node,memdev=mem")
|
|
|
|
cmd+=(-pidfile "$qemu_pid_file")
|
|
|
|
cmd+=(-serial "file:$vm_dir/serial.log")
|
|
|
|
cmd+=(-D "$vm_dir/qemu.log")
|
|
|
|
cmd+=(-chardev "file,path=$vm_dir/seabios.log,id=seabios" -device "isa-debugcon,iobase=0x402,chardev=seabios")
|
|
|
|
cmd+=(-net "user,hostfwd=tcp::$ssh_socket-:22,hostfwd=tcp::$fio_socket-:8765")
|
|
|
|
cmd+=(-net nic)
|
2018-08-09 17:14:38 +00:00
|
|
|
if [[ -z "$boot_from" ]]; then
|
2020-04-23 08:56:36 +00:00
|
|
|
cmd+=(-drive "file=$os,if=none,id=os_disk")
|
|
|
|
cmd+=(-device "ide-hd,drive=os_disk,bootindex=0")
|
2018-08-09 17:14:38 +00:00
|
|
|
fi
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
if ((${#disks[@]} == 0)) && [[ $disk_type_g == virtio* ]]; then
|
2020-04-23 09:22:39 +00:00
|
|
|
disks=("default_virtio.img")
|
2020-05-07 11:27:06 +00:00
|
|
|
elif ((${#disks[@]} == 0)); then
|
2020-04-23 09:22:39 +00:00
|
|
|
error "No disks defined, aborting"
|
|
|
|
return 1
|
2017-03-02 14:12:20 +00:00
|
|
|
fi
|
|
|
|
|
2020-04-23 09:22:39 +00:00
|
|
|
for disk in "${disks[@]}"; do
|
|
|
|
# Each disk can define its type in a form of a disk_name,type. The remaining parts
|
|
|
|
# of the string are dropped.
|
2020-05-07 11:27:06 +00:00
|
|
|
IFS="," read -r disk disk_type _ <<< "$disk"
|
2020-04-23 09:22:39 +00:00
|
|
|
[[ -z $disk_type ]] && disk_type=$disk_type_g
|
2018-01-23 18:19:23 +00:00
|
|
|
|
2017-03-02 14:12:20 +00:00
|
|
|
case $disk_type in
|
|
|
|
virtio)
|
|
|
|
local raw_name="RAWSCSI"
|
|
|
|
local raw_disk=$vm_dir/test.img
|
|
|
|
|
2019-07-25 13:01:09 +00:00
|
|
|
if [[ -n $disk ]]; then
|
2017-03-02 14:12:20 +00:00
|
|
|
[[ ! -b $disk ]] && touch $disk
|
2019-10-24 13:58:04 +00:00
|
|
|
local raw_disk
|
|
|
|
raw_disk=$(readlink -f $disk)
|
2017-03-02 14:12:20 +00:00
|
|
|
fi
|
|
|
|
|
2018-09-27 07:12:45 +00:00
|
|
|
# Create disk file if it not exist or it is smaller than 1G
|
2020-05-07 11:27:06 +00:00
|
|
|
if { [[ -f $raw_disk ]] && [[ $(stat --printf="%s" $raw_disk) -lt $((1024 * 1024 * 1024)) ]]; } \
|
|
|
|
|| [[ ! -e $raw_disk ]]; then
|
2017-03-02 14:12:20 +00:00
|
|
|
if [[ $raw_disk =~ /dev/.* ]]; then
|
|
|
|
error \
|
2018-01-29 23:43:37 +00:00
|
|
|
"ERROR: Virtio disk point to missing device ($raw_disk) -\n" \
|
2017-03-02 14:12:20 +00:00
|
|
|
" this is probably not what you want."
|
2020-05-07 11:27:06 +00:00
|
|
|
return 1
|
2017-03-02 14:12:20 +00:00
|
|
|
fi
|
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "Creating Virtio disc $raw_disk"
|
2018-09-27 07:12:45 +00:00
|
|
|
dd if=/dev/zero of=$raw_disk bs=1024k count=1024
|
2017-03-02 14:12:20 +00:00
|
|
|
else
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "Using existing image $raw_disk"
|
2017-03-02 14:12:20 +00:00
|
|
|
fi
|
|
|
|
|
2020-04-23 08:56:36 +00:00
|
|
|
cmd+=(-device "virtio-scsi-pci,num_queues=$queue_number")
|
|
|
|
cmd+=(-device "scsi-hd,drive=hd$i,vendor=$raw_name")
|
|
|
|
cmd+=(-drive "if=none,id=hd$i,file=$raw_disk,format=raw$raw_cache")
|
2017-03-02 14:12:20 +00:00
|
|
|
;;
|
2017-06-16 10:03:46 +00:00
|
|
|
spdk_vhost_scsi)
|
2018-02-01 14:32:21 +00:00
|
|
|
notice "using socket $vhost_dir/naa.$disk.$vm_num"
|
2020-04-23 08:56:36 +00:00
|
|
|
cmd+=(-chardev "socket,id=char_$disk,path=$vhost_dir/naa.$disk.$vm_num")
|
|
|
|
cmd+=(-device "vhost-user-scsi-pci,id=scsi_$disk,num_queues=$queue_number,chardev=char_$disk")
|
2018-08-09 17:14:38 +00:00
|
|
|
if [[ "$disk" == "$boot_from" ]]; then
|
2020-04-23 08:56:36 +00:00
|
|
|
cmd[-1]+=,bootindex=0
|
2018-08-09 17:14:38 +00:00
|
|
|
boot_disk_present=true
|
|
|
|
fi
|
2017-03-02 14:12:20 +00:00
|
|
|
;;
|
2017-06-16 10:03:46 +00:00
|
|
|
spdk_vhost_blk)
|
2018-02-01 14:32:21 +00:00
|
|
|
notice "using socket $vhost_dir/naa.$disk.$vm_num"
|
2020-04-23 08:56:36 +00:00
|
|
|
cmd+=(-chardev "socket,id=char_$disk,path=$vhost_dir/naa.$disk.$vm_num")
|
|
|
|
cmd+=(-device "vhost-user-blk-pci,num-queues=$queue_number,chardev=char_$disk")
|
2018-08-09 17:14:38 +00:00
|
|
|
if [[ "$disk" == "$boot_from" ]]; then
|
2020-04-23 08:56:36 +00:00
|
|
|
cmd[-1]+=,bootindex=0
|
2018-08-09 17:14:38 +00:00
|
|
|
boot_disk_present=true
|
|
|
|
fi
|
2020-06-01 11:05:32 +00:00
|
|
|
|
|
|
|
if $packed; then
|
|
|
|
check_qemu_packedring_support
|
|
|
|
notice "Enabling packed ring support for VM $vm_num, controller $vhost_dir/naa.$disk.$vm_num"
|
|
|
|
cmd[-1]+=,packed=on
|
|
|
|
fi
|
2017-06-16 10:03:46 +00:00
|
|
|
;;
|
2017-03-02 14:12:20 +00:00
|
|
|
kernel_vhost)
|
|
|
|
if [[ -z $disk ]]; then
|
|
|
|
error "need WWN for $disk_type"
|
|
|
|
return 1
|
|
|
|
elif [[ ! $disk =~ ^[[:alpha:]]{3}[.][[:xdigit:]]+$ ]]; then
|
|
|
|
error "$disk_type - disk(wnn)=$disk does not look like WNN number"
|
|
|
|
return 1
|
|
|
|
fi
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "Using kernel vhost disk wwn=$disk"
|
2020-04-23 08:56:36 +00:00
|
|
|
cmd+=(-device "vhost-scsi-pci,wwpn=$disk,num_queues=$queue_number")
|
2017-03-02 14:12:20 +00:00
|
|
|
;;
|
|
|
|
*)
|
2017-06-16 10:03:46 +00:00
|
|
|
error "unknown mode '$disk_type', use: virtio, spdk_vhost_scsi, spdk_vhost_blk or kernel_vhost"
|
2017-03-02 14:12:20 +00:00
|
|
|
return 1
|
2020-04-23 09:29:40 +00:00
|
|
|
;;
|
2017-03-02 14:12:20 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2018-08-09 17:14:38 +00:00
|
|
|
if [[ -n $boot_from ]] && [[ $boot_disk_present == false ]]; then
|
|
|
|
error "Boot from $boot_from is selected but device is not present"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
((${#qemu_args[@]})) && cmd+=("${qemu_args[@]}")
|
2018-01-03 13:24:38 +00:00
|
|
|
notice "Saving to $vm_dir/run.sh"
|
2020-05-07 11:27:06 +00:00
|
|
|
cat <<- RUN > "$vm_dir/run.sh"
|
2020-05-04 07:54:28 +00:00
|
|
|
#!/bin/bash
|
2020-05-04 08:57:37 +00:00
|
|
|
qemu_log () {
|
|
|
|
echo "=== qemu.log ==="
|
|
|
|
[[ -s $vm_dir/qemu.log ]] && cat $vm_dir/qemu.log
|
|
|
|
echo "=== qemu.log ==="
|
|
|
|
}
|
2020-05-04 07:54:28 +00:00
|
|
|
|
|
|
|
if [[ \$EUID -ne 0 ]]; then
|
|
|
|
echo "Go away user come back as root"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-05-04 08:57:37 +00:00
|
|
|
trap "qemu_log" EXIT
|
2020-05-04 07:54:28 +00:00
|
|
|
|
2020-05-04 08:57:37 +00:00
|
|
|
qemu_cmd=($(printf '%s\n' "${cmd[@]}"))
|
|
|
|
chmod +r $vm_dir/*
|
2020-05-04 07:54:28 +00:00
|
|
|
echo "Running VM in $vm_dir"
|
|
|
|
rm -f $qemu_pid_file
|
|
|
|
"\${qemu_cmd[@]}"
|
2020-05-04 08:57:37 +00:00
|
|
|
|
2020-05-04 07:54:28 +00:00
|
|
|
echo "Waiting for QEMU pid file"
|
|
|
|
sleep 1
|
|
|
|
[[ ! -f $qemu_pid_file ]] && sleep 1
|
|
|
|
[[ ! -f $qemu_pid_file ]] && echo "ERROR: no qemu pid file found" && exit 1
|
2020-05-04 08:57:37 +00:00
|
|
|
exit 0
|
2020-05-04 07:54:28 +00:00
|
|
|
# EOF
|
|
|
|
RUN
|
2017-03-02 14:12:20 +00:00
|
|
|
chmod +x $vm_dir/run.sh
|
|
|
|
|
|
|
|
# Save generated sockets redirection
|
|
|
|
echo $ssh_socket > $vm_dir/ssh_socket
|
|
|
|
echo $fio_socket > $vm_dir/fio_socket
|
2018-01-03 13:24:38 +00:00
|
|
|
echo $monitor_port > $vm_dir/monitor_port
|
|
|
|
|
|
|
|
rm -f $vm_dir/migration_port
|
|
|
|
[[ -z $vm_incoming ]] || echo $migration_port > $vm_dir/migration_port
|
|
|
|
|
2017-03-02 14:12:20 +00:00
|
|
|
echo $gdbserver_socket > $vm_dir/gdbserver_socket
|
|
|
|
echo $vnc_socket >> $vm_dir/vnc_socket
|
2018-01-03 13:24:38 +00:00
|
|
|
|
2019-06-04 20:29:27 +00:00
|
|
|
[[ -z $vm_incoming ]] || ln -fs $VM_DIR/$vm_incoming $vm_dir/vm_incoming
|
|
|
|
[[ -z $vm_migrate_to ]] || ln -fs $VM_DIR/$vm_migrate_to $vm_dir/vm_migrate_to
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_run() {
|
2018-01-30 14:18:17 +00:00
|
|
|
local OPTIND optchar vm
|
2017-03-02 14:12:20 +00:00
|
|
|
local run_all=false
|
2018-01-30 14:18:17 +00:00
|
|
|
local vms_to_run=""
|
|
|
|
|
2017-03-02 14:12:20 +00:00
|
|
|
while getopts 'a-:' optchar; do
|
|
|
|
case "$optchar" in
|
|
|
|
a) run_all=true ;;
|
|
|
|
*)
|
2017-12-18 19:45:33 +00:00
|
|
|
error "Unknown param $OPTARG"
|
2017-03-02 14:12:20 +00:00
|
|
|
return 1
|
2020-05-07 11:27:06 +00:00
|
|
|
;;
|
2017-03-02 14:12:20 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if $run_all; then
|
2018-01-30 14:18:17 +00:00
|
|
|
vms_to_run="$(vm_list_all)"
|
2017-03-02 14:12:20 +00:00
|
|
|
else
|
2020-05-07 11:27:06 +00:00
|
|
|
shift $((OPTIND - 1))
|
2019-11-25 11:21:54 +00:00
|
|
|
for vm in "$@"; do
|
2017-03-02 14:12:20 +00:00
|
|
|
vm_num_is_valid $1 || return 1
|
2019-06-04 20:29:27 +00:00
|
|
|
if [[ ! -x $VM_DIR/$vm/run.sh ]]; then
|
2017-03-02 14:12:20 +00:00
|
|
|
error "VM$vm not defined - setup it first"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-01-30 14:18:17 +00:00
|
|
|
vms_to_run+=" $vm"
|
2017-03-02 14:12:20 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
for vm in $vms_to_run; do
|
2018-01-30 14:18:17 +00:00
|
|
|
if vm_is_running $vm; then
|
2019-06-04 20:29:27 +00:00
|
|
|
warning "VM$vm ($VM_DIR/$vm) already running"
|
2017-03-02 14:12:20 +00:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2019-06-04 20:29:27 +00:00
|
|
|
notice "running $VM_DIR/$vm/run.sh"
|
|
|
|
if ! $VM_DIR/$vm/run.sh; then
|
2017-03-02 14:12:20 +00:00
|
|
|
error "FAILED to run vm $vm"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_print_logs() {
|
2019-03-20 20:48:26 +00:00
|
|
|
vm_num=$1
|
|
|
|
warning "================"
|
|
|
|
warning "QEMU LOG:"
|
2019-06-04 20:29:27 +00:00
|
|
|
if [[ -r $VM_DIR/$vm_num/qemu.log ]]; then
|
|
|
|
cat $VM_DIR/$vm_num/qemu.log
|
2019-03-20 20:48:26 +00:00
|
|
|
else
|
|
|
|
warning "LOG qemu.log not found"
|
|
|
|
fi
|
|
|
|
|
|
|
|
warning "VM LOG:"
|
2019-06-04 20:29:27 +00:00
|
|
|
if [[ -r $VM_DIR/$vm_num/serial.log ]]; then
|
|
|
|
cat $VM_DIR/$vm_num/serial.log
|
2019-03-20 20:48:26 +00:00
|
|
|
else
|
|
|
|
warning "LOG serial.log not found"
|
|
|
|
fi
|
|
|
|
|
|
|
|
warning "SEABIOS LOG:"
|
2019-06-04 20:29:27 +00:00
|
|
|
if [[ -r $VM_DIR/$vm_num/seabios.log ]]; then
|
|
|
|
cat $VM_DIR/$vm_num/seabios.log
|
2019-03-20 20:48:26 +00:00
|
|
|
else
|
|
|
|
warning "LOG seabios.log not found"
|
|
|
|
fi
|
|
|
|
warning "================"
|
|
|
|
}
|
|
|
|
|
2017-03-02 14:12:20 +00:00
|
|
|
# Wait for all created VMs to boot.
|
|
|
|
# param $1 max wait time
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_wait_for_boot() {
|
2017-03-02 14:12:20 +00:00
|
|
|
assert_number $1
|
|
|
|
|
2019-12-13 16:20:12 +00:00
|
|
|
xtrace_disable
|
2018-01-05 18:55:37 +00:00
|
|
|
|
2017-03-02 14:12:20 +00:00
|
|
|
local all_booted=false
|
|
|
|
local timeout_time=$1
|
|
|
|
[[ $timeout_time -lt 10 ]] && timeout_time=10
|
2019-10-24 13:58:04 +00:00
|
|
|
local timeout_time
|
|
|
|
timeout_time=$(date -d "+$timeout_time seconds" +%s)
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "Waiting for VMs to boot"
|
2017-03-02 14:12:20 +00:00
|
|
|
shift
|
2019-10-01 19:40:07 +00:00
|
|
|
if [[ "$*" == "" ]]; then
|
2019-06-04 20:29:27 +00:00
|
|
|
local vms_to_check="$VM_DIR/[0-9]*"
|
2017-03-02 14:12:20 +00:00
|
|
|
else
|
|
|
|
local vms_to_check=""
|
2019-11-25 11:21:54 +00:00
|
|
|
for vm in "$@"; do
|
2019-06-04 20:29:27 +00:00
|
|
|
vms_to_check+=" $VM_DIR/$vm"
|
2017-03-02 14:12:20 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
for vm in $vms_to_check; do
|
2019-10-24 13:58:04 +00:00
|
|
|
local vm_num
|
|
|
|
vm_num=$(basename $vm)
|
2017-03-02 14:12:20 +00:00
|
|
|
local i=0
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "waiting for VM$vm_num ($vm)"
|
2017-03-02 14:12:20 +00:00
|
|
|
while ! vm_os_booted $vm_num; do
|
|
|
|
if ! vm_is_running $vm_num; then
|
2017-12-18 19:45:33 +00:00
|
|
|
warning "VM $vm_num is not running"
|
2019-03-20 20:48:26 +00:00
|
|
|
vm_print_logs $vm_num
|
2019-12-13 16:20:12 +00:00
|
|
|
xtrace_restore
|
2017-03-02 14:12:20 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $(date +%s) -gt $timeout_time ]]; then
|
2018-01-05 18:55:37 +00:00
|
|
|
warning "timeout waiting for machines to boot"
|
2019-03-20 20:48:26 +00:00
|
|
|
vm_print_logs $vm_num
|
2019-12-13 16:20:12 +00:00
|
|
|
xtrace_restore
|
2017-03-02 14:12:20 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2020-05-07 11:27:06 +00:00
|
|
|
if ((i > 30)); then
|
2017-03-02 14:12:20 +00:00
|
|
|
local i=0
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
echo -n "."
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo ""
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "VM$vm_num ready"
|
2018-10-02 14:17:41 +00:00
|
|
|
#Change Timeout for stopping services to prevent lengthy powerdowns
|
2019-02-05 08:41:22 +00:00
|
|
|
#Check that remote system is not Cygwin in case of Windows VMs
|
2019-10-24 13:58:04 +00:00
|
|
|
local vm_os
|
|
|
|
vm_os=$(vm_exec $vm_num "uname -o")
|
2019-02-05 08:41:22 +00:00
|
|
|
if [[ "$vm_os" != "Cygwin" ]]; then
|
2019-06-04 22:00:09 +00:00
|
|
|
vm_exec $vm_num "echo 'DefaultTimeoutStopSec=10' >> /etc/systemd/system.conf; systemctl daemon-reexec"
|
2019-02-05 08:41:22 +00:00
|
|
|
fi
|
2017-03-02 14:12:20 +00:00
|
|
|
done
|
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "all VMs ready"
|
2019-12-13 16:20:12 +00:00
|
|
|
xtrace_restore
|
2017-03-02 14:12:20 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_start_fio_server() {
|
2017-03-02 14:12:20 +00:00
|
|
|
local OPTIND optchar
|
|
|
|
local readonly=''
|
2020-05-21 07:43:44 +00:00
|
|
|
local fio_bin=''
|
2017-03-02 14:12:20 +00:00
|
|
|
while getopts ':-:' optchar; do
|
|
|
|
case "$optchar" in
|
|
|
|
-)
|
2020-05-07 11:27:06 +00:00
|
|
|
case "$OPTARG" in
|
|
|
|
fio-bin=*) local fio_bin="${OPTARG#*=}" ;;
|
|
|
|
readonly) local readonly="--readonly" ;;
|
|
|
|
*) error "Invalid argument '$OPTARG'" && return 1 ;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*) error "Invalid argument '$OPTARG'" && return 1 ;;
|
2017-03-02 14:12:20 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
shift $((OPTIND - 1))
|
2019-11-25 11:21:54 +00:00
|
|
|
for vm_num in "$@"; do
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "Starting fio server on VM$vm_num"
|
2017-03-02 14:12:20 +00:00
|
|
|
if [[ $fio_bin != "" ]]; then
|
2020-01-14 12:03:17 +00:00
|
|
|
vm_exec $vm_num 'cat > /root/fio; chmod +x /root/fio' < $fio_bin
|
2019-06-04 22:00:09 +00:00
|
|
|
vm_exec $vm_num /root/fio $readonly --eta=never --server --daemonize=/root/fio.pid
|
2017-03-02 14:12:20 +00:00
|
|
|
else
|
2019-06-04 22:00:09 +00:00
|
|
|
vm_exec $vm_num fio $readonly --eta=never --server --daemonize=/root/fio.pid
|
2017-03-02 14:12:20 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_check_scsi_location() {
|
2017-03-02 14:12:20 +00:00
|
|
|
# Script to find wanted disc
|
2019-09-16 09:23:41 +00:00
|
|
|
local script='shopt -s nullglob;
|
|
|
|
for entry in /sys/block/sd*; do
|
|
|
|
disk_type="$(cat $entry/device/vendor)";
|
|
|
|
if [[ $disk_type == INTEL* ]] || [[ $disk_type == RAWSCSI* ]] || [[ $disk_type == LIO-ORG* ]]; then
|
|
|
|
fname=$(basename $entry);
|
|
|
|
echo -n " $fname";
|
|
|
|
fi;
|
2017-03-02 14:12:20 +00:00
|
|
|
done'
|
|
|
|
|
2019-06-04 22:00:09 +00:00
|
|
|
SCSI_DISK="$(echo "$script" | vm_exec $1 bash -s)"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
|
|
|
if [[ -z "$SCSI_DISK" ]]; then
|
|
|
|
error "no test disk found!"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Script to perform scsi device reset on all disks in VM
|
|
|
|
# param $1 VM num
|
|
|
|
# param $2..$n Disks to perform reset on
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_reset_scsi_devices() {
|
2017-03-02 14:12:20 +00:00
|
|
|
for disk in "${@:2}"; do
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "VM$1 Performing device reset on disk $disk"
|
2019-06-04 22:00:09 +00:00
|
|
|
vm_exec $1 sg_reset /dev/$disk -vNd
|
2017-03-02 14:12:20 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vm_check_blk_location() {
|
2017-06-16 10:03:46 +00:00
|
|
|
local script='shopt -s nullglob; cd /sys/block; echo vd*'
|
2019-06-04 22:00:09 +00:00
|
|
|
SCSI_DISK="$(echo "$script" | vm_exec $1 bash -s)"
|
2017-06-16 10:03:46 +00:00
|
|
|
|
|
|
|
if [[ -z "$SCSI_DISK" ]]; then
|
|
|
|
error "no blk test disk found!"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function run_fio() {
|
2017-12-15 15:11:02 +00:00
|
|
|
local arg
|
|
|
|
local job_file=""
|
|
|
|
local fio_bin=""
|
|
|
|
local vms=()
|
|
|
|
local out=""
|
|
|
|
local vm
|
2018-01-03 13:24:38 +00:00
|
|
|
local run_server_mode=true
|
2020-03-31 15:21:10 +00:00
|
|
|
local run_plugin_mode=false
|
2020-03-25 13:49:18 +00:00
|
|
|
local fio_start_cmd
|
|
|
|
local fio_output_format="normal"
|
2020-07-23 13:01:58 +00:00
|
|
|
local fio_gtod_reduce=false
|
2020-04-20 09:26:55 +00:00
|
|
|
local wait_for_fio=true
|
2017-12-15 15:11:02 +00:00
|
|
|
|
2019-11-25 11:21:54 +00:00
|
|
|
for arg in "$@"; do
|
2017-12-15 15:11:02 +00:00
|
|
|
case "$arg" in
|
|
|
|
--job-file=*) local job_file="${arg#*=}" ;;
|
2018-01-03 13:24:38 +00:00
|
|
|
--fio-bin=*) local fio_bin="${arg#*=}" ;;
|
2020-05-07 11:27:06 +00:00
|
|
|
--vm=*) vms+=("${arg#*=}") ;;
|
2017-12-15 15:11:02 +00:00
|
|
|
--out=*)
|
2018-01-03 13:24:38 +00:00
|
|
|
local out="${arg#*=}"
|
|
|
|
mkdir -p $out
|
|
|
|
;;
|
|
|
|
--local) run_server_mode=false ;;
|
2020-03-31 15:21:10 +00:00
|
|
|
--plugin)
|
|
|
|
notice "Using plugin mode. Disabling server mode."
|
|
|
|
run_plugin_mode=true
|
2020-05-07 11:27:06 +00:00
|
|
|
run_server_mode=false
|
|
|
|
;;
|
2020-03-25 13:49:18 +00:00
|
|
|
--json) fio_output_format="json" ;;
|
|
|
|
--hide-results) hide_results=true ;;
|
2020-04-20 09:26:55 +00:00
|
|
|
--no-wait-for-fio) wait_for_fio=false ;;
|
2020-07-23 13:01:58 +00:00
|
|
|
--gtod-reduce) fio_gtod_reduce=true ;;
|
2020-05-07 11:27:06 +00:00
|
|
|
*)
|
|
|
|
error "Invalid argument '$arg'"
|
|
|
|
return 1
|
|
|
|
;;
|
2017-12-15 15:11:02 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2019-07-25 13:01:09 +00:00
|
|
|
if [[ -n "$fio_bin" && ! -r "$fio_bin" ]]; then
|
2018-01-03 13:24:38 +00:00
|
|
|
error "FIO binary '$fio_bin' does not exist"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-01-03 10:05:35 +00:00
|
|
|
|
2020-05-21 07:45:46 +00:00
|
|
|
if [[ -z "$fio_bin" ]]; then
|
|
|
|
fio_bin="fio"
|
|
|
|
fi
|
|
|
|
|
2018-01-03 13:24:38 +00:00
|
|
|
if [[ ! -r "$job_file" ]]; then
|
|
|
|
error "Fio job '$job_file' does not exist"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2020-03-25 13:49:18 +00:00
|
|
|
fio_start_cmd="$fio_bin --eta=never "
|
|
|
|
|
2019-10-24 13:58:04 +00:00
|
|
|
local job_fname
|
|
|
|
job_fname=$(basename "$job_file")
|
2020-04-16 09:06:55 +00:00
|
|
|
log_fname="${job_fname%%.*}.log"
|
|
|
|
fio_start_cmd+=" --output=$out/$log_fname --output-format=$fio_output_format "
|
2020-03-25 13:49:18 +00:00
|
|
|
|
2017-12-15 15:11:02 +00:00
|
|
|
# prepare job file for each VM
|
2019-11-25 11:21:54 +00:00
|
|
|
for vm in "${vms[@]}"; do
|
2017-12-15 15:11:02 +00:00
|
|
|
local vm_num=${vm%%:*}
|
|
|
|
local vmdisks=${vm#*:}
|
|
|
|
|
2019-06-04 22:00:09 +00:00
|
|
|
sed "s@filename=@filename=$vmdisks@" $job_file | vm_exec $vm_num "cat > /root/$job_fname"
|
2020-07-23 13:01:58 +00:00
|
|
|
|
|
|
|
if $fio_gtod_reduce; then
|
|
|
|
vm_exec $vm_num "echo 'gtod_reduce=1' >> /root/$job_fname"
|
|
|
|
fi
|
|
|
|
|
2019-06-04 22:00:09 +00:00
|
|
|
vm_exec $vm_num cat /root/$job_fname
|
2020-03-25 13:49:18 +00:00
|
|
|
|
|
|
|
if $run_server_mode; then
|
2020-04-16 08:28:30 +00:00
|
|
|
fio_start_cmd+="--client=127.0.0.1,$(vm_fio_socket $vm_num) --remote-config /root/$job_fname "
|
2020-03-25 13:49:18 +00:00
|
|
|
fi
|
|
|
|
|
2018-01-03 13:24:38 +00:00
|
|
|
if ! $run_server_mode; then
|
2019-07-25 13:01:09 +00:00
|
|
|
if [[ -n "$fio_bin" ]]; then
|
2020-03-31 15:21:10 +00:00
|
|
|
if ! $run_plugin_mode; then
|
|
|
|
vm_exec $vm_num 'cat > /root/fio; chmod +x /root/fio' < $fio_bin
|
|
|
|
vm_fio_bin="/root/fio"
|
|
|
|
else
|
|
|
|
vm_fio_bin="/usr/src/fio/fio"
|
|
|
|
fi
|
2018-01-03 13:24:38 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
notice "Running local fio on VM $vm_num"
|
2020-04-20 09:26:55 +00:00
|
|
|
vm_exec $vm_num "$vm_fio_bin --output=/root/$log_fname --output-format=$fio_output_format /root/$job_fname & echo \$! > /root/fio.pid" &
|
2020-03-27 11:51:25 +00:00
|
|
|
vm_exec_pids+=("$!")
|
2018-01-03 13:24:38 +00:00
|
|
|
fi
|
2017-12-15 15:11:02 +00:00
|
|
|
done
|
|
|
|
|
2018-01-03 13:24:38 +00:00
|
|
|
if ! $run_server_mode; then
|
2020-04-20 09:26:55 +00:00
|
|
|
if ! $wait_for_fio; then
|
|
|
|
return 0
|
|
|
|
fi
|
2020-03-27 11:51:25 +00:00
|
|
|
echo "Waiting for guest fio instances to finish.."
|
|
|
|
wait "${vm_exec_pids[@]}"
|
|
|
|
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
local vm_num=${vm%%:*}
|
2020-04-16 09:06:55 +00:00
|
|
|
vm_exec $vm_num cat /root/$log_fname > "$out/vm${vm_num}_${log_fname}"
|
2020-03-27 11:51:25 +00:00
|
|
|
done
|
2018-01-03 13:24:38 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2020-03-25 13:49:18 +00:00
|
|
|
$fio_start_cmd
|
2020-05-21 07:45:46 +00:00
|
|
|
sleep 1
|
2020-03-25 13:49:18 +00:00
|
|
|
|
2020-07-07 09:52:28 +00:00
|
|
|
if [[ "$fio_output_format" == "json" ]]; then
|
|
|
|
# Fio in client-server mode produces a lot of "trash" output
|
|
|
|
# preceding JSON structure, making it not possible to parse.
|
|
|
|
# Remove these lines from file.
|
|
|
|
# shellcheck disable=SC2005
|
|
|
|
echo "$(grep -vP '^[<\w]' "$out/$log_fname")" > "$out/$log_fname"
|
|
|
|
fi
|
|
|
|
|
2020-03-25 13:49:18 +00:00
|
|
|
if [[ ! $hide_results ]]; then
|
2020-04-16 09:06:55 +00:00
|
|
|
cat $out/$log_fname
|
2020-03-25 13:49:18 +00:00
|
|
|
fi
|
2017-12-15 15:11:02 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 15:43:39 +00:00
|
|
|
# Parsing fio results for json output and client-server mode only!
|
|
|
|
function parse_fio_results() {
|
|
|
|
local fio_log_dir=$1
|
|
|
|
local fio_log_filename=$2
|
|
|
|
local fio_csv_filename
|
|
|
|
|
|
|
|
# Variables used in parsing loop
|
|
|
|
local log_file
|
|
|
|
local rwmode mixread mixwrite
|
|
|
|
local lat_key lat_divisor
|
|
|
|
local client_stats iops bw
|
|
|
|
local read_avg_lat read_min_lat read_max_lat
|
|
|
|
local write_avg_lat write_min_lat write_min_lat
|
|
|
|
|
|
|
|
declare -A results
|
|
|
|
results["iops"]=0
|
|
|
|
results["bw"]=0
|
|
|
|
results["avg_lat"]=0
|
|
|
|
results["min_lat"]=0
|
|
|
|
results["max_lat"]=0
|
|
|
|
|
|
|
|
# Loop using the log filename to see if there are any other
|
|
|
|
# matching files. This is in case we ran fio test multiple times.
|
|
|
|
log_files=("$fio_log_dir/$fio_log_filename"*)
|
|
|
|
for log_file in "${log_files[@]}"; do
|
|
|
|
rwmode=$(jq -r '.["client_stats"][0]["job options"]["rw"]' "$log_file")
|
|
|
|
mixread=1
|
|
|
|
mixwrite=1
|
|
|
|
if [[ $rwmode = *"rw"* ]]; then
|
|
|
|
mixread=$(jq -r '.["client_stats"][0]["job options"]["rwmixread"]' "$log_file")
|
|
|
|
mixread=$(bc -l <<< "scale=3; $mixread/100")
|
|
|
|
mixwrite=$(bc -l <<< "scale=3; 1-$mixread")
|
|
|
|
fi
|
|
|
|
|
|
|
|
client_stats=$(jq -r '.["client_stats"][] | select(.jobname == "All clients")' "$log_file")
|
|
|
|
|
|
|
|
# Check latency unit and later normalize to microseconds
|
|
|
|
lat_key="lat_us"
|
|
|
|
lat_divisor=1
|
|
|
|
if jq -er '.read["lat_ns"]' &> /dev/null <<< $client_stats; then
|
|
|
|
lat_key="lat_ns"
|
|
|
|
lat_divisor=1000
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Horrific bash float point arithmetic oprations below.
|
|
|
|
# Viewer discretion is advised.
|
|
|
|
iops=$(jq -r '[.read["iops"],.write["iops"]] | add' <<< $client_stats)
|
|
|
|
bw=$(jq -r '[.read["bw"],.write["bw"]] | add' <<< $client_stats)
|
|
|
|
read_avg_lat=$(jq -r --arg lat_key $lat_key '.read[$lat_key]["mean"]' <<< $client_stats)
|
|
|
|
read_min_lat=$(jq -r --arg lat_key $lat_key '.read[$lat_key]["min"]' <<< $client_stats)
|
|
|
|
read_max_lat=$(jq -r --arg lat_key $lat_key '.read[$lat_key]["max"]' <<< $client_stats)
|
|
|
|
write_avg_lat=$(jq -r --arg lat_key $lat_key '.write[$lat_key]["mean"]' <<< $client_stats)
|
|
|
|
write_min_lat=$(jq -r --arg lat_key $lat_key '.write[$lat_key]["min"]' <<< $client_stats)
|
|
|
|
write_max_lat=$(jq -r --arg lat_key $lat_key '.write[$lat_key]["max"]' <<< $client_stats)
|
|
|
|
|
|
|
|
results["iops"]=$(bc -l <<< "${results[iops]} + $iops")
|
|
|
|
results["bw"]=$(bc -l <<< "${results[bw]} + $bw")
|
|
|
|
results["avg_lat"]=$(bc -l <<< "${results[avg_lat]} + ($mixread*$read_avg_lat + $mixwrite*$write_avg_lat)/$lat_divisor")
|
|
|
|
results["min_lat"]=$(bc -l <<< "${results[min_lat]} + ($mixread*$read_min_lat + $mixwrite*$write_min_lat)/$lat_divisor")
|
|
|
|
results["max_lat"]=$(bc -l <<< "${results[max_lat]} + ($mixread*$read_max_lat + $mixwrite*$write_max_lat)/$lat_divisor")
|
|
|
|
done
|
|
|
|
|
|
|
|
results["iops"]=$(bc -l <<< "scale=3; ${results[iops]} / ${#log_files[@]}")
|
|
|
|
results["bw"]=$(bc -l <<< "scale=3; ${results[bw]} / ${#log_files[@]}")
|
|
|
|
results["avg_lat"]=$(bc -l <<< "scale=3; ${results[avg_lat]} / ${#log_files[@]}")
|
|
|
|
results["min_lat"]=$(bc -l <<< "scale=3; ${results[min_lat]} / ${#log_files[@]}")
|
|
|
|
results["max_lat"]=$(bc -l <<< "scale=3; ${results[max_lat]} / ${#log_files[@]}")
|
|
|
|
|
|
|
|
fio_csv_filename="${fio_log_filename%%.*}.csv"
|
|
|
|
cat <<- EOF > "$fio_log_dir/$fio_csv_filename"
|
|
|
|
iops,bw,avg_lat,min_lat,max_lat
|
|
|
|
${results["iops"]},${results["bw"]},${results["avg_lat"]},${results["min_lat"]},${results["max_lat"]}
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2017-03-02 14:12:20 +00:00
|
|
|
# Shutdown or kill any running VM and SPDK APP.
|
|
|
|
#
|
2020-05-07 11:27:06 +00:00
|
|
|
function at_app_exit() {
|
2019-06-04 20:55:21 +00:00
|
|
|
local vhost_name
|
2018-02-01 14:32:21 +00:00
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "APP EXITING"
|
|
|
|
notice "killing all VMs"
|
2017-03-02 14:12:20 +00:00
|
|
|
vm_kill_all
|
|
|
|
# Kill vhost application
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "killing vhost app"
|
2018-02-01 14:32:21 +00:00
|
|
|
|
2019-12-10 06:58:35 +00:00
|
|
|
for vhost_name in "$TARGET_DIR"/*; do
|
2020-11-06 11:27:51 +00:00
|
|
|
vhost_kill "$(basename "$vhost_name")"
|
2018-02-01 14:32:21 +00:00
|
|
|
done
|
2017-03-02 14:12:20 +00:00
|
|
|
|
2017-12-18 19:45:33 +00:00
|
|
|
notice "EXIT DONE"
|
2017-03-02 14:12:20 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function error_exit() {
|
2017-03-02 14:12:20 +00:00
|
|
|
trap - ERR
|
2017-10-23 20:37:23 +00:00
|
|
|
print_backtrace
|
2017-03-02 14:12:20 +00:00
|
|
|
set +e
|
2017-12-18 19:45:33 +00:00
|
|
|
error "Error on $1 $2"
|
2017-03-02 14:12:20 +00:00
|
|
|
|
|
|
|
at_app_exit
|
|
|
|
exit 1
|
|
|
|
}
|