test/cuse: revert NVMe namespaces to default state
If for any reason the cuse tests do not revert state of NVMe namespaces to the original state, the test machines would be stuck in until manual intervention. Assumed default state is single namespace, encompassing available space formatted as 4k block size. This patch adds nvme_namespace_revert(), which searches for NVMe devices that support Namespace Managment and have some space unallocated. When such device is found, all existing namespaces are removed and single one created. Fix #1435 Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Change-Id: Ifc3b04b3f166bf450b884674fa6a482e2fbc4c29 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2829 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Karol Latecki <karol.latecki@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
d5eb583584
commit
4c21ef3645
@ -110,6 +110,9 @@ if [ $(uname -s) = Linux ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# Revert NVMe namespaces to default state
|
||||
nvme_namespace_revert
|
||||
|
||||
# Delete all leftover lvols and gpt partitions
|
||||
# Matches both /dev/nvmeXnY on Linux and /dev/nvmeXnsY on BSD
|
||||
# Filter out nvme with partitions - the "p*" suffix
|
||||
|
@ -1212,6 +1212,48 @@ function get_first_nvme_bdf() {
|
||||
head -1 <<< "$(get_nvme_bdfs)"
|
||||
}
|
||||
|
||||
function nvme_namespace_revert() {
|
||||
$rootdir/scripts/setup.sh
|
||||
sleep 1
|
||||
bdfs=$(get_nvme_bdfs)
|
||||
|
||||
$rootdir/scripts/setup.sh reset
|
||||
sleep 1
|
||||
|
||||
for bdf in $bdfs; do
|
||||
nvme_ctrlr=/dev/$(get_nvme_ctrlr_from_bdf ${bdf})
|
||||
if [[ -z "$nvme_ctrlr" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check Optional Admin Command Support for Namespace Management
|
||||
oacs=$(nvme id-ctrl ${nvme_ctrlr} | grep oacs | cut -d: -f2)
|
||||
oacs_ns_manage=$((oacs & 0x8))
|
||||
|
||||
if [[ "$oacs_ns_manage" -ne 0 ]]; then
|
||||
# This assumes every NVMe controller contains single namespace,
|
||||
# encompassing Total NVM Capacity and formatted as 4k block size.
|
||||
|
||||
unvmcap=$(nvme id-ctrl ${nvme_ctrlr} | grep unvmcap | cut -d: -f2)
|
||||
if [[ "$unvmcap" -eq 0 ]]; then
|
||||
# All available space already used
|
||||
continue
|
||||
fi
|
||||
tnvmcap=$(nvme id-ctrl ${nvme_ctrlr} | grep tnvmcap | cut -d: -f2)
|
||||
blksize=4096
|
||||
|
||||
size=$((tnvmcap / blksize))
|
||||
|
||||
nvme detach-ns ${nvme_ctrlr} -n 0xffffffff -c 0 || true
|
||||
nvme delete-ns ${nvme_ctrlr} -n 0xffffffff || true
|
||||
nvme create-ns ${nvme_ctrlr} -s ${size} -c ${size} -b ${blksize}
|
||||
nvme attach-ns ${nvme_ctrlr} -n 1 -c 0
|
||||
nvme reset ${nvme_ctrlr}
|
||||
waitforblk "${nvme_ctrlr}n1"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Define temp storage for all the tests. Look for 2GB at minimum
|
||||
set_test_storage "${TEST_MIN_STORAGE_SIZE:-$((1 << 31))}"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user