2016-06-29 17:02:03 +00:00
|
|
|
NVMF_PORT=4420
|
2016-06-17 19:56:56 +00:00
|
|
|
NVMF_IP_PREFIX="192.168.100"
|
2016-06-08 01:47:02 +00:00
|
|
|
NVMF_IP_LEAST_ADDR=8
|
2018-11-20 12:27:13 +00:00
|
|
|
NVMF_TCP_IP_ADDRESS="127.0.0.1"
|
2019-07-15 04:42:41 +00:00
|
|
|
NVMF_TRANSPORT_OPTS=""
|
2019-12-19 14:17:49 +00:00
|
|
|
NVMF_SERIAL=SPDK00000000000001
|
2016-06-08 01:47:02 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function build_nvmf_app_args() {
|
2019-05-15 22:23:36 +00:00
|
|
|
if [ $SPDK_RUN_NON_ROOT -eq 1 ]; then
|
2020-02-20 10:24:53 +00:00
|
|
|
NVMF_APP=(sudo -u "$USER" "${NVMF_APP[@]}")
|
|
|
|
NVMF_APP+=(-i "$NVMF_APP_SHM_ID" -e 0xFFFF)
|
2019-05-15 22:23:36 +00:00
|
|
|
else
|
2020-02-20 10:24:53 +00:00
|
|
|
NVMF_APP+=(-i "$NVMF_APP_SHM_ID" -e 0xFFFF)
|
2019-05-15 22:23:36 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
: ${NVMF_APP_SHM_ID="0"}
|
|
|
|
export NVMF_APP_SHM_ID
|
2020-02-20 10:24:53 +00:00
|
|
|
build_nvmf_app_args
|
2017-05-27 00:13:55 +00:00
|
|
|
|
2019-03-04 16:24:39 +00:00
|
|
|
have_pci_nics=0
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function load_ib_rdma_modules() {
|
2019-06-12 07:48:32 +00:00
|
|
|
if [ $(uname) != Linux ]; then
|
2016-07-08 21:19:11 +00:00
|
|
|
return 0
|
2016-06-08 01:47:02 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
modprobe ib_cm
|
|
|
|
modprobe ib_core
|
2018-08-28 06:44:36 +00:00
|
|
|
# Newer kernels do not have the ib_ucm module
|
|
|
|
modprobe ib_ucm || true
|
2016-06-08 01:47:02 +00:00
|
|
|
modprobe ib_umad
|
|
|
|
modprobe ib_uverbs
|
|
|
|
modprobe iw_cm
|
|
|
|
modprobe rdma_cm
|
|
|
|
modprobe rdma_ucm
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function detect_soft_roce_nics() {
|
2017-07-24 17:04:32 +00:00
|
|
|
if hash rxe_cfg; then
|
|
|
|
rxe_cfg start
|
2017-07-25 19:02:08 +00:00
|
|
|
rdma_nics=$(get_rdma_if_list)
|
2018-04-10 12:17:30 +00:00
|
|
|
all_nics=$(ip -o link | awk '{print $2}' | cut -d":" -f1)
|
2018-04-10 14:26:01 +00:00
|
|
|
non_rdma_nics=$(echo -e "$rdma_nics\n$all_nics" | sort | uniq -u)
|
2017-07-25 19:02:08 +00:00
|
|
|
for nic in $non_rdma_nics; do
|
2018-02-15 13:39:47 +00:00
|
|
|
if [[ -d /sys/class/net/${nic}/bridge ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
2017-07-25 19:02:08 +00:00
|
|
|
rxe_cfg add $nic || true
|
|
|
|
done
|
2017-07-24 17:04:32 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-03-04 16:50:07 +00:00
|
|
|
# args 1 and 2 represent the grep filters for finding our NICS.
|
|
|
|
# subsequent args are all drivers that should be loaded if we find these NICs.
|
|
|
|
# Those drivers should be supplied in the correct order.
|
2020-05-07 11:27:06 +00:00
|
|
|
function detect_nics_and_probe_drivers() {
|
2019-03-04 16:50:07 +00:00
|
|
|
NIC_VENDOR="$1"
|
|
|
|
NIC_CLASS="$2"
|
2019-03-04 16:16:19 +00:00
|
|
|
|
2019-06-12 07:48:32 +00:00
|
|
|
nvmf_nic_bdfs=$(lspci | grep Ethernet | grep "$NIC_VENDOR" | grep "$NIC_CLASS" | awk -F ' ' '{print "0000:"$1}')
|
2016-06-08 01:47:02 +00:00
|
|
|
|
|
|
|
if [ -z "$nvmf_nic_bdfs" ]; then
|
2016-07-08 21:19:11 +00:00
|
|
|
return 0
|
2016-06-08 01:47:02 +00:00
|
|
|
fi
|
|
|
|
|
2019-03-04 16:24:39 +00:00
|
|
|
have_pci_nics=1
|
2019-03-04 16:50:07 +00:00
|
|
|
if [ $# -ge 2 ]; then
|
|
|
|
# shift out the first two positional arguments.
|
|
|
|
shift 2
|
|
|
|
# Iterate through the remaining arguments.
|
|
|
|
for i; do
|
|
|
|
modprobe "$i"
|
|
|
|
done
|
|
|
|
fi
|
2019-03-01 20:35:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function detect_pci_nics() {
|
2019-03-01 20:35:34 +00:00
|
|
|
|
|
|
|
if ! hash lspci; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2019-03-04 16:50:07 +00:00
|
|
|
detect_nics_and_probe_drivers "Mellanox" "ConnectX-4" "mlx4_core" "mlx4_ib" "mlx4_en"
|
|
|
|
detect_nics_and_probe_drivers "Mellanox" "ConnectX-5" "mlx5_core" "mlx5_ib"
|
2019-03-01 18:12:48 +00:00
|
|
|
detect_nics_and_probe_drivers "Intel" "X722" "i40e" "i40iw"
|
2019-03-04 17:04:25 +00:00
|
|
|
detect_nics_and_probe_drivers "Chelsio" "Unified Wire" "cxgb4" "iw_cxgb4"
|
2019-03-01 20:35:34 +00:00
|
|
|
|
2019-03-04 16:24:39 +00:00
|
|
|
if [ "$have_pci_nics" -eq "0" ]; then
|
2019-03-01 20:35:34 +00:00
|
|
|
return 0
|
|
|
|
fi
|
2016-06-08 01:47:02 +00:00
|
|
|
|
2019-03-01 20:35:34 +00:00
|
|
|
# Provide time for drivers to properly load.
|
2016-06-17 19:56:56 +00:00
|
|
|
sleep 5
|
2016-06-08 01:47:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function detect_rdma_nics() {
|
2019-03-04 16:24:39 +00:00
|
|
|
detect_pci_nics
|
|
|
|
if [ "$have_pci_nics" -eq "0" ]; then
|
2018-08-06 20:27:52 +00:00
|
|
|
detect_soft_roce_nics
|
|
|
|
fi
|
2016-06-08 01:47:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function allocate_nic_ips() {
|
|
|
|
((count = NVMF_IP_LEAST_ADDR))
|
2017-08-09 22:06:08 +00:00
|
|
|
for nic_name in $(get_rdma_if_list); do
|
2017-07-25 19:02:08 +00:00
|
|
|
ip="$(get_ip_address $nic_name)"
|
|
|
|
if [ -z $ip ]; then
|
2018-04-10 12:17:30 +00:00
|
|
|
ip addr add $NVMF_IP_PREFIX.$count/24 dev $nic_name
|
|
|
|
ip link set $nic_name up
|
2020-05-07 11:27:06 +00:00
|
|
|
((count = count + 1))
|
2017-07-25 19:02:08 +00:00
|
|
|
fi
|
|
|
|
# dump configuration for debug log
|
2018-04-10 12:17:30 +00:00
|
|
|
ip addr show $nic_name
|
2016-06-08 01:47:02 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function get_available_rdma_ips() {
|
2017-08-09 22:06:08 +00:00
|
|
|
for nic_name in $(get_rdma_if_list); do
|
2018-04-10 12:17:30 +00:00
|
|
|
get_ip_address $nic_name
|
2017-07-25 19:02:08 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function get_rdma_if_list() {
|
2019-12-10 06:58:35 +00:00
|
|
|
for nic_type in /sys/class/infiniband/*; do
|
|
|
|
[[ -e "$nic_type" ]] || break
|
|
|
|
for nic_name in /sys/class/infiniband/"$(basename ${nic_type})"/device/net/*; do
|
|
|
|
[[ -e "$nic_name" ]] || break
|
|
|
|
basename "$nic_name"
|
2017-07-25 15:39:51 +00:00
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function get_ip_address() {
|
2017-07-25 19:02:08 +00:00
|
|
|
interface=$1
|
2018-04-10 12:17:30 +00:00
|
|
|
ip -o -4 addr show $interface | awk '{print $4}' | cut -d"/" -f1
|
2017-07-25 19:02:08 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function nvmfcleanup() {
|
2016-07-11 18:06:55 +00:00
|
|
|
sync
|
2018-08-28 19:41:49 +00:00
|
|
|
set +e
|
|
|
|
for i in {1..20}; do
|
2019-07-04 00:59:13 +00:00
|
|
|
modprobe -v -r nvme-$TEST_TRANSPORT
|
2019-09-13 14:40:15 +00:00
|
|
|
if modprobe -v -r nvme-fabrics; then
|
2018-08-28 19:41:49 +00:00
|
|
|
set -e
|
2020-04-10 14:19:34 +00:00
|
|
|
return 0
|
2018-08-28 19:41:49 +00:00
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# So far unable to remove the kernel modules. Try
|
|
|
|
# one more time and let it fail.
|
2019-07-04 00:59:13 +00:00
|
|
|
# Allow the transport module to fail for now. See Jim's comment
|
|
|
|
# about the nvme-tcp module below.
|
|
|
|
modprobe -v -r nvme-$TEST_TRANSPORT || true
|
|
|
|
modprobe -v -r nvme-fabrics
|
2016-06-08 01:47:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function nvmftestinit() {
|
2019-06-03 19:26:47 +00:00
|
|
|
if [ -z $TEST_TRANSPORT ]; then
|
|
|
|
echo "transport not specified - use --transport= to specify"
|
|
|
|
return 1
|
|
|
|
fi
|
2019-05-16 23:50:48 +00:00
|
|
|
if [ "$TEST_MODE" == "iso" ]; then
|
2018-08-14 18:05:15 +00:00
|
|
|
$rootdir/scripts/setup.sh
|
2019-06-03 20:35:33 +00:00
|
|
|
if [ "$TEST_TRANSPORT" == "rdma" ]; then
|
|
|
|
rdma_device_init
|
|
|
|
fi
|
2018-08-14 18:05:15 +00:00
|
|
|
fi
|
2019-07-15 04:42:41 +00:00
|
|
|
|
|
|
|
NVMF_TRANSPORT_OPTS="-t $TEST_TRANSPORT"
|
2019-06-03 20:35:33 +00:00
|
|
|
if [ "$TEST_TRANSPORT" == "rdma" ]; then
|
|
|
|
RDMA_IP_LIST=$(get_available_rdma_ips)
|
|
|
|
NVMF_FIRST_TARGET_IP=$(echo "$RDMA_IP_LIST" | head -n 1)
|
2019-10-23 22:58:47 +00:00
|
|
|
NVMF_SECOND_TARGET_IP=$(echo "$RDMA_IP_LIST" | tail -n +2 | head -n 1)
|
2019-06-03 20:35:33 +00:00
|
|
|
if [ -z $NVMF_FIRST_TARGET_IP ]; then
|
|
|
|
echo "no NIC for nvmf test"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
elif [ "$TEST_TRANSPORT" == "tcp" ]; then
|
|
|
|
NVMF_FIRST_TARGET_IP=127.0.0.1
|
2019-07-15 04:45:56 +00:00
|
|
|
NVMF_TRANSPORT_OPTS="$NVMF_TRANSPORT_OPTS -o"
|
2019-05-13 19:11:00 +00:00
|
|
|
fi
|
2019-07-04 00:51:10 +00:00
|
|
|
|
|
|
|
# currently we run the host/perf test for TCP even on systems without kernel nvme-tcp
|
|
|
|
# support; that's fine since the host/perf test uses the SPDK initiator
|
|
|
|
# maybe later we will enforce modprobe to succeed once we have systems in the test pool
|
|
|
|
# with nvme-tcp kernel support - but until then let this pass so we can still run the
|
|
|
|
# host/perf test with the tcp transport
|
|
|
|
modprobe nvme-$TEST_TRANSPORT || true
|
2019-05-13 19:11:00 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function nvmfappstart() {
|
2019-05-13 19:11:00 +00:00
|
|
|
timing_enter start_nvmf_tgt
|
2020-04-28 15:08:33 +00:00
|
|
|
"${NVMF_APP[@]}" "$@" &
|
2019-05-13 19:11:00 +00:00
|
|
|
nvmfpid=$!
|
2019-08-09 08:46:01 +00:00
|
|
|
trap 'process_shm --id $NVMF_APP_SHM_ID; nvmftestfini; exit 1' SIGINT SIGTERM EXIT
|
2019-05-13 19:11:00 +00:00
|
|
|
waitforlisten $nvmfpid
|
|
|
|
timing_exit start_nvmf_tgt
|
2018-08-14 18:05:15 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function nvmftestfini() {
|
2020-03-19 11:16:38 +00:00
|
|
|
nvmfcleanup || :
|
2019-12-03 20:14:20 +00:00
|
|
|
if [ -n "$nvmfpid" ]; then
|
|
|
|
killprocess $nvmfpid
|
|
|
|
fi
|
2019-05-16 23:50:48 +00:00
|
|
|
if [ "$TEST_MODE" == "iso" ]; then
|
2018-08-14 18:05:15 +00:00
|
|
|
$rootdir/scripts/setup.sh reset
|
2019-06-03 20:35:33 +00:00
|
|
|
if [ "$TEST_TRANSPORT" == "rdma" ]; then
|
|
|
|
rdma_device_init
|
|
|
|
fi
|
2018-08-14 18:05:15 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function rdma_device_init() {
|
2016-06-08 01:47:02 +00:00
|
|
|
load_ib_rdma_modules
|
|
|
|
detect_rdma_nics
|
2016-06-17 19:56:56 +00:00
|
|
|
allocate_nic_ips
|
2016-06-08 01:47:02 +00:00
|
|
|
}
|
2017-07-25 19:02:08 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function revert_soft_roce() {
|
2017-07-25 19:02:08 +00:00
|
|
|
if hash rxe_cfg; then
|
2018-04-10 12:17:30 +00:00
|
|
|
interfaces="$(ip -o link | awk '{print $2}' | cut -d":" -f1)"
|
2017-07-25 19:02:08 +00:00
|
|
|
for interface in $interfaces; do
|
|
|
|
rxe_cfg remove $interface || true
|
|
|
|
done
|
|
|
|
rxe_cfg stop || true
|
|
|
|
fi
|
|
|
|
}
|
2017-12-19 14:01:11 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function check_ip_is_soft_roce() {
|
2017-12-19 14:01:11 +00:00
|
|
|
IP=$1
|
|
|
|
if hash rxe_cfg; then
|
|
|
|
dev=$(ip -4 -o addr show | grep $IP | cut -d" " -f2)
|
2020-02-06 13:13:23 +00:00
|
|
|
if (rxe_cfg status "rxe" | grep -q $dev); then
|
2018-11-01 17:11:42 +00:00
|
|
|
return 0
|
2019-11-20 23:10:20 +00:00
|
|
|
else
|
|
|
|
return 1
|
2017-12-19 14:01:11 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
2018-10-20 16:20:43 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function nvme_connect() {
|
2019-10-24 13:58:04 +00:00
|
|
|
local init_count
|
|
|
|
init_count=$(nvme list | wc -l)
|
2018-10-20 16:20:43 +00:00
|
|
|
|
2019-11-25 11:21:54 +00:00
|
|
|
if ! nvme connect "$@"; then return $?; fi
|
2018-10-20 16:20:43 +00:00
|
|
|
|
|
|
|
for i in $(seq 1 10); do
|
|
|
|
if [ $(nvme list | wc -l) -gt $init_count ]; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
sleep 1s
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
2020-03-20 09:14:31 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function get_nvme_devs() {
|
2020-03-20 09:14:31 +00:00
|
|
|
local dev rest
|
|
|
|
|
|
|
|
nvmes=()
|
|
|
|
while read -r dev rest; do
|
|
|
|
if [[ $dev == /dev/nvme* ]]; then
|
|
|
|
nvmes+=("$dev")
|
|
|
|
fi
|
|
|
|
if [[ $1 == print ]]; then
|
|
|
|
echo "$dev $rest"
|
|
|
|
fi
|
|
|
|
done < <(nvme list)
|
2020-05-07 11:27:06 +00:00
|
|
|
((${#nvmes[@]})) || return 1
|
2020-03-20 09:14:31 +00:00
|
|
|
echo "${#nvmes[@]}" >&2
|
|
|
|
}
|
2020-03-18 17:39:21 +00:00
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
function gen_nvmf_target_json() {
|
2020-03-18 17:39:21 +00:00
|
|
|
local subsystem config=()
|
|
|
|
|
|
|
|
for subsystem in "${@:-1}"; do
|
|
|
|
config+=(
|
|
|
|
"$(
|
2020-05-07 11:27:06 +00:00
|
|
|
cat <<- EOF
|
2020-03-18 17:39:21 +00:00
|
|
|
{
|
|
|
|
"params": {
|
|
|
|
"name": "Nvme$subsystem",
|
|
|
|
"trtype": "$TEST_TRANSPORT",
|
|
|
|
"traddr": "$NVMF_FIRST_TARGET_IP",
|
|
|
|
"adrfam": "ipv4",
|
|
|
|
"trsvcid": "$NVMF_PORT",
|
|
|
|
"subnqn": "nqn.2016-06.io.spdk:cnode$subsystem"
|
|
|
|
},
|
|
|
|
"method": "bdev_nvme_attach_controller"
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
)
|
|
|
|
done
|
2020-05-07 11:27:06 +00:00
|
|
|
jq . <<- JSON
|
2020-03-18 17:39:21 +00:00
|
|
|
{
|
|
|
|
"subsystems": [
|
|
|
|
{
|
|
|
|
"subsystem": "bdev",
|
|
|
|
"config": [
|
2020-05-07 11:27:06 +00:00
|
|
|
$(
|
|
|
|
IFS=","
|
|
|
|
printf '%s\n' "${config[*]}"
|
|
|
|
)
|
2020-03-18 17:39:21 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
JSON
|
|
|
|
}
|