Skip to content

Commit

Permalink
update host package
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Sch <[email protected]>
  • Loading branch information
SchSeba committed Dec 17, 2023
1 parent d10f2d3 commit d4e9591
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 131 deletions.
5 changes: 4 additions & 1 deletion pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,18 @@ func (dn *Daemon) Run(stopCh <-chan struct{}, exitCh <-chan error) error {
}

if !vars.UsingSystemdMode {
log.Log.V(0).Info("Run(): daemon running in systemd mode")
log.Log.V(0).Info("Run(): daemon running in daemon mode")
dn.HostHelpers.TryEnableRdma()
dn.HostHelpers.TryEnableTun()
dn.HostHelpers.TryEnableVhostNet()
err := systemd.CleanSriovFilesFromHost(vars.ClusterType == consts.ClusterTypeOpenshift)
if err != nil {
log.Log.Error(err, "failed to remove all the systemd sriov files")
}
} else {
log.Log.V(0).Info("Run(): daemon running in systemd mode")
}

// Only watch own SriovNetworkNodeState CR
defer utilruntime.HandleCrash()
defer dn.workqueue.ShutDown()
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/platforms"
"os"
"path/filepath"
"time"
Expand All @@ -19,6 +18,7 @@ import (
snclientset "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/client/clientset/versioned"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/platforms"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vars"
)

