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