2017-12-14 01:44:56 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
function nbd_start_disks() {
|
|
|
|
local rpc_server=$1
|
|
|
|
local bdev_list=($2)
|
|
|
|
local nbd_list=($3)
|
2018-11-20 11:20:35 +00:00
|
|
|
local i
|
2017-12-14 01:44:56 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
for ((i = 0; i < ${#nbd_list[@]}; i++)); do
|
2019-09-17 10:36:40 +00:00
|
|
|
$rootdir/scripts/rpc.py -s $rpc_server nbd_start_disk ${bdev_list[$i]} ${nbd_list[$i]}
|
2018-11-20 11:20:35 +00:00
|
|
|
# Wait for nbd device ready
|
|
|
|
waitfornbd $(basename ${nbd_list[$i]})
|
2017-12-14 01:44:56 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-01-15 12:52:11 +00:00
|
|
|
function nbd_start_disks_without_nbd_idx() {
|
|
|
|
local rpc_server=$1
|
|
|
|
local bdev_list=($2)
|
|
|
|
local i
|
|
|
|
local nbd_device
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
for ((i = 0; i < ${#bdev_list[@]}; i++)); do
|
2019-09-17 10:36:40 +00:00
|
|
|
nbd_device=$($rootdir/scripts/rpc.py -s $rpc_server nbd_start_disk ${bdev_list[$i]})
|
2019-01-15 12:52:11 +00:00
|
|
|
# Wait for nbd device ready
|
|
|
|
waitfornbd $(basename ${nbd_device})
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-12-14 01:44:56 +00:00
|
|
|
function waitfornbd_exit() {
|
2018-11-20 11:20:35 +00:00
|
|
|
local nbd_name=$1
|
2017-12-14 01:44:56 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
for ((i = 1; i <= 20; i++)); do
|
2017-12-14 01:44:56 +00:00
|
|
|
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)
|
2018-11-20 11:20:35 +00:00
|
|
|
local i
|
2017-12-14 01:44:56 +00:00
|
|
|
|
2019-11-25 11:21:54 +00:00
|
|
|
for i in "${nbd_list[@]}"; do
|
2019-09-17 10:47:41 +00:00
|
|
|
$rootdir/scripts/rpc.py -s $rpc_server nbd_stop_disk $i
|
2018-11-20 11:20:35 +00:00
|
|
|
waitfornbd_exit $(basename $i)
|
2017-12-14 01:44:56 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function nbd_get_count() {
|
|
|
|
# return = count of spdk nbd devices
|
|
|
|
local rpc_server=$1
|
|
|
|
|
2019-09-17 10:59:02 +00:00
|
|
|
nbd_disks_json=$($rootdir/scripts/rpc.py -s $rpc_server nbd_get_disks)
|
2019-06-12 07:48:32 +00:00
|
|
|
nbd_disks_name=$(echo "${nbd_disks_json}" | jq -r '.[] | .nbd_device')
|
|
|
|
count=$(echo "${nbd_disks_name}" | grep -c /dev/nbd || true)
|
2017-12-14 01:44:56 +00:00
|
|
|
echo $count
|
|
|
|
}
|
|
|
|
|
|
|
|
function nbd_dd_data_verify() {
|
|
|
|
local nbd_list=($1)
|
|
|
|
local operation=$2
|
2020-05-10 20:07:54 +00:00
|
|
|
local tmp_file=$SPDK_TEST_STORAGE/nbdrandtest
|
2017-12-14 01:44:56 +00:00
|
|
|
|
|
|
|
if [ "$operation" = "write" ]; then
|
|
|
|
# data write
|
|
|
|
dd if=/dev/urandom of=$tmp_file bs=4096 count=256
|
2019-11-25 11:21:54 +00:00
|
|
|
for i in "${nbd_list[@]}"; do
|
2017-12-14 01:44:56 +00:00
|
|
|
dd if=$tmp_file of=$i bs=4096 count=256 oflag=direct
|
|
|
|
done
|
|
|
|
elif [ "$operation" = "verify" ]; then
|
|
|
|
# data read and verify
|
2019-11-25 11:21:54 +00:00
|
|
|
for i in "${nbd_list[@]}"; do
|
2017-12-14 01:44:56 +00:00
|
|
|
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
|
2019-10-28 12:23:22 +00:00
|
|
|
return 1
|
2017-12-14 01:44:56 +00:00
|
|
|
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
|
2019-10-28 12:23:22 +00:00
|
|
|
return 1
|
2017-12-14 01:44:56 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
2019-01-15 12:52:11 +00:00
|
|
|
|
|
|
|
function nbd_rpc_start_stop_verify() {
|
|
|
|
local rpc_server=$1
|
|
|
|
local bdev_list=($2)
|
|
|
|
|
|
|
|
nbd_start_disks_without_nbd_idx $rpc_server "${bdev_list[*]}"
|
|
|
|
|
2019-09-17 10:59:02 +00:00
|
|
|
nbd_disks_json=$($rootdir/scripts/rpc.py -s $rpc_server nbd_get_disks)
|
2019-06-12 07:48:32 +00:00
|
|
|
nbd_disks_name=($(echo "${nbd_disks_json}" | jq -r '.[] | .nbd_device'))
|
2019-01-15 12:52:11 +00:00
|
|
|
nbd_stop_disks $rpc_server "${nbd_disks_name[*]}"
|
|
|
|
|
|
|
|
count=$(nbd_get_count $rpc_server)
|
|
|
|
if [ $count -ne 0 ]; then
|
2019-10-28 12:23:22 +00:00
|
|
|
return 1
|
2019-01-15 12:52:11 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|