nbd: add rpc test scripts

Test nbd rpc methods:
  start_nbd_disk
  get_nbd_disk
  stop_nbd_disk

Verify nbd data read and write by dd and cmp.

Change-Id: Ie32639d11727893ceac7adce0119b9c2085e74e1
Signed-off-by: Xiaodong Liu <xiaodong.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/391732
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Xiaodong Liu 2017-12-13 20:44:56 -05:00 committed by Jim Harris
parent e4150a5540
commit cc8533a990
2 changed files with 131 additions and 2 deletions

View File

@ -18,6 +18,35 @@ function run_fio()
}
source $rootdir/scripts/autotest_common.sh
source $testdir/nbd/nbd_common.sh
function nbd_function_test() {
if [ $(uname -s) = Linux ] && modprobe -n nbd; then
local rpc_server=/var/tmp/spdk-nbd.sock
local conf=$1
local nbd_num=6
local nbd_all=(`ls /dev/nbd*`)
local bdev_all=($bdevs_name)
local nbd_list=(${nbd_all[@]:0:$nbd_num})
local bdev_list=(${bdev_all[@]:0:$nbd_num})
if [ ! -e $conf ]; then
return 1
fi
modprobe nbd
$rootdir/test/app/bdev_svc/bdev_svc -r $rpc_server -i 0 -c ${conf} &
nbd_pid=$!
echo "Process nbd pid: $nbd_pid"
waitforlisten $nbd_pid $rpc_server
nbd_rpc_data_verify $rpc_server "${bdev_list[*]}" "${nbd_list[*]}"
killprocess $nbd_pid
fi
return 0
}
timing_enter bdev
@ -31,16 +60,21 @@ timing_enter bounds
$testdir/bdevio/bdevio $testdir/bdev.conf
timing_exit bounds
timing_enter nbd
timing_enter nbd_gpt
if grep -q Nvme0 $testdir/bdev.conf; then
part_dev_by_gpt $testdir/bdev.conf Nvme0n1 $rootdir
fi
timing_exit nbd
timing_exit nbd_gpt
timing_enter bdev_svc
bdevs=$(discover_bdevs $rootdir $testdir/bdev.conf | jq -r '.[] | select(.claimed == false)')
timing_exit bdev_svc
timing_enter nbd
bdevs_name=$(echo $bdevs | jq -r '.name')
nbd_function_test $testdir/bdev.conf "$bdevs_name"
timing_exit nbd
if [ -d /usr/src/fio ] && [ $SPDK_RUN_ASAN -eq 0 ]; then
timing_enter fio

View File

@ -0,0 +1,95 @@
set -e
function nbd_start_disks() {
local rpc_server=$1
local bdev_list=($2)
local nbd_list=($3)
for (( i=0; i<${#nbd_list[@]}; i++ )); do
$rootdir/scripts/rpc.py -s $rpc_server start_nbd_disk \
${bdev_list[$i]} ${nbd_list[$i]}
done
# Wait for nbd devices ready
for i in ${nbd_list[@]}; do
waitfornbd ${i:5}
done
}
function waitfornbd_exit() {
nbd_name=$1
for ((i=1; i<=20; i++)); do
if grep -q -w $nbd_name /proc/partitions; then
sleep 0.1
else
break
fi
done
return 0
}
function nbd_stop_disks() {
local rpc_server=$1
local nbd_list=($2)
for i in ${nbd_list[@]}; do
$rootdir/scripts/rpc.py -s $rpc_server stop_nbd_disk $i
done
for i in ${nbd_list[@]}; do
waitfornbd_exit ${i:5}
done
}
function nbd_get_count() {
# return = count of spdk nbd devices
local rpc_server=$1
nbd_disks_json=`$rootdir/scripts/rpc.py -s $rpc_server get_nbd_disks`
nbd_disks_name=`echo "${nbd_disks_json}" | jq -r '.[] | .nbd_device'`
count=`echo "${nbd_disks_name}" | grep -c /dev/nbd || true`
echo $count
}
function nbd_dd_data_verify() {
local nbd_list=($1)
local operation=$2
local tmp_file=/tmp/nbdrandtest
if [ "$operation" = "write" ]; then
# data write
dd if=/dev/urandom of=$tmp_file bs=4096 count=256
for i in ${nbd_list[@]}; do
dd if=$tmp_file of=$i bs=4096 count=256 oflag=direct
done
elif [ "$operation" = "verify" ]; then
# data read and verify
for i in ${nbd_list[@]}; do
cmp -b -n 1M $tmp_file $i
done
rm $tmp_file
fi
}
function nbd_rpc_data_verify() {
local rpc_server=$1
local bdev_list=($2)
local nbd_list=($3)
nbd_start_disks $rpc_server "${bdev_list[*]}" "${nbd_list[*]}"
count=$(nbd_get_count $rpc_server)
if [ $count -ne ${#nbd_list[@]} ]; then
return -1
fi
nbd_dd_data_verify "${nbd_list[*]}" "write"
nbd_dd_data_verify "${nbd_list[*]}" "verify"
nbd_stop_disks $rpc_server "${nbd_list[*]}"
count=$(nbd_get_count $rpc_server)
if [ $count -ne 0 ]; then
return -1
fi
return 0
}