diff --git a/bindata/scripts/load-udev.sh b/bindata/scripts/load-udev.sh deleted file mode 100755 index d65830ed03..0000000000 --- a/bindata/scripts/load-udev.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -REDHAT_RELEASE_FILE="/host/etc/redhat-release" -udevadm_bin="" - -if [ -f "$REDHAT_RELEASE_FILE" ]; then - udevadm_bin="/usr/sbin/udevadm" -elif grep -i --quiet 'ubuntu' /host/etc/os-release; then - if grep -i --quiet '20' /host/etc/os-release; then - udevadm_bin="/usr/bin/udevadm" - elif grep -i --quiet '16\|18\|14' /host/etc/os-release; then - udevadm_bin="/sbin/udevadm" - fi -fi - -if [ -z "$udevadm_bin" ]; then - echo "udevadm not found" - exit 1 -fi - -echo "Reload udev rules: $udevadm_bin control --reload-rules" -chroot /host/ $udevadm_bin control --reload-rules - -echo "Trigger udev event: $udevadm_bin trigger --action add --attr-match subsystem=net" -chroot /host/ $udevadm_bin trigger --action add --attr-match subsystem=net diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index 05c765416d..a0c2b33ffc 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -1,16 +1,11 @@ package daemon import ( - "bytes" "context" "encoding/json" "fmt" "math/rand" - "os" "os/exec" - "path" - "strconv" - "strings" "sync" "time" @@ -108,11 +103,10 @@ type Daemon struct { } const ( - udevScriptsPath = "/bindata/scripts/load-udev.sh" - annoKey = "sriovnetwork.openshift.io/state" - annoIdle = "Idle" - annoDraining = "Draining" - annoMcpPaused = "Draining_MCP_Paused" + annoKey = "sriovnetwork.openshift.io/state" + annoIdle = "Idle" + annoDraining = "Draining" + annoMcpPaused = "Draining_MCP_Paused" ) // writer implements io.Writer interface as a pass-through for log.Log. @@ -207,9 +201,6 @@ func (dn *Daemon) Run(stopCh <-chan struct{}, exitCh <-chan error) error { if err := dn.HostHelpers.PrepareVFRepUdevRule(); err != nil { log.Log.Error(err, "failed to prepare udev files to rename VF representors for requested VFs") } - if err := dn.tryCreateSwitchdevUdevRule(); err != nil { - log.Log.Error(err, "failed to create udev files for switchdev") - } var timeout int64 = 5 var metadataKey = "metadata.name" @@ -282,11 +273,6 @@ func (dn *Daemon) Run(stopCh <-chan struct{}, exitCh <-chan error) error { } } return err - case <-time.After(30 * time.Second): - log.Log.V(2).Info("Run(): period refresh") - if err := dn.tryCreateSwitchdevUdevRule(); err != nil { - log.Log.V(2).Error(err, "Could not create udev rule") - } } } } @@ -1067,75 +1053,6 @@ func (dn *Daemon) drainNode() error { return nil } -// TODO: move this to host interface -func (dn *Daemon) tryCreateSwitchdevUdevRule() error { - log.Log.V(2).Info("tryCreateSwitchdevUdevRule()") - nodeState, nodeStateErr := dn.client.SriovnetworkV1().SriovNetworkNodeStates(vars.Namespace).Get( - context.Background(), - vars.NodeName, - metav1.GetOptions{}, - ) - if nodeStateErr != nil { - log.Log.Error(nodeStateErr, "could not fetch node state, skip updating switchdev udev rules", "name", vars.NodeName) - return nil - } - - var newContent string - filePath := path.Join(vars.FilesystemRoot, "/host/etc/udev/rules.d/20-switchdev.rules") - - for _, ifaceStatus := range nodeState.Status.Interfaces { - if ifaceStatus.EswitchMode == sriovnetworkv1.ESwithModeSwitchDev { - switchID, err := dn.HostHelpers.GetPhysSwitchID(ifaceStatus.Name) - if err != nil { - return err - } - portName, err := dn.HostHelpers.GetPhysPortName(ifaceStatus.Name) - if err != nil { - return err - } - newContent = newContent + fmt.Sprintf("SUBSYSTEM==\"net\", ACTION==\"add|move\", ATTRS{phys_switch_id}==\"%s\", ATTR{phys_port_name}==\"pf%svf*\", IMPORT{program}=\"/etc/udev/switchdev-vf-link-name.sh $attr{phys_port_name}\", NAME=\"%s_$env{NUMBER}\"\n", switchID, strings.TrimPrefix(portName, "p"), ifaceStatus.Name) - } - } - - oldContent, err := os.ReadFile(filePath) - // if oldContent = newContent, don't do anything - if err == nil && newContent == string(oldContent) { - return nil - } - - log.Log.V(2).Info("Old udev content and new content differ. Writing new content to file.", - "old-content", strings.TrimSuffix(string(oldContent), "\n"), - "new-content", strings.TrimSuffix(newContent, "\n"), - "path", filePath) - - // if the file does not exist or if oldContent != newContent - // write to file and create it if it doesn't exist - err = os.WriteFile(filePath, []byte(newContent), 0664) - if err != nil { - log.Log.Error(err, "tryCreateSwitchdevUdevRule(): fail to write file") - return err - } - - var stdout, stderr bytes.Buffer - cmd := exec.Command("/bin/bash", path.Join(vars.FilesystemRoot, udevScriptsPath)) - cmd.Stdout = &stdout - cmd.Stderr = &stderr - if err := cmd.Run(); err != nil { - return err - } - log.Log.V(2).Info("tryCreateSwitchdevUdevRule(): stdout", "output", cmd.Stdout) - - i, err := strconv.Atoi(strings.TrimSpace(stdout.String())) - if err == nil { - if i == 0 { - log.Log.V(2).Info("tryCreateSwitchdevUdevRule(): switchdev udev rules loaded") - } else { - log.Log.V(2).Info("tryCreateSwitchdevUdevRule(): switchdev udev rules not loaded") - } - } - return nil -} - func (dn *Daemon) prepareNMUdevRule() error { // we need to remove the Red Hat Virtio network device from the udev rule configuration // if we don't remove it when running the config-daemon on a virtual node it will disconnect the node after a reboot diff --git a/pkg/helper/mock/mock_helper.go b/pkg/helper/mock/mock_helper.go index c9314faff2..74aa7bdd61 100644 --- a/pkg/helper/mock/mock_helper.go +++ b/pkg/helper/mock/mock_helper.go @@ -168,17 +168,17 @@ func (mr *MockHostHelpersInterfaceMockRecorder) ConfigSriovDeviceVirtual(iface i } // ConfigSriovInterfaces mocks base method. -func (m *MockHostHelpersInterface) ConfigSriovInterfaces(storeManager store.ManagerInterface, interfaces []v1.Interface, ifaceStatuses []v1.InterfaceExt, pfsToConfig map[string]bool, skipVFConfiguration bool) error { +func (m *MockHostHelpersInterface) ConfigSriovInterfaces(storeManager store.ManagerInterface, interfaces []v1.Interface, ifaceStatuses []v1.InterfaceExt, skipVFConfiguration bool) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConfigSriovInterfaces", storeManager, interfaces, ifaceStatuses, pfsToConfig, skipVFConfiguration) + ret := m.ctrl.Call(m, "ConfigSriovInterfaces", storeManager, interfaces, ifaceStatuses, skipVFConfiguration) ret0, _ := ret[0].(error) return ret0 } // ConfigSriovInterfaces indicates an expected call of ConfigSriovInterfaces. -func (mr *MockHostHelpersInterfaceMockRecorder) ConfigSriovInterfaces(storeManager, interfaces, ifaceStatuses, pfsToConfig, skipVFConfiguration interface{}) *gomock.Call { +func (mr *MockHostHelpersInterfaceMockRecorder) ConfigSriovInterfaces(storeManager, interfaces, ifaceStatuses, skipVFConfiguration interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigSriovInterfaces", reflect.TypeOf((*MockHostHelpersInterface)(nil).ConfigSriovInterfaces), storeManager, interfaces, ifaceStatuses, pfsToConfig, skipVFConfiguration) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigSriovInterfaces", reflect.TypeOf((*MockHostHelpersInterface)(nil).ConfigSriovInterfaces), storeManager, interfaces, ifaceStatuses, skipVFConfiguration) } // CreateVDPADevice mocks base method. @@ -1185,18 +1185,3 @@ func (mr *MockHostHelpersInterfaceMockRecorder) WriteCheckpointFile(arg0 interfa mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WriteCheckpointFile", reflect.TypeOf((*MockHostHelpersInterface)(nil).WriteCheckpointFile), arg0) } - -// WriteSwitchdevConfFile mocks base method. -func (m *MockHostHelpersInterface) WriteSwitchdevConfFile(newState *v1.SriovNetworkNodeState, pfsToSkip map[string]bool) (bool, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WriteSwitchdevConfFile", newState, pfsToSkip) - ret0, _ := ret[0].(bool) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// WriteSwitchdevConfFile indicates an expected call of WriteSwitchdevConfFile. -func (mr *MockHostHelpersInterfaceMockRecorder) WriteSwitchdevConfFile(newState, pfsToSkip interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WriteSwitchdevConfFile", reflect.TypeOf((*MockHostHelpersInterface)(nil).WriteSwitchdevConfFile), newState, pfsToSkip) -} diff --git a/pkg/host/internal/sriov/sriov.go b/pkg/host/internal/sriov/sriov.go index 0b5e099541..d535041963 100644 --- a/pkg/host/internal/sriov/sriov.go +++ b/pkg/host/internal/sriov/sriov.go @@ -574,13 +574,13 @@ func (s *sriov) configSriovDevice(iface *sriovnetworkv1.Interface, skipVFConfigu } func (s *sriov) ConfigSriovInterfaces(storeManager store.ManagerInterface, - interfaces []sriovnetworkv1.Interface, ifaceStatuses []sriovnetworkv1.InterfaceExt, pfsToConfig map[string]bool, skipVFConfiguration bool) error { + interfaces []sriovnetworkv1.Interface, ifaceStatuses []sriovnetworkv1.InterfaceExt, skipVFConfiguration bool) error { if s.kernelHelper.IsKernelLockdownMode() && mlx.HasMellanoxInterfacesInSpec(ifaceStatuses, interfaces) { log.Log.Error(nil, "cannot use mellanox devices when in kernel lockdown mode") return fmt.Errorf("cannot use mellanox devices when in kernel lockdown mode") } - toBeConfigured, toBeResetted, err := s.getConfigureAndReset(storeManager, interfaces, ifaceStatuses, pfsToConfig) + toBeConfigured, toBeResetted, err := s.getConfigureAndReset(storeManager, interfaces, ifaceStatuses) if err != nil { log.Log.Error(err, "cannot get a list of interfaces to configure") return fmt.Errorf("cannot get a list of interfaces to configure") @@ -608,7 +608,8 @@ func (s *sriov) ConfigSriovInterfaces(storeManager store.ManagerInterface, return nil } -func (s *sriov) getConfigureAndReset(storeManager store.ManagerInterface, interfaces []sriovnetworkv1.Interface, ifaceStatuses []sriovnetworkv1.InterfaceExt, pfsToConfig map[string]bool) ([]interfaceToConfigure, []sriovnetworkv1.InterfaceExt, error) { +func (s *sriov) getConfigureAndReset(storeManager store.ManagerInterface, interfaces []sriovnetworkv1.Interface, + ifaceStatuses []sriovnetworkv1.InterfaceExt) ([]interfaceToConfigure, []sriovnetworkv1.InterfaceExt, error) { toBeConfigured := []interfaceToConfigure{} toBeResetted := []sriovnetworkv1.InterfaceExt{} for _, ifaceStatus := range ifaceStatuses { @@ -616,11 +617,6 @@ func (s *sriov) getConfigureAndReset(storeManager store.ManagerInterface, interf for _, iface := range interfaces { if iface.PciAddress == ifaceStatus.PciAddress { configured = true - - if skip := pfsToConfig[iface.PciAddress]; skip { - break - } - skip, err := skipSriovConfig(&iface, &ifaceStatus, storeManager) if err != nil { log.Log.Error(err, "getConfigureAndReset(): failed to check interface") @@ -636,9 +632,7 @@ func (s *sriov) getConfigureAndReset(storeManager store.ManagerInterface, interf } if !configured && ifaceStatus.NumVfs > 0 { - if skip := pfsToConfig[ifaceStatus.PciAddress]; !skip { - toBeResetted = append(toBeResetted, ifaceStatus) - } + toBeResetted = append(toBeResetted, ifaceStatus) } } return toBeConfigured, toBeResetted, nil diff --git a/pkg/host/internal/sriov/sriov_test.go b/pkg/host/internal/sriov/sriov_test.go index 6eca40bac9..1286406b65 100644 --- a/pkg/host/internal/sriov/sriov_test.go +++ b/pkg/host/internal/sriov/sriov_test.go @@ -166,7 +166,7 @@ var _ = Describe("SRIOV", func() { }}, }}, []sriovnetworkv1.InterfaceExt{{PciAddress: "0000:d8:00.0"}, {PciAddress: "0000:d8:00.1"}}, - map[string]bool{"0000:d8:00.1": true}, false)).NotTo(HaveOccurred()) + false)).NotTo(HaveOccurred()) helpers.GinkgoAssertFileContentsEquals("/sys/bus/pci/devices/0000:d8:00.0/sriov_numvfs", "2") }) It("should configure IB", func() { @@ -215,7 +215,7 @@ var _ = Describe("SRIOV", func() { }}, }}, []sriovnetworkv1.InterfaceExt{{PciAddress: "0000:d8:00.0"}}, - map[string]bool{}, false)).NotTo(HaveOccurred()) + false)).NotTo(HaveOccurred()) helpers.GinkgoAssertFileContentsEquals("/sys/bus/pci/devices/0000:d8:00.0/sriov_numvfs", "1") }) @@ -279,7 +279,7 @@ var _ = Describe("SRIOV", func() { }}, }}, []sriovnetworkv1.InterfaceExt{{PciAddress: "0000:d8:00.0"}}, - map[string]bool{}, false)).NotTo(HaveOccurred()) + false)).NotTo(HaveOccurred()) helpers.GinkgoAssertFileContentsEquals("/sys/bus/pci/devices/0000:d8:00.0/sriov_numvfs", "1") }) @@ -302,7 +302,7 @@ var _ = Describe("SRIOV", func() { }}, }}, []sriovnetworkv1.InterfaceExt{{PciAddress: "0000:d8:00.0"}}, - map[string]bool{}, false)).To(HaveOccurred()) + false)).To(HaveOccurred()) }) It("externally managed - wrong MTU", func() { @@ -328,7 +328,7 @@ var _ = Describe("SRIOV", func() { }}, }}, []sriovnetworkv1.InterfaceExt{{PciAddress: "0000:d8:00.0"}}, - map[string]bool{}, false)).To(HaveOccurred()) + false)).To(HaveOccurred()) }) It("reset device", func() { @@ -359,8 +359,7 @@ var _ = Describe("SRIOV", func() { LinkType: "ETH", NumVfs: 2, TotalVfs: 2, - }}, - map[string]bool{}, false)).NotTo(HaveOccurred()) + }}, false)).NotTo(HaveOccurred()) helpers.GinkgoAssertFileContentsEquals("/sys/bus/pci/devices/0000:d8:00.0/sriov_numvfs", "0") }) It("reset device - skip external", func() { @@ -379,8 +378,7 @@ var _ = Describe("SRIOV", func() { PciAddress: "0000:d8:00.0", NumVfs: 2, TotalVfs: 2, - }}, - map[string]bool{}, false)).NotTo(HaveOccurred()) + }}, false)).NotTo(HaveOccurred()) }) It("should configure - skipVFConfiguration is true", func() { helpers.GinkgoConfigureFakeFS(&fakefilesystem.FS{ @@ -424,7 +422,7 @@ var _ = Describe("SRIOV", func() { }}, }}, []sriovnetworkv1.InterfaceExt{{PciAddress: "0000:d8:00.0"}}, - map[string]bool{}, true)).NotTo(HaveOccurred()) + true)).NotTo(HaveOccurred()) helpers.GinkgoAssertFileContentsEquals("/sys/bus/pci/devices/0000:d8:00.0/sriov_numvfs", "2") }) }) diff --git a/pkg/host/mock/mock_host.go b/pkg/host/mock/mock_host.go index 9c5773f248..1057acb99f 100644 --- a/pkg/host/mock/mock_host.go +++ b/pkg/host/mock/mock_host.go @@ -138,17 +138,17 @@ func (mr *MockHostManagerInterfaceMockRecorder) ConfigSriovDeviceVirtual(iface i } // ConfigSriovInterfaces mocks base method. -func (m *MockHostManagerInterface) ConfigSriovInterfaces(storeManager store.ManagerInterface, interfaces []v1.Interface, ifaceStatuses []v1.InterfaceExt, pfsToConfig map[string]bool, skipVFConfiguration bool) error { +func (m *MockHostManagerInterface) ConfigSriovInterfaces(storeManager store.ManagerInterface, interfaces []v1.Interface, ifaceStatuses []v1.InterfaceExt, skipVFConfiguration bool) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConfigSriovInterfaces", storeManager, interfaces, ifaceStatuses, pfsToConfig, skipVFConfiguration) + ret := m.ctrl.Call(m, "ConfigSriovInterfaces", storeManager, interfaces, ifaceStatuses, skipVFConfiguration) ret0, _ := ret[0].(error) return ret0 } // ConfigSriovInterfaces indicates an expected call of ConfigSriovInterfaces. -func (mr *MockHostManagerInterfaceMockRecorder) ConfigSriovInterfaces(storeManager, interfaces, ifaceStatuses, pfsToConfig, skipVFConfiguration interface{}) *gomock.Call { +func (mr *MockHostManagerInterfaceMockRecorder) ConfigSriovInterfaces(storeManager, interfaces, ifaceStatuses, skipVFConfiguration interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigSriovInterfaces", reflect.TypeOf((*MockHostManagerInterface)(nil).ConfigSriovInterfaces), storeManager, interfaces, ifaceStatuses, pfsToConfig, skipVFConfiguration) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigSriovInterfaces", reflect.TypeOf((*MockHostManagerInterface)(nil).ConfigSriovInterfaces), storeManager, interfaces, ifaceStatuses, skipVFConfiguration) } // CreateVDPADevice mocks base method. @@ -1014,18 +1014,3 @@ func (mr *MockHostManagerInterfaceMockRecorder) VFIsReady(pciAddr interface{}) * mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VFIsReady", reflect.TypeOf((*MockHostManagerInterface)(nil).VFIsReady), pciAddr) } - -// WriteSwitchdevConfFile mocks base method. -func (m *MockHostManagerInterface) WriteSwitchdevConfFile(newState *v1.SriovNetworkNodeState, pfsToSkip map[string]bool) (bool, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WriteSwitchdevConfFile", newState, pfsToSkip) - ret0, _ := ret[0].(bool) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// WriteSwitchdevConfFile indicates an expected call of WriteSwitchdevConfFile. -func (mr *MockHostManagerInterfaceMockRecorder) WriteSwitchdevConfFile(newState, pfsToSkip interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WriteSwitchdevConfFile", reflect.TypeOf((*MockHostManagerInterface)(nil).WriteSwitchdevConfFile), newState, pfsToSkip) -} diff --git a/pkg/host/types/interfaces.go b/pkg/host/types/interfaces.go index c813d6848a..c9b843ade4 100644 --- a/pkg/host/types/interfaces.go +++ b/pkg/host/types/interfaces.go @@ -154,14 +154,12 @@ type SriovInterface interface { // ConfigSriovInterfaces configure multiple SR-IOV devices with the desired configuration // if skipVFConfiguration flag is set, the function will configure PF and create VFs on it, but will skip VFs configuration ConfigSriovInterfaces(storeManager store.ManagerInterface, interfaces []sriovnetworkv1.Interface, - ifaceStatuses []sriovnetworkv1.InterfaceExt, pfsToConfig map[string]bool, skipVFConfiguration bool) error + ifaceStatuses []sriovnetworkv1.InterfaceExt, skipVFConfiguration bool) error // ConfigSriovInterfaces configure virtual functions for virtual environments with the desired configuration ConfigSriovDeviceVirtual(iface *sriovnetworkv1.Interface) error } type UdevInterface interface { - // WriteSwitchdevConfFile writes the needed switchdev configuration files for HW offload support - WriteSwitchdevConfFile(newState *sriovnetworkv1.SriovNetworkNodeState, pfsToSkip map[string]bool) (bool, error) // PrepareNMUdevRule creates the needed udev rules to disable NetworkManager from // our managed SR-IOV virtual functions PrepareNMUdevRule(supportedVfIds []string) error diff --git a/pkg/plugins/generic/generic_plugin.go b/pkg/plugins/generic/generic_plugin.go index 8a510417cb..a7a71ca15a 100644 --- a/pkg/plugins/generic/generic_plugin.go +++ b/pkg/plugins/generic/generic_plugin.go @@ -3,7 +3,6 @@ package generic import ( "bytes" "errors" - "fmt" "os/exec" "reflect" "strconv" @@ -18,7 +17,6 @@ import ( plugin "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/plugins" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vars" - mlx "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vendors/mellanox" ) var PluginName = "generic" @@ -57,7 +55,6 @@ type GenericPlugin struct { LastState *sriovnetworkv1.SriovNetworkNodeState DriverStateMap DriverStateMapType DesiredKernelArgs map[string]bool - pfsToSkip map[string]bool helpers helper.HostHelpersInterface skipVFConfiguration bool } @@ -112,7 +109,6 @@ func NewGenericPlugin(helpers helper.HostHelpersInterface, options ...Option) (p SpecVersion: "1.0", DriverStateMap: driverStateMap, DesiredKernelArgs: make(map[string]bool), - pfsToSkip: make(map[string]bool), helpers: helpers, skipVFConfiguration: cfg.skipVFConfiguration, }, nil @@ -185,7 +181,7 @@ func (p *GenericPlugin) Apply() error { } if err := p.helpers.ConfigSriovInterfaces(p.helpers, p.DesireState.Spec.Interfaces, - p.DesireState.Status.Interfaces, p.pfsToSkip, p.skipVFConfiguration); err != nil { + p.DesireState.Status.Interfaces, p.skipVFConfiguration); err != nil { // Catch the "cannot allocate memory" error and try to use PCI realloc if errors.Is(err, syscall.ENOMEM) { p.addToDesiredKernelArgs(consts.KernelArgPciRealloc) @@ -368,76 +364,9 @@ func (p *GenericPlugin) needRebootNode(state *sriovnetworkv1.SriovNetworkNodeSta log.Log.V(2).Info("generic plugin needRebootNode(): need reboot for updating kernel arguments") needReboot = true } - - // Create a map with all the PFs we will need to configure - // we need to create it here before we access the host file system using the chroot function - // because the skipConfigVf needs the mstconfig package that exist only inside the sriov-config-daemon file system - pfsToSkip, err := getPfsToSkip(p.DesireState, p.helpers) - if err != nil { - return false, err - } - p.pfsToSkip = pfsToSkip - - updateNode, err = p.helpers.WriteSwitchdevConfFile(state, p.pfsToSkip) - if err != nil { - log.Log.Error(err, "generic plugin needRebootNode(): fail to write switchdev device config file") - return false, err - } - if updateNode { - log.Log.V(2).Info("generic plugin needRebootNode(): need reboot for updating switchdev device configuration") - needReboot = true - } - return needReboot, nil } -// getPfsToSkip return a map of devices pci addresses to should be configured via systemd instead if the legacy mode -// we skip devices in switchdev mode and Bluefield card in ConnectX mode -func getPfsToSkip(ns *sriovnetworkv1.SriovNetworkNodeState, mlxHelper mlx.MellanoxInterface) (map[string]bool, error) { - pfsToSkip := map[string]bool{} - for _, ifaceStatus := range ns.Status.Interfaces { - for _, iface := range ns.Spec.Interfaces { - if iface.PciAddress == ifaceStatus.PciAddress { - skip, err := skipConfigVf(iface, ifaceStatus, mlxHelper) - if err != nil { - log.Log.Error(err, "GetPfsToSkip(): fail to check for skip VFs", "device", iface.PciAddress) - return pfsToSkip, err - } - pfsToSkip[iface.PciAddress] = skip - break - } - } - } - - return pfsToSkip, nil -} - -// skipConfigVf Use systemd service to configure switchdev mode or BF-2 NICs in OpenShift -func skipConfigVf(ifSpec sriovnetworkv1.Interface, ifStatus sriovnetworkv1.InterfaceExt, mlxHelper mlx.MellanoxInterface) (bool, error) { - if ifSpec.EswitchMode == sriovnetworkv1.ESwithModeSwitchDev { - log.Log.V(2).Info("skipConfigVf(): skip config VF for switchdev device") - return true, nil - } - - // NVIDIA BlueField 2 and BlueField3 in OpenShift - if vars.ClusterType == consts.ClusterTypeOpenshift && ifStatus.Vendor == mlx.VendorMellanox && (ifStatus.DeviceID == mlx.DeviceBF2 || ifStatus.DeviceID == mlx.DeviceBF3) { - // TODO: remove this when switch to the systemd configuration support. - mode, err := mlxHelper.GetMellanoxBlueFieldMode(ifStatus.PciAddress) - if err != nil { - return false, fmt.Errorf("failed to read Mellanox Bluefield card mode for %s,%v", ifStatus.PciAddress, err) - } - - if mode == mlx.BluefieldConnectXMode { - return false, nil - } - - log.Log.V(2).Info("skipConfigVf(): skip config VF for Bluefiled card on DPU mode") - return true, nil - } - - return false, nil -} - // ////////////// for testing purposes only /////////////////////// func (p *GenericPlugin) getDriverStateMap() DriverStateMapType { return p.DriverStateMap diff --git a/pkg/plugins/generic/generic_plugin_test.go b/pkg/plugins/generic/generic_plugin_test.go index 881fc87d4b..9f9c1be83b 100644 --- a/pkg/plugins/generic/generic_plugin_test.go +++ b/pkg/plugins/generic/generic_plugin_test.go @@ -77,8 +77,6 @@ var _ = Describe("Generic plugin", func() { }}, }, } - - hostHelper.EXPECT().WriteSwitchdevConfFile(networkNodeState, map[string]bool{"0000:00:00.0": false}).Return(false, nil) needDrain, needReboot, err := genericPlugin.OnNodeStateChange(networkNodeState) Expect(err).ToNot(HaveOccurred()) Expect(needReboot).To(BeFalse()) @@ -133,8 +131,6 @@ var _ = Describe("Generic plugin", func() { }}, }, } - - hostHelper.EXPECT().WriteSwitchdevConfFile(networkNodeState, map[string]bool{"0000:00:00.0": false}).Return(false, nil) needDrain, needReboot, err := genericPlugin.OnNodeStateChange(networkNodeState) Expect(err).ToNot(HaveOccurred()) Expect(needReboot).To(BeFalse())