scripts/setup: Unify block name lookup

Change-Id: Icde3b528d37f6c9a2d8a2fd9f3548f3ee75ceff0
Signed-off-by: Michal Berger <michalx.berger@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3890
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
Michal Berger 2020-08-21 12:42:35 +02:00 committed by Tomasz Zawadzki
parent 51b5fa8579
commit 69ae10f785

View File

@ -146,37 +146,31 @@ function linux_hugetlbfs_mounts() {
mount | grep ' type hugetlbfs ' | awk '{ print $3 }' mount | grep ' type hugetlbfs ' | awk '{ print $3 }'
} }
function get_nvme_name_from_bdf() { function get_block_dev_from_bdf() {
local blknames=() local bdf=$1
local block
set +e for block in /sys/block/*; do
nvme_devs=$(lsblk -d --output NAME | grep "^nvme") if [[ $(readlink -f "$block/device") == *"/$bdf/"* ]]; then
set -e echo "${block##*/}"
for dev in $nvme_devs; do return 0
link_name=$(readlink /sys/block/$dev/device/device) || true
if [ -z "$link_name" ]; then
link_name=$(readlink /sys/block/$dev/device)
fi
link_bdf=$(basename "$link_name")
if [ "$link_bdf" = "$1" ]; then
blknames+=($dev)
fi fi
done done
printf '%s\n' "${blknames[@]}"
} }
function get_virtio_names_from_bdf() { function get_mounted_part_dev_from_bdf_block() {
blk_devs=$(lsblk --nodeps --output NAME) local bdf=$1
virtio_names=() local blocks block part
for dev in $blk_devs; do blocks=($(get_block_dev_from_bdf "$bdf"))
if readlink "/sys/block/$dev" | grep -q "$1"; then
virtio_names+=("$dev") for block in "${blocks[@]}"; do
fi for part in "/sys/block/$block/$block"*; do
if [[ $(< /proc/mounts) == *"/dev/${part##*/} "* ]]; then
echo "${part##*/}"
fi
done
done done
eval "$2=( " "${virtio_names[@]}" " )"
} }
function collect_devices() { function collect_devices() {
@ -246,22 +240,13 @@ function configure_linux_pci() {
# NVMe # NVMe
for bdf in ${pci_bus_cache["0x010802"]}; do for bdf in ${pci_bus_cache["0x010802"]}; do
blknames=() blknames=($(get_mounted_part_dev_from_bdf_block "$bdf"))
if ! pci_can_use $bdf; then if ! pci_can_use $bdf; then
pci_dev_echo "$bdf" "Skipping un-whitelisted NVMe controller at $bdf" pci_dev_echo "$bdf" "Skipping un-whitelisted NVMe controller at $bdf"
continue continue
fi fi
mount=false if ((${#blknames[@]} == 0)); then
for blkname in $(get_nvme_name_from_bdf $bdf); do
mountpoints=$(lsblk /dev/$blkname --output MOUNTPOINT -n | wc -w)
if [ "$mountpoints" != "0" ]; then
mount=true
blknames+=($blkname)
fi
done
if ! $mount; then
linux_bind_driver "$bdf" "$driver_name" linux_bind_driver "$bdf" "$driver_name"
else else
for name in "${blknames[@]}"; do for name in "${blknames[@]}"; do
@ -318,14 +303,11 @@ function configure_linux_pci() {
pci_dev_echo "$bdf" "Skipping un-whitelisted Virtio device at $bdf" pci_dev_echo "$bdf" "Skipping un-whitelisted Virtio device at $bdf"
continue continue
fi fi
blknames=() blknames=($(get_mounted_part_dev_from_bdf_block "$bdf"))
get_virtio_names_from_bdf "$bdf" blknames if ((${#blknames[@]} > 0)); then
for blkname in "${blknames[@]}"; do pci_dev_echo "$bdf" "Active mountpoints on ${blknames[*]}, so not binding"
if [ "$(lsblk /dev/$blkname --output MOUNTPOINT -n | wc -w)" != "0" ]; then continue
pci_dev_echo "$bdf" "Active mountpoints on /dev/$blkname, so not binding" fi
continue 2
fi
done
linux_bind_driver "$bdf" "$driver_name" linux_bind_driver "$bdf" "$driver_name"
done done
@ -715,8 +697,7 @@ function status_linux() {
fi fi
device=$(cat /sys/bus/pci/devices/$bdf/device) device=$(cat /sys/bus/pci/devices/$bdf/device)
vendor=$(cat /sys/bus/pci/devices/$bdf/vendor) vendor=$(cat /sys/bus/pci/devices/$bdf/vendor)
blknames=() blknames=($(get_mounted_part_dev_from_bdf_block "$bdf"))
get_virtio_names_from_bdf "$bdf" blknames
echo -e "$bdf\t${vendor#0x}\t${device#0x}\t$node\t\t${driver:--}\t\t" "${blknames[@]}" echo -e "$bdf\t${vendor#0x}\t${device#0x}\t$node\t\t${driver:--}\t\t" "${blknames[@]}"
done done
done done