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/../../..)
|
2020-03-04 13:28:36 +00:00
|
|
|
source $rootdir/scripts/common.sh
|
|
|
|
source $rootdir/test/common/autotest_common.sh
|
|
|
|
|
|
|
|
NVME_CMD="/usr/local/src/nvme-cli/nvme"
|
|
|
|
|
|
|
|
rpc_py=$rootdir/scripts/rpc.py
|
|
|
|
|
|
|
|
$rootdir/scripts/setup.sh
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
bdfs=$(get_nvme_bdfs)
|
|
|
|
|
|
|
|
$rootdir/scripts/setup.sh reset
|
|
|
|
|
2021-11-25 01:40:59 +00:00
|
|
|
# Find bdf that supports Namespace Management
|
2020-03-04 13:28:36 +00:00
|
|
|
for bdf in $bdfs; do
|
2020-06-08 14:48:03 +00:00
|
|
|
nvme_name=$(get_nvme_ctrlr_from_bdf ${bdf})
|
|
|
|
if [[ -z "$nvme_name" ]]; then
|
2020-03-04 13:28:36 +00:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2020-06-09 09:41:16 +00:00
|
|
|
# Check Optional Admin Command Support for Namespace Management
|
2020-03-04 13:28:36 +00:00
|
|
|
oacs=$($NVME_CMD id-ctrl /dev/${nvme_name} | grep oacs | cut -d: -f2)
|
|
|
|
oacs_ns_manage=$((oacs & 0x8))
|
|
|
|
|
2020-04-17 12:30:16 +00:00
|
|
|
if [[ "$oacs_ns_manage" -ne 0 ]]; then
|
2020-03-04 13:28:36 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-04-17 12:30:16 +00:00
|
|
|
if [[ "${nvme_name}" == "" ]] || [[ "$oacs_ns_manage" -eq 0 ]]; 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}
|
|
|
|
|
|
|
|
# Detect supported features and configuration
|
2020-04-17 12:30:16 +00:00
|
|
|
oaes=$($NVME_CMD id-ctrl ${nvme_dev} | grep oaes | cut -d: -f2)
|
|
|
|
aer_ns_change=$((oaes & 0x100))
|
|
|
|
|
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"
|
|
|
|
active_nsids=$($NVME_CMD list-ns ${nvme_dev} | cut -f2 -d:)
|
|
|
|
# Cant globally detach all namespaces ... must do so one by one
|
|
|
|
for n in ${active_nsids}; do
|
|
|
|
info_print "removing nsid=${n}"
|
|
|
|
$NVME_CMD detach-ns ${nvme_dev} -n ${n} -c 0 || true
|
|
|
|
$NVME_CMD delete-ns ${nvme_dev} -n ${n} || true
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-03-04 13:28:36 +00:00
|
|
|
function clean_up() {
|
|
|
|
$rootdir/scripts/setup.sh reset
|
|
|
|
|
2020-06-09 09:41:16 +00:00
|
|
|
# This assumes every NVMe controller contains single namespace,
|
2020-06-23 06:37:57 +00:00
|
|
|
# encompassing Total NVM Capacity and formatted as 512 block size.
|
|
|
|
# 512 block size is needed for test/vhost/vhost_boot.sh to
|
2022-11-02 15:09:36 +00:00
|
|
|
# successfully run.
|
2020-06-09 09:41:16 +00:00
|
|
|
|
|
|
|
tnvmcap=$($NVME_CMD id-ctrl ${nvme_dev} | grep tnvmcap | cut -d: -f2)
|
2020-06-23 06:37:57 +00:00
|
|
|
blksize=512
|
2020-06-09 09:41:16 +00:00
|
|
|
|
|
|
|
size=$((tnvmcap / blksize))
|
2020-03-04 13:28:36 +00:00
|
|
|
|
|
|
|
echo "Restoring $nvme_dev..."
|
2021-12-10 22:54:30 +00:00
|
|
|
remove_all_namespaces
|
|
|
|
nsid=$($NVME_CMD create-ns ${nvme_dev} -s ${size} -c ${size} -b ${blksize} | grep -o 'nsid:[0-9].*' | cut -f2 -d:)
|
|
|
|
$NVME_CMD attach-ns ${nvme_dev} -n ${nsid} -c 0
|
2020-03-04 13:28:36 +00:00
|
|
|
$NVME_CMD reset ${nvme_dev}
|
|
|
|
|
|
|
|
$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
|
2021-12-10 22:54:30 +00:00
|
|
|
nsids=()
|
2020-03-04 13:28:36 +00:00
|
|
|
|
2021-12-10 22:54:30 +00:00
|
|
|
for i in {1..2}; do
|
|
|
|
info_print "create ns: nsze=10000 ncap=10000 flbias=0"
|
|
|
|
nsid=$($NVME_CMD create-ns ${ctrlr} -s 10000 -c 10000 -f 0 | grep -o 'nsid:[0-9].*' | cut -f2 -d:)
|
|
|
|
nsids+=(${nsid})
|
|
|
|
info_print "attach ns: nsid=${nsid} controller=0"
|
|
|
|
$NVME_CMD attach-ns ${ctrlr} -n ${nsid} -c 0
|
2020-03-04 13:28:36 +00:00
|
|
|
|
2021-12-10 22:54:30 +00:00
|
|
|
reset_nvme_if_aer_unsupported ${ctrlr}
|
|
|
|
sleep 1
|
2020-03-04 13:28:36 +00:00
|
|
|
|
2021-12-10 22:54:30 +00:00
|
|
|
[[ -c "${ctrlr}n${nsid}" ]]
|
|
|
|
done
|
2020-03-04 13:28:36 +00:00
|
|
|
|
2021-12-10 22:54:30 +00:00
|
|
|
for n in "${nsids[@]}"; do
|
|
|
|
info_print "detach ns: nsid=${n} controller=0"
|
|
|
|
$NVME_CMD detach-ns ${ctrlr} -n ${n} -c 0 || true
|
2020-03-04 13:28:36 +00:00
|
|
|
|
2021-12-10 22:54:30 +00:00
|
|
|
info_print "delete ns: nsid=${n}"
|
|
|
|
$NVME_CMD delete-ns ${ctrlr} -n ${n} || true
|
2020-03-04 13:28:36 +00:00
|
|
|
|
2021-12-10 22:54:30 +00:00
|
|
|
reset_nvme_if_aer_unsupported ${ctrlr}
|
|
|
|
sleep 1
|
2020-03-04 13:28:36 +00:00
|
|
|
|
2021-12-10 22:54:30 +00:00
|
|
|
[[ ! -c "${ctrlr}n${n}" ]]
|
|
|
|
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
|