Skip to content

Commit

Permalink
Fix number of VF interface names
Browse files Browse the repository at this point in the history
Only a single VF interace name is used.

Signed-off-by: Marcelo Guerrero <[email protected]>
  • Loading branch information
mlguerrero12 committed Jun 5, 2023
1 parent 80e5fcc commit f9e08ec
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 50 deletions.
12 changes: 6 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func LoadConf(bytes []byte) (*sriovtypes.NetConf, error) {
return n, fmt.Errorf("pci address %s is already allocated", n.DeviceID)
}

// Assuming VF is netdev interface; Get interface name(s)
hostIFNames, err := utils.GetVFLinkNames(n.DeviceID)
if err != nil || hostIFNames == "" {
// Assuming VF is netdev interface; Get interface name
hostIFName, err := utils.GetVFLinkName(n.DeviceID)
if err != nil || hostIFName == "" {
// VF interface not found; check if VF has dpdk driver
hasDpdkDriver, err := utils.HasDpdkDriver(n.DeviceID)
if err != nil {
Expand All @@ -61,11 +61,11 @@ func LoadConf(bytes []byte) (*sriovtypes.NetConf, error) {
n.DPDKMode = hasDpdkDriver
}

if hostIFNames != "" {
n.OrigVfState.HostIFName = hostIFNames
if hostIFName != "" {
n.OrigVfState.HostIFName = hostIFName
}

if hostIFNames == "" && !n.DPDKMode {
if hostIFName == "" && !n.DPDKMode {
return nil, fmt.Errorf("LoadConf(): the VF %s does not have a interface name or a dpdk driver", n.DeviceID)
}

Expand Down
6 changes: 1 addition & 5 deletions pkg/sriov/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (s *sriovManager) SetupVF(conf *sriovtypes.NetConf, podifName string, netns
}); err != nil {
return "", fmt.Errorf("error setting up interface in container namespace: %q", err)
}
conf.ContIFNames = podifName
conf.ContIFName = podifName

return macAddress, nil
}
Expand All @@ -147,10 +147,6 @@ func (s *sriovManager) ReleaseVF(conf *sriovtypes.NetConf, podifName string, net
return fmt.Errorf("failed to get init netns: %v", err)
}

if len(conf.ContIFNames) < 1 && len(conf.ContIFNames) != len(conf.OrigVfState.HostIFName) {
return fmt.Errorf("number of interface names mismatch ContIFNames: %d HostIFNames: %d", len(conf.ContIFNames), len(conf.OrigVfState.HostIFName))
}

return netns.Do(func(_ ns.NetNS) error {
// get VF device
linkObj, err := s.nLink.LinkByName(podifName)
Expand Down
70 changes: 35 additions & 35 deletions pkg/sriov/sriov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ var _ = Describe("Sriov", func() {
BeforeEach(func() {
podifName = "net1"
netconf = &sriovtypes.NetConf{
Master: "enp175s0f1",
DeviceID: "0000:af:06.0",
VFID: 0,
ContIFNames: "net1",
Master: "enp175s0f1",
DeviceID: "0000:af:06.0",
VFID: 0,
ContIFName: "net1",
OrigVfState: sriovtypes.VfState{
HostIFName: "enp175s6",
},
Expand Down Expand Up @@ -141,10 +141,10 @@ var _ = Describe("Sriov", func() {
BeforeEach(func() {
podifName = "net1"
netconf = &sriovtypes.NetConf{
Master: "enp175s0f1",
DeviceID: "0000:af:06.0",
VFID: 0,
ContIFNames: "net1",
Master: "enp175s0f1",
DeviceID: "0000:af:06.0",
VFID: 0,
ContIFName: "net1",
OrigVfState: sriovtypes.VfState{
HostIFName: "enp175s6",
},
Expand All @@ -162,7 +162,7 @@ var _ = Describe("Sriov", func() {
mocked := &mocks_utils.NetlinkManager{}
fakeLink := &FakeLink{netlink.LinkAttrs{Index: 1000, Name: "dummylink"}}

mocked.On("LinkByName", netconf.ContIFNames).Return(fakeLink, nil)
mocked.On("LinkByName", netconf.ContIFName).Return(fakeLink, nil)
mocked.On("LinkSetDown", fakeLink).Return(nil)
mocked.On("LinkSetName", fakeLink, netconf.OrigVfState.HostIFName).Return(nil)
mocked.On("LinkSetNsFd", fakeLink, mock.AnythingOfType("int")).Return(nil)
Expand All @@ -181,11 +181,11 @@ var _ = Describe("Sriov", func() {
BeforeEach(func() {
podifName = "net1"
netconf = &sriovtypes.NetConf{
Master: "enp175s0f1",
DeviceID: "0000:af:06.0",
VFID: 0,
MAC: "aa:f3:8d:65:1b:d4",
ContIFNames: "net1",
Master: "enp175s0f1",
DeviceID: "0000:af:06.0",
VFID: 0,
MAC: "aa:f3:8d:65:1b:d4",
ContIFName: "net1",
OrigVfState: sriovtypes.VfState{
HostIFName: "enp175s6",
EffectiveMAC: "c6:c8:7f:1f:21:90",
Expand All @@ -204,7 +204,7 @@ var _ = Describe("Sriov", func() {
mocked := &mocks_utils.NetlinkManager{}
fakeLink := &FakeLink{netlink.LinkAttrs{Index: 1000, Name: "dummylink"}}

mocked.On("LinkByName", netconf.ContIFNames).Return(fakeLink, nil)
mocked.On("LinkByName", netconf.ContIFName).Return(fakeLink, nil)
mocked.On("LinkSetDown", fakeLink).Return(nil)
mocked.On("LinkSetName", fakeLink, netconf.OrigVfState.HostIFName).Return(nil)
mocked.On("LinkSetNsFd", fakeLink, mock.AnythingOfType("int")).Return(nil)
Expand All @@ -224,10 +224,10 @@ var _ = Describe("Sriov", func() {

BeforeEach(func() {
netconf = &sriovtypes.NetConf{
Master: "enp175s0f1",
DeviceID: "0000:af:06.0",
VFID: 0,
ContIFNames: "net1",
Master: "enp175s0f1",
DeviceID: "0000:af:06.0",
VFID: 0,
ContIFName: "net1",
OrigVfState: sriovtypes.VfState{
HostIFName: "enp175s6",
},
Expand Down Expand Up @@ -264,10 +264,10 @@ var _ = Describe("Sriov", func() {

BeforeEach(func() {
netconf = &sriovtypes.NetConf{
Master: "enp175s0f1",
DeviceID: "0000:af:06.0",
VFID: 0,
ContIFNames: "net1",
Master: "enp175s0f1",
DeviceID: "0000:af:06.0",
VFID: 0,
ContIFName: "net1",
OrigVfState: sriovtypes.VfState{
HostIFName: "enp175s6",
},
Expand Down Expand Up @@ -296,18 +296,18 @@ var _ = Describe("Sriov", func() {
minTxRate := 1000

netconf = &sriovtypes.NetConf{
Master: "enp175s0f1",
DeviceID: "0000:af:06.0",
VFID: 3,
ContIFNames: "net1",
MAC: "d2:fc:22:a7:0d:e8",
Vlan: &vlan,
VlanQoS: &vlanQos,
SpoofChk: "on",
MaxTxRate: &maxTxRate,
MinTxRate: &minTxRate,
Trust: "on",
LinkState: "enable",
Master: "enp175s0f1",
DeviceID: "0000:af:06.0",
VFID: 3,
ContIFName: "net1",
MAC: "d2:fc:22:a7:0d:e8",
Vlan: &vlan,
VlanQoS: &vlanQos,
SpoofChk: "on",
MaxTxRate: &maxTxRate,
MinTxRate: &minTxRate,
Trust: "on",
LinkState: "enable",
OrigVfState: sriovtypes.VfState{
HostIFName: "enp175s6",
SpoofChk: false,
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type NetConf struct {
VlanQoS *int `json:"vlanQoS"`
DeviceID string `json:"deviceID"` // PCI address of a VF in valid sysfs format
VFID int
ContIFNames string // VF names after in the container; used during deletion
ContIFName string // VF name after in the container; used during deletion
MinTxRate *int `json:"min_tx_rate"` // Mbps, 0 = disable rate limiting
MaxTxRate *int `json:"max_tx_rate"` // Mbps, 0 = disable rate limiting
SpoofChk string `json:"spoofchk,omitempty"` // on|off
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ func GetSharedPF(ifName string) (string, error) {
return pfName, fmt.Errorf("Shared PF not found")
}

// GetVFLinkNames returns VF's network interface name given it's PCI addr
func GetVFLinkNames(pciAddr string) (string, error) {
// GetVFLinkName returns VF's network interface name given it's PCI addr
func GetVFLinkName(pciAddr string) (string, error) {
var names []string
vfDir := filepath.Join(SysBusPci, pciAddr, "net")
if _, err := os.Lstat(vfDir); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ = Describe("Utils", func() {
// Expect(err).To(HaveOccurred(), "Looking for shared PF for not supported NIC should return an error")
// })
})
Context("Checking GetVFLinkNames function", func() {
Context("Checking GetVFLinkName function", func() {
It("Assuming existing vf", func() {
result, err := GetVFLinkNamesFromVFID("enp175s0f1", 0)
Expect(result).To(ContainElement("enp175s6"), "Existing PF should have at least one VF")
Expand Down

0 comments on commit f9e08ec

Please sign in to comment.