2017-09-26 13:02:52 +00:00
|
|
|
# Prints error message and return error code, closes vhost app and remove
|
|
|
|
# pmem pool file
|
|
|
|
# input: error message, error code
|
2020-05-07 11:27:06 +00:00
|
|
|
function error() {
|
2017-09-26 13:02:52 +00:00
|
|
|
local error_code=${2:-1}
|
|
|
|
echo "==========="
|
|
|
|
echo -e "ERROR: $1"
|
|
|
|
echo "error code: $error_code"
|
|
|
|
echo "==========="
|
2019-06-04 20:55:21 +00:00
|
|
|
vhost_kill 0
|
2017-09-26 13:02:52 +00:00
|
|
|
pmem_clean_pool_file
|
|
|
|
return $error_code
|
|
|
|
}
|
|
|
|
|
|
|
|
# check if there is pool file & remove it
|
|
|
|
# input: path to pool file
|
2019-06-15 18:47:53 +00:00
|
|
|
# default: $default_pool_file
|
2020-05-07 11:27:06 +00:00
|
|
|
function pmem_clean_pool_file() {
|
2019-06-15 18:47:53 +00:00
|
|
|
local pool_file=${1:-$default_pool_file}
|
2017-09-26 13:02:52 +00:00
|
|
|
|
|
|
|
if [ -f $pool_file ]; then
|
|
|
|
echo "Deleting old pool_file"
|
|
|
|
rm $pool_file
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# create new pmem file
|
|
|
|
# input: path to pool file, size in MB, block_size
|
2019-06-15 18:47:53 +00:00
|
|
|
# default: $default_pool_file 32 512
|
2020-05-07 11:27:06 +00:00
|
|
|
function pmem_create_pool_file() {
|
2019-06-15 18:47:53 +00:00
|
|
|
local pool_file=${1:-$default_pool_file}
|
2017-09-26 13:02:52 +00:00
|
|
|
local size=${2:-32}
|
|
|
|
local block_size=${3:-512}
|
|
|
|
|
|
|
|
pmem_clean_pool_file $pool_file
|
|
|
|
echo "Creating new pool file"
|
2019-08-29 10:36:38 +00:00
|
|
|
if ! $rpc_py bdev_pmem_create_pool $pool_file $size $block_size; then
|
2017-09-26 13:02:52 +00:00
|
|
|
error "Creating pool_file failed!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f $pool_file ]; then
|
|
|
|
error "Creating pool_file failed!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function pmem_unmount_ramspace() {
|
2019-06-15 18:47:53 +00:00
|
|
|
if [ -d "$testdir/ramspace" ]; then
|
|
|
|
if mount | grep -q "$testdir/ramspace"; then
|
|
|
|
umount $testdir/ramspace
|
2017-09-26 13:02:52 +00:00
|
|
|
fi
|
|
|
|
|
2019-06-15 18:47:53 +00:00
|
|
|
rm -rf $testdir/ramspace
|
2017-09-26 13:02:52 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function pmem_print_tc_name() {
|
2017-09-26 13:02:52 +00:00
|
|
|
echo ""
|
|
|
|
echo "==============================================================="
|
|
|
|
echo "Now running: $1"
|
|
|
|
echo "==============================================================="
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vhost_start() {
|
2017-09-26 13:02:52 +00:00
|
|
|
local vhost_pid
|
|
|
|
|
2020-05-11 21:15:03 +00:00
|
|
|
$SPDK_BIN_DIR/vhost &
|
2017-09-26 13:02:52 +00:00
|
|
|
|
|
|
|
vhost_pid=$!
|
2019-06-15 18:47:53 +00:00
|
|
|
echo $vhost_pid > $testdir/vhost.pid
|
2017-11-09 23:33:29 +00:00
|
|
|
waitforlisten $vhost_pid
|
2017-09-26 13:02:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function vhost_kill() {
|
2019-06-15 18:47:53 +00:00
|
|
|
local vhost_pid_file="$testdir/vhost.pid"
|
2019-10-24 13:58:04 +00:00
|
|
|
local vhost_pid
|
|
|
|
vhost_pid="$(cat $vhost_pid_file)"
|
2017-09-26 13:02:52 +00:00
|
|
|
|
2019-06-15 18:47:53 +00:00
|
|
|
if [[ ! -f $vhost_pid_file ]]; then
|
2017-09-26 13:02:52 +00:00
|
|
|
echo -e "ERROR: No vhost pid file found!"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! kill -s INT $vhost_pid; then
|
|
|
|
echo -e "ERROR: Failed to exit vhost / invalid pid!"
|
|
|
|
rm $vhost_pid_file
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
rm $vhost_pid_file
|
|
|
|
}
|