Skip to content

Commit

Permalink
Fix can't get pfname for virtio pci path
Browse files Browse the repository at this point in the history
Fixed issue with virtio driver by adding a conditional check for the virtio path under the PCI address,
preventing errors when the pf name cannot be found. This ensures successful acquisition of vf resources.

Fixes #507

Signed-off-by: JasinlikeEatingOrange <jasin_smith@outlook.com>
  • Loading branch information
huangyunpeng committed Nov 30, 2023
1 parent 30652a2 commit c220256
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ func GetPfName(pciAddr string) (string, error) {
}

path := filepath.Join(sysBusPci, pciAddr, "physfn", "net")
virtIOpath := filepath.Join(sysBusPci, pciAddr, "physfn")
dir, err := os.ReadDir(virtIOpath)
if err != nil {
return "", fmt.Errorf("can't open path %s: %w", virtIOpath, err)
}
for _, file := range dir {
if strings.Contains(file.Name(), "virtio") {
path = filepath.Join(virtIOpath, file.Name(), "net")
break
}
}
files, err := os.ReadDir(path)
if err != nil {
if os.IsNotExist(err) {
Expand Down
12 changes: 12 additions & 0 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,18 @@ var _ = Describe("In the utils package", func() {
},
"0000:01:10.0", "", true,
),
Entry("pf net is virtio path",
&FakeFilesystem{
Dirs: []string{
"sys/bus/pci/devices/0000:01:00.0/",
"sys/bus/pci/devices/0000:01:10.0/",
"sys/bus/pci/devices/0000:01:00.0/virtio1/net/fakePF"},
Symlinks: map[string]string{
"sys/bus/pci/devices/0000:01:10.0/physfn": "../0000:01:00.0",
},
},
"0000:01:10.0", "fakePF", false,
),
)

DescribeTable("getting PF names switchdev",
Expand Down

0 comments on commit c220256

Please sign in to comment.