Skip to content

Commit

Permalink
Merge pull request #316 from SchSeba/revert_mtu
Browse files Browse the repository at this point in the history
Revert mtu
  • Loading branch information
zeeke authored Jan 13, 2025
2 parents 4e22051 + 20cb85c commit ae8ffa4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
22 changes: 22 additions & 0 deletions pkg/sriov/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ func (s *sriovManager) ReleaseVF(conf *sriovtypes.NetConf, podifName string, net
}
}

// reset MTU for VF device until if the MTU was captured in the cache
if conf.OrigVfState.MTU != 0 {
logging.Debug("Reset VF device MTU",
"func", "ReleaseVF",
"linkObj", linkObj,
"conf.OrigVfState.HostIFName", conf.OrigVfState.HostIFName,
"conf.OrigVfState.MTU", conf.OrigVfState.MTU)
err = s.nLink.LinkSetMTU(linkObj, conf.OrigVfState.MTU)
if err != nil {
return fmt.Errorf("failed to reset MTU for link link %s: %q", conf.OrigVfState.HostIFName, err)
}
}

// move VF device to init netns
logging.Debug("Move VF device to init netns",
"func", "ReleaseVF",
Expand Down Expand Up @@ -351,6 +364,15 @@ func (s *sriovManager) FillOriginalVfInfo(conf *sriovtypes.NetConf) error {
}
conf.OrigVfState.FillFromVfInfo(vfState)

// add also MTU to the vf info in the vf is we have an interface name
if conf.OrigVfState.HostIFName != "" {
vfLink, err := s.nLink.LinkByName(conf.OrigVfState.HostIFName)
if err != nil {
return fmt.Errorf("failed to lookup vf %q: %v", conf.OrigVfState.HostIFName, err)
}
conf.OrigVfState.MTU = vfLink.Attrs().MTU
}

return err
}

Expand Down
15 changes: 14 additions & 1 deletion pkg/sriov/sriov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var _ = Describe("Sriov", func() {
VFID: 0,
OrigVfState: sriovtypes.VfState{
HostIFName: "enp175s6",
MTU: 1500,
}},
}
t = GinkgoT()
Expand Down Expand Up @@ -310,6 +311,7 @@ var _ = Describe("Sriov", func() {
OrigVfState: sriovtypes.VfState{
HostIFName: "enp175s6",
EffectiveMAC: "6e:16:06:0e:b7:e9",
MTU: 1500,
}},
}
})
Expand All @@ -331,6 +333,7 @@ var _ = Describe("Sriov", func() {
mocked.On("LinkByName", podifName).Return(fakeLink, nil)
mocked.On("LinkSetDown", fakeLink).Return(nil)
mocked.On("LinkSetName", fakeLink, netconf.OrigVfState.HostIFName).Return(nil)
mocked.On("LinkSetMTU", fakeLink, 1500).Return(nil)
mocked.On("LinkSetNsFd", fakeLink, mock.AnythingOfType("int")).Return(nil)
sm := sriovManager{nLink: mocked}
err = sm.ReleaseVF(netconf, podifName, targetNetNS)
Expand Down Expand Up @@ -434,7 +437,7 @@ var _ = Describe("Sriov", func() {

fakeLink := &utils.FakeLink{LinkAttrs: netlink.LinkAttrs{
Index: 1000,
Name: "dummylink",
Name: netconf.Name,
HardwareAddr: fakeMac,
Vfs: []netlink.VfInfo{
{
Expand All @@ -443,10 +446,19 @@ var _ = Describe("Sriov", func() {
},
},
}}

fakeVFLink := &utils.FakeLink{LinkAttrs: netlink.LinkAttrs{
Index: 1001,
Name: netconf.OrigVfState.HostIFName,
MTU: 1500,
}}

mocked.On("LinkByName", netconf.Master).Return(fakeLink, nil)
mocked.On("LinkByName", netconf.OrigVfState.HostIFName).Return(fakeVFLink, nil)
sm := sriovManager{nLink: mocked}
err = sm.FillOriginalVfInfo(netconf)
Expect(err).NotTo(HaveOccurred())
Expect(netconf.OrigVfState.MTU).To(Equal(1500))
mocked.AssertExpectations(t)
})
})
Expand Down Expand Up @@ -509,6 +521,7 @@ var _ = Describe("Sriov", func() {
MinTxRate: 0,
MaxTxRate: 0,
LinkState: 2, // disable
MTU: 1500,
}},
}
})
Expand Down
1 change: 1 addition & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type VfState struct {
MinTxRate int
MaxTxRate int
LinkState uint32
MTU int
}

// FillFromVfInfo - Fill attributes according to the provided netlink.VfInfo struct
Expand Down
18 changes: 18 additions & 0 deletions pkg/utils/mocks/netlink_manager_mock.go

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

6 changes: 6 additions & 0 deletions pkg/utils/netlink_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type NetlinkManager interface {
LinkSetVfSpoofchk(netlink.Link, int, bool) error
LinkSetVfTrust(netlink.Link, int, bool) error
LinkSetVfState(netlink.Link, int, uint32) error
LinkSetMTU(netlink.Link, int) error
LinkDelAltName(netlink.Link, string) error
}

Expand Down Expand Up @@ -92,6 +93,11 @@ func (n *MyNetlink) LinkSetVfState(link netlink.Link, vf int, state uint32) erro
return netlink.LinkSetVfState(link, vf, state)
}

// LinkSetMTU using NetlinkManager
func (n *MyNetlink) LinkSetMTU(link netlink.Link, mtu int) error {
return netlink.LinkSetMTU(link, mtu)
}

// LinkDelAltName using NetlinkManager
func (n *MyNetlink) LinkDelAltName(link netlink.Link, altName string) error {
return netlink.LinkDelAltName(link, altName)
Expand Down

0 comments on commit ae8ffa4

Please sign in to comment.