Commit 2e497261 authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

setup/interactive: Rewrite bdevices()



This option is used to bind a device to a given driver. It was a bit
hard to follow what argument needed to be passed there so split the
dev and driver selection into separate routines. Add small wrapper
function to print some extra driver info for selected device.

Change-Id: Ia870d8e4314c02f364c2264bf3266cd0077e7e9a
Signed-off-by: default avatarMichal Berger <michal.berger@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22316


Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
parent f01d428b
Loading
Loading
Loading
Loading
+35 −12
Original line number Diff line number Diff line
@@ -241,31 +241,54 @@ odevices() {
bdevices() {
	[[ $os == Linux ]] || return 0

	local bdfd bdf driver
	local bdf driver

	gdevices

	while read -rp "(BDF->driver)> " bdfd; do
		bdfd=${bdfd,,}
		if [[ -z $bdfd ]]; then
	while read -rp "(BDF)> " bdf; do
		bdf=${bdf,,}
		if [[ -z $bdf ]]; then
			return
		fi

		bdf=${bdfd/->*/} driver=${bdfd/*->/}
		[[ -n ${dev_ref["$bdf"]} ]] || continue

		pdriver "$bdf"

		if [[ $driver == "${drivers_d["$bdf"]}" ]]; then
		while read -rp "Select driver ($bdf)> " driver; do
			driver=${driver,,}
			if [[ -z $driver ]]; then
				continue 2
			fi
			if [[ $driver == "${pci_bus_driver["$bdf"]}" ]]; then
				echo "$bdf already bound to $driver"
				continue
			fi
			break
		done

		# Try to be nice and silently attempt to load the driver just in case
		modprobe -q "$driver" || true

		if [[ -n ${dev_ref["$bdf"]} && -n $driver ]]; then
			if yn "$bdf currently bound to ${drivers_d["$bdf"]:-none}. Bind to $driver?"; then
		if yn "$bdf currently bound to ${pci_bus_driver["$bdf"]:-none}. Bind to $driver?"; then
			linux_bind_driver "$bdf" "$driver"
			fi
			return
		fi
	done
}

pdriver() {
	local bdf=$1

	cat <<- DRIVER

		$bdf:
		  main driver: $(collect_driver "$bdf")
		  current driver: ${pci_bus_driver["$bdf"]:-none}

	DRIVER
}

status() {
	local _os=${os,,}