File: lib.sh

package info (click to toggle)
linux 6.19.4-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,759,672 kB
  • sloc: ansic: 27,007,359; asm: 273,393; sh: 151,330; python: 81,278; makefile: 58,557; perl: 34,311; xml: 21,064; cpp: 5,986; yacc: 4,841; lex: 2,901; awk: 1,707; sed: 30; ruby: 25
file content (42 lines) | stat: -rwxr-xr-x 964 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# SPDX-License-Identifier: GPL-2.0-or-later

readonly DEVICES_DIR="${TMPDIR:-/tmp}/vfio-selftests-devices"

function write_to() {
	# Unfortunately set -x does not show redirects so use echo to manually
	# tell the user what commands are being run.
	echo "+ echo \"${2}\" > ${1}"
	echo "${2}" > ${1}
}

function get_driver() {
	if [ -L /sys/bus/pci/devices/${1}/driver ]; then
		basename $(readlink -m /sys/bus/pci/devices/${1}/driver)
	fi
}

function bind() {
	write_to /sys/bus/pci/drivers/${2}/bind ${1}
}

function unbind() {
	write_to /sys/bus/pci/drivers/${2}/unbind ${1}
}

function set_sriov_numvfs() {
	write_to /sys/bus/pci/devices/${1}/sriov_numvfs ${2}
}

function get_sriov_numvfs() {
	if [ -f /sys/bus/pci/devices/${1}/sriov_numvfs ]; then
		cat /sys/bus/pci/devices/${1}/sriov_numvfs
	fi
}

function set_driver_override() {
	write_to /sys/bus/pci/devices/${1}/driver_override ${2}
}

function clear_driver_override() {
	set_driver_override ${1} ""
}