Skip to content

Commit 92a2ebd

Browse files
authored
Add: list VFs by device address in nicctl.sh (#1160)
Add an option to nicctl to list VFs by PFs PCI address To test ./script/nicctl.sh list <PF's PCIe address>
1 parent 7f6cfb7 commit 92a2ebd

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

script/nicctl.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if [ $# -lt 2 ]; then
1717
echo " create_dcf_vf Create DCF VFs and bind to VFIO"
1818
echo " disable_vf Disable VF"
1919
echo " list all List all NIC devices and the brief"
20+
echo " list <bb:dd:ff.x> List VFs of the specified PF"
2021
exit 0
2122
fi
2223

@@ -112,6 +113,23 @@ create_kvf() {
112113
done
113114
}
114115

116+
list_vf() {
117+
pci_device_path="/sys/bus/pci/devices/$1/"
118+
if [ ! -d "$pci_device_path" ]; then
119+
echo "PCI device $1 does not exist."
120+
exit 1
121+
fi
122+
vf_names=$(find "$pci_device_path" -name "virtfn*" -exec basename {} \; | sort)
123+
if [ -z "$vf_names" ]; then
124+
echo "No VFs found for $1"
125+
return
126+
fi
127+
for vf in $vf_names; do
128+
vfport=$(basename "$(readlink "$pci_device_path/$vf")")
129+
printf "%s\n" "$vfport"
130+
done
131+
}
132+
115133
list() {
116134
printf "%-4s\t%-12s\t%-12s\t%-4s\t%-6s\t%-10s\n" "ID" "PCI BDF" "Driver" "NUMA" "IOMMU" "IF Name"
117135

@@ -149,8 +167,13 @@ if [ -z "$cmd" ]; then
149167
fi
150168

151169
if [ "$cmd" == "list" ]; then
152-
list
153-
exit 0
170+
if [ "$2" == "all" ]; then
171+
list
172+
exit 0
173+
else
174+
list_vf "$2"
175+
exit 0
176+
fi
154177
fi
155178

156179
bdf=$2

0 commit comments

Comments
 (0)