2020-03-04 13:28:36 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-11-02 15:49:40 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
# Copyright (C) 2020 Intel Corporation
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
2020-03-04 13:28:36 +00:00
|
|
|
testdir=$(readlink -f $(dirname $0))
|
2020-06-08 11:42:52 +00:00
|
|
|
rootdir=$(readlink -f $testdir/../../..)
|
2023-01-27 15:16:54 +00:00
|
|
|
source "$testdir/common.sh"
|
2020-03-04 13:28:36 +00:00
|
|
|
|
|
|
|
$rootdir/scripts/setup.sh reset
|
2023-01-27 15:16:54 +00:00
|
|
|
scan_nvme_ctrls
|
2020-03-04 13:28:36 +00:00
|
|
|
|
2021-11-25 01:40:59 +00:00
|
|
|
# Find bdf that supports Namespace Management
|
2023-01-27 15:16:54 +00:00
|
|
|
for ctrl in "${!ctrls[@]}"; do
|
2020-06-09 09:41:16 +00:00
|
|
|
# Check Optional Admin Command Support for Namespace Management
|
2023-01-27 15:16:54 +00:00
|
|
|
(($(get_nvme_ctrl_feature "$ctrl" oacs) & 0x8)) && nvme_name=$ctrl && break
|
2020-03-04 13:28:36 +00:00
|
|
|
done
|
|
|
|
|
2023-01-27 15:16:54 +00:00
|
|
|
if [[ -z $nvme_name ]]; then
|
2021-11-25 01:40:59 +00:00
|
|
|
echo "No NVMe device supporting Namespace management found"
|
2020-03-04 13:28:36 +00:00
|
|
|
$rootdir/scripts/setup.sh
|
2020-06-08 15:16:41 +00:00
|
|
|
exit 1
|
2020-03-04 13:28:36 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
nvme_dev=/dev/${nvme_name}
|
2023-01-27 15:16:54 +00:00
|
|
|
bdf=${bdfs["$nvme_name"]}
|
|
|
|
nsids=($(get_nvme_nss "$nvme_name"))
|
2020-03-04 13:28:36 +00:00
|
|
|
|
|
|
|
# Detect supported features and configuration
|
2023-01-27 15:16:54 +00:00
|
|
|
oaes=$(get_nvme_ctrl_feature "$nvme_name" oaes)
|
2020-04-17 12:30:16 +00:00
|
|
|
aer_ns_change=$((oaes & 0x100))
|
2023-01-27 15:16:54 +00:00
|
|
|
cntlid=$(get_nvme_ctrl_feature "$nvme_name")
|
2020-04-17 12:30:16 +00:00
|
|
|
|
2020-06-09 09:48:37 +00:00
|
|
|
function reset_nvme_if_aer_unsupported() {
|
|
|
|
if [[ "$aer_ns_change" -eq "0" ]]; then
|
|
|
|
sleep 1
|
|
|
|
$NVME_CMD reset "$1" || true
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-12-10 22:54:30 +00:00
|
|
|
function remove_all_namespaces() {
|
|
|
|
info_print "delete all namespaces"
|
|
|
|
# Cant globally detach all namespaces ... must do so one by one
|
2023-01-27 15:16:54 +00:00
|
|
|
for nsid in "${nsids[@]}"; do
|
|
|
|
info_print "removing nsid=${nsid}"
|
|
|
|
$NVME_CMD detach-ns ${nvme_dev} -n ${nsid} -c ${cntlid} || true
|
|
|
|
$NVME_CMD delete-ns ${nvme_dev} -n ${nsid} || true
|
2021-12-10 22:54:30 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-03-04 13:28:36 +00:00
|
|
|
function clean_up() {
|
2023-01-27 15:16:54 +00:00
|
|
|
"$rootdir/scripts/setup.sh" reset
|
|
|
|
remove_all_namespaces
|
2020-03-04 13:28:36 +00:00
|
|
|
|
|
|
|
echo "Restoring $nvme_dev..."
|
2023-01-27 15:16:54 +00:00
|
|
|
for nsid in "${nsids[@]}"; do
|
|
|
|
ncap=$(get_nvme_ns_feature "$nvme_name" "$nsid" ncap)
|
|
|
|
nsze=$(get_nvme_ns_feature "$nvme_name" "$nsid" nsze)
|
|
|
|
lbaf=$(get_active_lbaf "$nvme_name" "$nsid")
|
|
|
|
$NVME_CMD create-ns ${nvme_dev} -s ${nsze} -c ${ncap} -f ${lbaf}
|
|
|
|
$NVME_CMD attach-ns ${nvme_dev} -n ${nsid} -c ${cntlid}
|
|
|
|
$NVME_CMD reset ${nvme_dev}
|
|
|
|
done
|
2020-03-04 13:28:36 +00:00
|
|
|
|
|
|
|
$rootdir/scripts/setup.sh
|
|
|
|
}
|
|
|
|
|
|
|
|
function info_print() {
|
|
|
|
echo "---"
|
|
|
|
echo "$@"
|
|
|
|
echo "---"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Prepare controller
|
2021-12-10 22:54:30 +00:00
|
|
|
remove_all_namespaces
|
2020-03-04 13:28:36 +00:00
|
|
|
|
2020-06-09 09:48:37 +00:00
|
|
|
reset_nvme_if_aer_unsupported ${nvme_dev}
|
2020-03-04 13:28:36 +00:00
|
|
|
sleep 1
|
|
|
|
|
2020-11-25 20:31:42 +00:00
|
|
|
PCI_ALLOWED="${bdf}" $rootdir/scripts/setup.sh
|
2020-03-04 13:28:36 +00:00
|
|
|
|
2020-05-11 21:15:03 +00:00
|
|
|
$SPDK_BIN_DIR/spdk_tgt -m 0x3 &
|
2020-03-04 13:28:36 +00:00
|
|
|
spdk_tgt_pid=$!
|
|
|
|
trap 'kill -9 ${spdk_tgt_pid}; clean_up; exit 1' SIGINT SIGTERM EXIT
|
|
|
|
|
|
|
|
waitforlisten $spdk_tgt_pid
|
|
|
|
|
|
|
|
$rpc_py bdev_nvme_attach_controller -b Nvme0 -t PCIe -a ${bdf}
|
|
|
|
$rpc_py bdev_nvme_cuse_register -n Nvme0
|
|
|
|
|
2021-12-10 22:54:30 +00:00
|
|
|
ctrlr="/dev/spdk/nvme0"
|
|
|
|
|
2020-03-04 13:28:36 +00:00
|
|
|
sleep 1
|
2021-12-10 22:54:30 +00:00
|
|
|
[[ -c $ctrlr ]]
|
2020-03-04 13:28:36 +00:00
|
|
|
|
2021-12-10 22:54:30 +00:00
|
|
|
for dev in "${ctrlr}"n*; do
|
2020-03-04 13:28:36 +00:00
|
|
|
[[ ! -c ${dev} ]]
|
|
|
|
done
|
|
|
|
sleep 1
|
|
|
|
|
2023-01-27 15:16:54 +00:00
|
|
|
for nsid in "${nsids[@]}"; do
|
2021-12-10 22:54:30 +00:00
|
|
|
info_print "create ns: nsze=10000 ncap=10000 flbias=0"
|
2023-01-27 15:16:54 +00:00
|
|
|
$NVME_CMD create-ns ${ctrlr} -s 10000 -c 10000 -f 0
|
|
|
|
info_print "attach ns: nsid=${nsid} controller=${cntlid}"
|
|
|
|
$NVME_CMD attach-ns ${ctrlr} -n ${nsid} -c ${cntlid}
|
2021-12-10 22:54:30 +00:00
|
|
|
reset_nvme_if_aer_unsupported ${ctrlr}
|
|
|
|
sleep 1
|
|
|
|
[[ -c "${ctrlr}n${nsid}" ]]
|
2023-01-27 15:16:54 +00:00
|
|
|
info_print "detach ns: nsid=${nsid} controller=${cntlid}"
|
|
|
|
$NVME_CMD detach-ns ${ctrlr} -n ${nsid} -c ${cntlid}
|
|
|
|
info_print "delete ns: nsid=${nsid}"
|
|
|
|
$NVME_CMD delete-ns ${ctrlr} -n ${nsid}
|
2021-12-10 22:54:30 +00:00
|
|
|
reset_nvme_if_aer_unsupported ${ctrlr}
|
|
|
|
sleep 1
|
2023-01-27 15:16:54 +00:00
|
|
|
[[ ! -c "${ctrlr}n${nsid}" ]]
|
2021-12-10 22:54:30 +00:00
|
|
|
done
|
2020-03-04 13:28:36 +00:00
|
|
|
|
|
|
|
# Here we should not have any cuse devices
|
2021-12-10 22:54:30 +00:00
|
|
|
for dev in "${ctrlr}"n*; do
|
2020-03-04 13:28:36 +00:00
|
|
|
[[ ! -c ${dev} ]]
|
|
|
|
done
|
|
|
|
|
|
|
|
$rpc_py bdev_nvme_detach_controller Nvme0
|
|
|
|
|
|
|
|
sleep 1
|
2021-12-10 22:54:30 +00:00
|
|
|
[[ ! -c ${ctrlr} ]]
|
2020-03-04 13:28:36 +00:00
|
|
|
|
|
|
|
trap - SIGINT SIGTERM EXIT
|
|
|
|
killprocess $spdk_tgt_pid
|
|
|
|
clean_up
|