Skip to content

Commit d32c7ce

Browse files
committed
CA-412146 Filter out VF when scan
SR-IOV (Single Root I/O Virtualization) is a technology that allows a single physical PCI Express (PCIe) device, such as a network adapter, to be shared efficiently among multiple virtual machines (VMs) or containers. It achieves this by creating Virtual Functions (VFs) that act as lightweight PCIe functions, each assigned to a VM, while the Physical Function (PF) remains responsible for managing the device. Add check in Sysfs.is_physical - check if there is "physfn" in the device dir to filter out VF, then XAPI will not create PIF object for VF during scan. Signed-off-by: Changlei Li <[email protected]>
1 parent 743565c commit d32c7ce

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

ocaml/networkd/lib/network_utils.ml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,29 @@ module Sysfs = struct
181181
close_out outchan ;
182182
raise (Network_error (Write_error file))
183183

184-
let is_physical name =
184+
exception Unable_to_read_driver_link
185+
186+
let is_vif name =
187+
let devpath = getpath name "device" in
185188
try
186-
let devpath = getpath name "device" in
187189
let driver_link = Unix.readlink (devpath ^ "/driver") in
188190
(* filter out symlinks under device/driver which look like
189191
/../../../devices/xen-backend/vif- *)
190-
not
191-
(List.mem "xen-backend"
192-
(Astring.String.cuts ~empty:false ~sep:"/" driver_link)
193-
)
192+
List.mem "xen-backend"
193+
(Astring.String.cuts ~empty:false ~sep:"/" driver_link)
194+
with _ -> raise Unable_to_read_driver_link
195+
196+
let is_vf name =
197+
let devpath = getpath name "device" in
198+
try
199+
ignore @@ Unix.readlink (devpath ^ "/physfn") ;
200+
true
194201
with _ -> false
195202

203+
let is_physical name =
204+
try not (is_vif name || is_vf name)
205+
with Unable_to_read_driver_link -> false
206+
196207
(* device types are defined in linux/if_arp.h *)
197208
let is_ether_device name =
198209
match int_of_string (read_one_line (getpath name "type")) with
@@ -1547,7 +1558,7 @@ module Ovs = struct
15471558
let vif_arg =
15481559
let existing_vifs =
15491560
List.filter
1550-
(fun iface -> not (Sysfs.is_physical iface))
1561+
(fun iface -> try Sysfs.is_vif iface with _ -> false)
15511562
(bridge_to_interfaces name)
15521563
in
15531564
let ifaces_with_type =

0 commit comments

Comments
 (0)