• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

k8snetworkplumbingwg / sriov-network-operator / 10058808149

23 Jul 2024 12:22PM UTC coverage: 43.964% (+0.6%) from 43.351%
10058808149

Pull #659

github

web-flow
Merge f199eb95f into 588abb449
Pull Request #659: Configure IB VFs' GUIDs using a statically provided GUID pool

212 of 280 new or added lines in 13 files covered. (75.71%)

2 existing lines in 1 file now uncovered.

6526 of 14844 relevant lines covered (43.96%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.46
/pkg/host/internal/infiniband/ib_guid_pool.go
1
package infiniband
2

3
import (
4
        "fmt"
5
        "net"
6

7
        "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/netlink"
8
        "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/types"
9
)
10

11
// ibGUIDPool is an interface that returns the GUID, allocated for a specific VF id of the specific PF
12
type ibGUIDPool interface {
13
        // GetVFGUID returns the GUID, allocated for a specific VF id of the specific PF
14
        // If no guid pool exists for the given pfPciAddr, returns an error
15
        // If no guids are available for the given VF id, returns an error
16
        GetVFGUID(pfPciAddr string, vfID int) (net.HardwareAddr, error)
17
}
18

19
type ibGUIDPoolImpl struct {
20
        guidConfigs map[string]ibPfGUIDConfig
21
}
22

23
// newIbGUIDPool returns an instance of ibGUIDPool
24
func newIbGUIDPool(configPath string, netlinkLib netlink.NetlinkLib, networkHelper types.NetworkInterface) (ibGUIDPool, error) {
1✔
25
        // All validation for the config file is done in the getIbGUIDConfig function
1✔
26
        configs, err := getIbGUIDConfig(configPath, netlinkLib, networkHelper)
1✔
27
        if err != nil {
2✔
28
                return nil, fmt.Errorf("failed to create ib guid pool: %w", err)
1✔
29
        }
1✔
30

31
        return &ibGUIDPoolImpl{guidConfigs: configs}, nil
1✔
32
}
33

34
// GetVFGUID returns the GUID, allocated for a specific VF id of the specific PF
35
// If no guid pool exists for the given pfPciAddr, returns an error
36
// If no guids are available for the given VF id, returns an error
37
func (p *ibGUIDPoolImpl) GetVFGUID(pfPciAddr string, vfID int) (net.HardwareAddr, error) {
1✔
38
        config, exists := p.guidConfigs[pfPciAddr]
1✔
39
        if !exists {
1✔
NEW
40
                return nil, fmt.Errorf("no guid pool for pci address: %s", pfPciAddr)
×
NEW
41
        }
×
42

43
        if len(config.GUIDs) != 0 {
2✔
44
                if vfID >= len(config.GUIDs) {
2✔
45
                        return nil, fmt.Errorf("no guid allocation found for VF id: %d on pf %s", vfID, pfPciAddr)
1✔
46
                }
1✔
47

48
                guid := config.GUIDs[vfID]
1✔
49

1✔
50
                return guid.HardwareAddr(), nil
1✔
51
        }
52

53
        if config.GUIDRange != nil {
2✔
54
                nextGUID := config.GUIDRange.Start + GUID(vfID)
1✔
55
                if nextGUID > config.GUIDRange.End {
2✔
56
                        return nil, fmt.Errorf("no guid allocation found for VF id: %d on pf %s", vfID, pfPciAddr)
1✔
57
                }
1✔
58

59
                return nextGUID.HardwareAddr(), nil
1✔
60
        }
61

NEW
62
        return nil, fmt.Errorf("no guid pool for pci address: %s", pfPciAddr)
×
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc