Skip to content

Commit

Permalink
Replace govdpa lib calls with netlink
Browse files Browse the repository at this point in the history
This required to support additional configuration
options and to remove need to mount
/dev/ folder to the container (govdpa requires it)

Signed-off-by: Yury Kulazhenkov <[email protected]>
  • Loading branch information
ykulazhenkov committed Feb 22, 2024
1 parent 2fc7ca6 commit 535775a
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 294 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/google/go-cmp v0.6.0
github.com/hashicorp/go-retryablehttp v0.7.0
github.com/jaypipes/ghw v0.9.0
github.com/k8snetworkplumbingwg/govdpa v0.1.4
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0
github.com/k8snetworkplumbingwg/sriov-network-device-plugin v0.0.0-20221127172732-a5a7395122e3
github.com/onsi/ginkgo/v2 v2.11.0
Expand Down Expand Up @@ -92,6 +91,7 @@ require (
github.com/jaypipes/pcidb v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/k8snetworkplumbingwg/govdpa v0.1.4 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
Expand Down
15 changes: 15 additions & 0 deletions pkg/helper/mock/mock_helper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pkg/host/internal/kernel/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,25 @@ func (k *kernel) HasDriver(pciAddr string) (bool, string) {
return false, ""
}

// GetDriverByBusAndDevice returns driver for the device or error.
// returns "", nil if the device has no driver.
// bus - the bus path in the sysfs, e.g. "pci" or "vdpa"
// device - the name of the device on the bus, e.g. 0000:85:1e.5 for PCI or vpda1 for VDPA
func (k *kernel) GetDriverByBusAndDevice(bus, device string) (string, error) {
log.Log.V(2).Info("GetDriverByBusAndDevice(): get driver for device", "bus", bus, "device", device)
driver, err := getDriverByBusAndDevice(bus, device)
if err != nil {
log.Log.V(2).Info("GetDriverByBusAndDevice(): can't read device driver for device", "bus", bus, "device", device)
return "", err
}
if driver == "" {
log.Log.V(2).Info("GetDriverByBusAndDevice(): device has no driver", "bus", bus, "device", device)
} else {
log.Log.V(2).Info("GetDriverByBusAndDevice(): device driver", "bus", bus, "device", device, "driver", driver)
}
return driver, nil
}

func (k *kernel) TryEnableRdma() (bool, error) {
log.Log.V(2).Info("tryEnableRdma()")
chrootDefinition := utils.GetChrootExtension()
Expand Down
22 changes: 22 additions & 0 deletions pkg/host/internal/kernel/kernel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,27 @@ var _ = Describe("Kernel", func() {
helpers.GinkgoAssertFileContentsEquals("/sys/bus/pci/drivers/vfio-pci/bind", "0000:d8:00.0")
})
})
Context("GetDriverByBusAndDevice", func() {
It("device has driver", func() {
helpers.GinkgoConfigureFakeFS(&fakefilesystem.FS{
Dirs: []string{
"/sys/bus/vdpa/devices/vdpa:0000:d8:00.3"},
Symlinks: map[string]string{
"/sys/bus/vdpa/devices/vdpa:0000:d8:00.3/driver": "../../../../../bus/vdpa/drivers/vhost_vdpa"},
})
driver, err := k.GetDriverByBusAndDevice(consts.BusVdpa, "vdpa:0000:d8:00.3")
Expect(err).NotTo(HaveOccurred())
Expect(driver).To(Equal("vhost_vdpa"))
})
It("device has no driver", func() {
helpers.GinkgoConfigureFakeFS(&fakefilesystem.FS{
Dirs: []string{
"/sys/bus/vdpa/devices/vdpa:0000:d8:00.3"},
})
driver, err := k.GetDriverByBusAndDevice(consts.BusVdpa, "vdpa:0000:d8:00.3")
Expect(err).NotTo(HaveOccurred())
Expect(driver).To(BeEmpty())
})
})
})
})
40 changes: 0 additions & 40 deletions pkg/host/internal/lib/govdpa/govdpa.go

This file was deleted.

187 changes: 0 additions & 187 deletions pkg/host/internal/lib/govdpa/mock/mock_govdpa.go

This file was deleted.

43 changes: 43 additions & 0 deletions pkg/host/internal/lib/netlink/mock/mock_netlink.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 535775a

Please sign in to comment.