From 35babaded190028513ef7fcc7de63d47c837b7ef Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Tue, 23 Jun 2020 10:25:15 +0200 Subject: [PATCH] scripts/common: Use separate function for nvme driver lookup Check if given pci address is bound to nvme driver via a separate function - this makes the task of getting list of the nvme devices that can be used in tests a bit easier since we don't have to relay on, e.g., gen_nvme.sh where the extra step to get said devices is to parse the actual config. Change-Id: I1f15f08a3678c0c41b051348af259e225356c340 Signed-off-by: Michal Berger Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3014 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki --- scripts/common.sh | 25 +++++++++++++++++++++++++ scripts/gen_nvme.sh | 12 +----------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index c6b9a53f8..a70cfba0d 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -212,3 +212,28 @@ function iter_pci_class_code() { fi done } + +function nvme_in_userspace() { + # Check used drivers. If it's not vfio-pci or uio-pci-generic + # then most likely PCI_WHITELIST option was used for setup.sh + # and we do not want to use that disk. + + local bdf bdfs + local nvmes + + if [[ -n ${pci_bus_cache["0x010802"]} ]]; then + nvmes=(${pci_bus_cache["0x010802"]}) + else + nvmes=($(iter_pci_class_code 01 08 02)) + fi + + for bdf in "${nvmes[@]}"; do + if [[ -e /sys/bus/pci/drivers/nvme/$bdf ]] \ + || [[ $(uname -s) == FreeBSD && $(pciconf -l "pci$bdf") == nvme* ]]; then + continue + fi + bdfs+=("$bdf") + done + ((${#bdfs[@]})) || return 1 + printf '%s\n' "${bdfs[@]}" +} diff --git a/scripts/gen_nvme.sh b/scripts/gen_nvme.sh index 6e1f5b517..31817b271 100755 --- a/scripts/gen_nvme.sh +++ b/scripts/gen_nvme.sh @@ -34,17 +34,7 @@ function create_json_config() { echo '}' } -bdfs=() -# Check used drivers. If it's not vfio-pci or uio-pci-generic -# then most likely PCI_WHITELIST option was used for setup.sh -# and we do not want to use that disk. -for bdf in $(iter_pci_class_code 01 08 02); do - if [[ -e /sys/bus/pci/drivers/nvme/$bdf ]] \ - || [[ $(uname -s) == FreeBSD && $(pciconf -l "pci$bdf") == nvme* ]]; then - continue - fi - bdfs+=("$bdf") -done +bdfs=($(nvme_in_userspace)) if [ "$1" = "--json" ]; then create_json_config