Expand Down
12 changes: 6 additions & 6 deletions pkg/host/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// Unbind unbind driver for one device
func (h *HostManager) Unbind(pciAddr string) error {
func (h *hostManager) Unbind(pciAddr string) error {
log.Log.V(2).Info("Unbind(): unbind device driver for device", "device", pciAddr)
yes, driver := h.HasDriver(pciAddr)
if !yes {
Expand All @@ -33,7 +33,7 @@ func (h *HostManager) Unbind(pciAddr string) error {

// BindDpdkDriver bind dpdk driver for one device
// Bind the device given by "pciAddr" to the driver "driver"
func (h *HostManager) BindDpdkDriver(pciAddr, driver string) error {
func (h *hostManager) BindDpdkDriver(pciAddr, driver string) error {
log.Log.V(2).Info("BindDpdkDriver(): bind device to driver",
"device", pciAddr, "driver", driver)

Expand Down Expand Up @@ -80,7 +80,7 @@ func (h *HostManager) BindDpdkDriver(pciAddr, driver string) error {

// BindDefaultDriver bind driver for one device
// Bind the device given by "pciAddr" to the default driver
func (h *HostManager) BindDefaultDriver(pciAddr string) error {
func (h *hostManager) BindDefaultDriver(pciAddr string) error {
log.Log.V(2).Info("BindDefaultDriver(): bind device to default driver", "device", pciAddr)

if yes, d := h.HasDriver(pciAddr); yes {
Expand Down Expand Up @@ -114,7 +114,7 @@ func (h *HostManager) BindDefaultDriver(pciAddr string) error {
// Workaround function to handle a case where the vf default driver is stuck and not able to create the vf kernel interface.
// This function unbind the VF from the default driver and try to bind it again
// bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2045087
func (h *HostManager) RebindVfToDefaultDriver(vfAddr string) error {
func (h *hostManager) RebindVfToDefaultDriver(vfAddr string) error {
log.Log.Info("RebindVfToDefaultDriver()", "vf", vfAddr)
if err := h.Unbind(vfAddr); err != nil {
return err
Expand All @@ -128,7 +128,7 @@ func (h *HostManager) RebindVfToDefaultDriver(vfAddr string) error {
return nil
}

func (h *HostManager) UnbindDriverIfNeeded(vfAddr string, isRdma bool) error {
func (h *hostManager) UnbindDriverIfNeeded(vfAddr string, isRdma bool) error {
if isRdma {
log.Log.Info("UnbindDriverIfNeeded(): unbinding driver", "device", vfAddr)
if err := h.Unbind(vfAddr); err != nil {
Expand All @@ -139,7 +139,7 @@ func (h *HostManager) UnbindDriverIfNeeded(vfAddr string, isRdma bool) error {
return nil
}

func (h *HostManager) HasDriver(pciAddr string) (bool, string) {
func (h *hostManager) HasDriver(pciAddr string) (bool, string) {
driver, err := dputils.GetDriverName(pciAddr)
if err != nil {
log.Log.V(2).Info("HasDriver(): device driver is empty for device", "device", pciAddr)
Expand Down
42 changes: 21 additions & 21 deletions pkg/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,17 @@ type HostManagerInterface interface {
GetOSPrettyName() (string, error)
}

type HostManager struct {
utilsHelper utils.UtilsInterface
type hostManager struct {
utilsHelper utils.CmdInterface
}

func NewHostManager(utilsInterface utils.UtilsInterface) HostManagerInterface {
return &HostManager{
func NewHostManager(utilsInterface utils.CmdInterface) HostManagerInterface {
return &hostManager{
utilsHelper: utilsInterface,
}
}

func (h *HostManager) LoadKernelModule(name string, args ...string) error {
func (h *hostManager) LoadKernelModule(name string, args ...string) error {
log.Log.Info("LoadKernelModule(): try to load kernel module", "name", name, "args", args)
chrootDefinition := utils.GetChrootExtension()
cmdArgs := strings.Join(args, " ")
Expand All @@ -152,7 +152,7 @@ func (h *HostManager) LoadKernelModule(name string, args ...string) error {
return nil
}

func (h *HostManager) IsKernelModuleLoaded(kernelModuleName string) (bool, error) {
func (h *hostManager) IsKernelModuleLoaded(kernelModuleName string) (bool, error) {
log.Log.Info("IsKernelModuleLoaded(): check if kernel module is loaded", "name", kernelModuleName)
chrootDefinition := utils.GetChrootExtension()

Expand All @@ -176,19 +176,19 @@ func (h *HostManager) IsKernelModuleLoaded(kernelModuleName string) (bool, error
return false, nil
}

func (h *HostManager) TryEnableTun() {
func (h *hostManager) TryEnableTun() {
if err := h.LoadKernelModule("tun"); err != nil {
log.Log.Error(err, "tryEnableTun(): TUN kernel module not loaded")
}
}

func (h *HostManager) TryEnableVhostNet() {
func (h *hostManager) TryEnableVhostNet() {
if err := h.LoadKernelModule("vhost_net"); err != nil {
log.Log.Error(err, "tryEnableVhostNet(): VHOST_NET kernel module not loaded")
}
}

func (h *HostManager) TryEnableRdma() (bool, error) {
func (h *hostManager) TryEnableRdma() (bool, error) {
log.Log.V(2).Info("tryEnableRdma()")
chrootDefinition := utils.GetChrootExtension()

Expand Down Expand Up @@ -241,7 +241,7 @@ func (h *HostManager) TryEnableRdma() (bool, error) {
return false, fmt.Errorf("unable to load RDMA unsupported OS: %s", osName)
}

func (h *HostManager) EnableRDMAOnRHELMachine() (bool, error) {
func (h *hostManager) EnableRDMAOnRHELMachine() (bool, error) {
log.Log.Info("EnableRDMAOnRHELMachine()")
isCoreOsSystem, err := h.IsCoreOS()
if err != nil {
Expand Down Expand Up @@ -289,7 +289,7 @@ func (h *HostManager) EnableRDMAOnRHELMachine() (bool, error) {
return true, nil
}

func (h *HostManager) EnableRDMAOnUbuntuMachine() (bool, error) {
func (h *hostManager) EnableRDMAOnUbuntuMachine() (bool, error) {
log.Log.Info("EnableRDMAOnUbuntuMachine(): enabling RDMA on RHEL machine")
isRDMAEnable, err := h.EnableRDMA(ubuntuRDMAConditionFile, ubuntuRDMAServiceName, ubuntuPackageManager)
if err != nil {
Expand Down Expand Up @@ -318,7 +318,7 @@ func (h *HostManager) EnableRDMAOnUbuntuMachine() (bool, error) {
return true, nil
}

func (h *HostManager) IsRHELSystem() (bool, error) {
func (h *hostManager) IsRHELSystem() (bool, error) {
log.Log.Info("IsRHELSystem(): checking for RHEL machine")
path := redhatReleaseFile
if !vars.UsingSystemdMode {
Expand All @@ -337,7 +337,7 @@ func (h *HostManager) IsRHELSystem() (bool, error) {
return true, nil
}

func (h *HostManager) IsCoreOS() (bool, error) {
func (h *hostManager) IsCoreOS() (bool, error) {
log.Log.Info("IsCoreOS(): checking for CoreOS machine")
path := redhatReleaseFile
if !vars.UsingSystemdMode {
Expand All @@ -357,7 +357,7 @@ func (h *HostManager) IsCoreOS() (bool, error) {
return false, nil
}

func (h *HostManager) IsUbuntuSystem() (bool, error) {
func (h *hostManager) IsUbuntuSystem() (bool, error) {
log.Log.Info("IsUbuntuSystem(): checking for Ubuntu machine")
path := genericOSReleaseFile
if !vars.UsingSystemdMode {
Expand Down Expand Up @@ -387,7 +387,7 @@ func (h *HostManager) IsUbuntuSystem() (bool, error) {
return false, nil
}

func (h *HostManager) RdmaIsLoaded() (bool, error) {
func (h *hostManager) RdmaIsLoaded() (bool, error) {
log.Log.V(2).Info("RdmaIsLoaded()")
chrootDefinition := utils.GetChrootExtension()

Expand All @@ -405,7 +405,7 @@ func (h *HostManager) RdmaIsLoaded() (bool, error) {
return true, nil
}

func (h *HostManager) EnableRDMA(conditionFilePath, serviceName, packageManager string) (bool, error) {
func (h *hostManager) EnableRDMA(conditionFilePath, serviceName, packageManager string) (bool, error) {
path := conditionFilePath
if !vars.UsingSystemdMode {
path = pathlib.Join(hostPathFromDaemon, path)
Expand Down Expand Up @@ -438,7 +438,7 @@ func (h *HostManager) EnableRDMA(conditionFilePath, serviceName, packageManager
return true, nil
}

func (h *HostManager) InstallRDMA(packageManager string) error {
func (h *hostManager) InstallRDMA(packageManager string) error {
log.Log.Info("InstallRDMA(): installing RDMA")
chrootDefinition := utils.GetChrootExtension()

Expand All @@ -451,7 +451,7 @@ func (h *HostManager) InstallRDMA(packageManager string) error {
return nil
}

func (h *HostManager) TriggerUdevEvent() error {
func (h *hostManager) TriggerUdevEvent() error {
log.Log.Info("TriggerUdevEvent(): installing RDMA")

err := h.ReloadDriver("mlx4_en")
Expand All @@ -467,7 +467,7 @@ func (h *HostManager) TriggerUdevEvent() error {
return nil
}

func (h *HostManager) ReloadDriver(driverName string) error {
func (h *hostManager) ReloadDriver(driverName string) error {
log.Log.Info("ReloadDriver(): reload driver", "name", driverName)
chrootDefinition := utils.GetChrootExtension()

Expand All @@ -481,7 +481,7 @@ func (h *HostManager) ReloadDriver(driverName string) error {
return nil
}

func (h *HostManager) GetOSPrettyName() (string, error) {
func (h *hostManager) GetOSPrettyName() (string, error) {
path := genericOSReleaseFile
if !vars.UsingSystemdMode {
path = pathlib.Join(hostPathFromDaemon, path)
Expand All @@ -504,7 +504,7 @@ func (h *HostManager) GetOSPrettyName() (string, error) {

// IsKernelLockdownMode returns true when kernel lockdown mode is enabled
// TODO: change this to return error
func (h *HostManager) IsKernelLockdownMode() bool {
func (h *hostManager) IsKernelLockdownMode() bool {
path := utils.GetHostExtension()
path = filepath.Join(path, "/sys/kernel/security/lockdown")

Expand Down
4 changes: 2 additions & 2 deletions pkg/host/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// GetCurrentKernelArgs This retrieves the kernel cmd line arguments
func (h *HostManager) GetCurrentKernelArgs() (string, error) {
func (h *hostManager) GetCurrentKernelArgs() (string, error) {
path := consts.ProcKernelCmdLine
if !vars.UsingSystemdMode {
path = filepath.Join("/host", path)
Expand All @@ -27,7 +27,7 @@ func (h *HostManager) GetCurrentKernelArgs() (string, error) {

// IsKernelArgsSet This checks if the kernel cmd line is set properly. Please note that the same key could be repeated
// several times in the kernel cmd line. We can only ensure that the kernel cmd line has the key/val kernel arg that we set.
func (h *HostManager) IsKernelArgsSet(cmdLine string, karg string) bool {
func (h *hostManager) IsKernelArgsSet(cmdLine string, karg string) bool {
elements := strings.Fields(cmdLine)
for _, element := range elements {
if element == karg {
Expand Down
24 changes: 12 additions & 12 deletions pkg/host/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

// TryToGetVirtualInterfaceName get the interface name of a virtio interface
func (h *HostManager) TryToGetVirtualInterfaceName(pciAddr string) string {
func (h *hostManager) TryToGetVirtualInterfaceName(pciAddr string) string {
log.Log.Info("TryToGetVirtualInterfaceName() get interface name for device", "device", pciAddr)

// To support different driver that is not virtio-pci like mlx
Expand Down Expand Up @@ -55,7 +55,7 @@ func (h *HostManager) TryToGetVirtualInterfaceName(pciAddr string) string {
return names[0]
}

func (h *HostManager) TryGetInterfaceName(pciAddr string) string {
func (h *hostManager) TryGetInterfaceName(pciAddr string) string {
names, err := dputils.GetNetNames(pciAddr)
if err != nil || len(names) < 1 {
return ""
Expand All @@ -82,7 +82,7 @@ func (h *HostManager) TryGetInterfaceName(pciAddr string) string {
return netDevName
}

func (h *HostManager) GetNicSriovMode(pciAddress string) (string, error) {
func (h *hostManager) GetNicSriovMode(pciAddress string) (string, error) {
log.Log.V(2).Info("GetNicSriovMode()", "device", pciAddress)

devLink, err := netlink.DevLinkGetDeviceByName("pci", pciAddress)
Expand All @@ -97,7 +97,7 @@ func (h *HostManager) GetNicSriovMode(pciAddress string) (string, error) {
return devLink.Attrs.Eswitch.Mode, nil
}

func (h *HostManager) GetPhysSwitchID(name string) (string, error) {
func (h *hostManager) GetPhysSwitchID(name string) (string, error) {
swIDFile := filepath.Join(vars.FilesystemRoot, consts.SysClassNet, name, "phys_switch_id")
physSwitchID, err := os.ReadFile(swIDFile)
if err != nil {
Expand All @@ -109,7 +109,7 @@ func (h *HostManager) GetPhysSwitchID(name string) (string, error) {
return "", nil
}

func (h *HostManager) GetPhysPortName(name string) (string, error) {
func (h *hostManager) GetPhysPortName(name string) (string, error) {
devicePortNameFile := filepath.Join(vars.FilesystemRoot, consts.SysClassNet, name, "phys_port_name")
physPortName, err := os.ReadFile(devicePortNameFile)
if err != nil {
Expand All @@ -121,7 +121,7 @@ func (h *HostManager) GetPhysPortName(name string) (string, error) {
return "", nil
}

func (h *HostManager) IsSwitchdev(name string) bool {
func (h *hostManager) IsSwitchdev(name string) bool {
switchID, err := h.GetPhysSwitchID(name)
if err != nil || switchID == "" {
return false
Expand All @@ -130,7 +130,7 @@ func (h *HostManager) IsSwitchdev(name string) bool {
return true
}

func (h *HostManager) GetNetdevMTU(pciAddr string) int {
func (h *hostManager) GetNetdevMTU(pciAddr string) int {
log.Log.V(2).Info("GetNetdevMTU(): get MTU", "device", pciAddr)
ifaceName := h.TryGetInterfaceName(pciAddr)
if ifaceName == "" {
Expand All @@ -151,7 +151,7 @@ func (h *HostManager) GetNetdevMTU(pciAddr string) int {
return mtu
}

func (h *HostManager) SetNetdevMTU(pciAddr string, mtu int) error {
func (h *hostManager) SetNetdevMTU(pciAddr string, mtu int) error {
log.Log.V(2).Info("SetNetdevMTU(): set MTU", "device", pciAddr, "mtu", mtu)
if mtu <= 0 {
log.Log.V(2).Info("SetNetdevMTU(): refusing to set MTU", "mtu", mtu)
Expand All @@ -178,7 +178,7 @@ func (h *HostManager) SetNetdevMTU(pciAddr string, mtu int) error {
return nil
}

func (h *HostManager) GetNetDevMac(ifaceName string) string {
func (h *hostManager) GetNetDevMac(ifaceName string) string {
log.Log.V(2).Info("GetNetDevMac(): get Mac", "device", ifaceName)
macFilePath := filepath.Join(vars.FilesystemRoot, consts.SysClassNet, ifaceName, "address")
data, err := os.ReadFile(macFilePath)
Expand All @@ -190,7 +190,7 @@ func (h *HostManager) GetNetDevMac(ifaceName string) string {
return strings.TrimSpace(string(data))
}

func (h *HostManager) GetNetDevLinkSpeed(ifaceName string) string {
func (h *hostManager) GetNetDevLinkSpeed(ifaceName string) string {
log.Log.V(2).Info("GetNetDevLinkSpeed(): get LinkSpeed", "device", ifaceName)
speedFilePath := filepath.Join(vars.FilesystemRoot, consts.SysClassNet, ifaceName, "speed")
data, err := os.ReadFile(speedFilePath)
Expand All @@ -202,7 +202,7 @@ func (h *HostManager) GetNetDevLinkSpeed(ifaceName string) string {
return fmt.Sprintf("%s Mb/s", strings.TrimSpace(string(data)))
}

func (h *HostManager) GetLinkType(ifaceStatus sriovnetworkv1.InterfaceExt) string {
func (h *hostManager) GetLinkType(ifaceStatus sriovnetworkv1.InterfaceExt) string {
log.Log.V(2).Info("GetLinkType()", "device", ifaceStatus.PciAddress)
if ifaceStatus.Name != "" {
link, err := netlink.LinkByName(ifaceStatus.Name)
Expand All @@ -221,7 +221,7 @@ func (h *HostManager) GetLinkType(ifaceStatus sriovnetworkv1.InterfaceExt) strin
return ""
}

func (h *HostManager) DiscoverSriovDevices(storeManager StoreManagerInterface) ([]sriovnetworkv1.InterfaceExt, error) {
func (h *hostManager) DiscoverSriovDevices(storeManager StoreManagerInterface) ([]sriovnetworkv1.InterfaceExt, error) {
log.Log.V(2).Info("DiscoverSriovDevices")
pfList := []sriovnetworkv1.InterfaceExt{}

Expand Down
Loading

0 comments on commit d4e9591

Please sign in to comment.