forked from k8snetworkplumbingwg/sriovnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmofed_ib_helper.go
55 lines (47 loc) · 1.53 KB
/
mofed_ib_helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package sriovnet
import (
"net"
"path/filepath"
"strconv"
)
const (
ibSriovCfgDir = "sriov"
ibSriovNodeFile = "node"
ibSriovPortFile = "port"
ibSriovPortAdminFile = "policy"
ibSriovPortAdminStateFollow = "Follow"
)
func ibGetPortAdminState(pfNetdevName string, vfIndex int) (string, error) {
path := filepath.Join(NetSysDir, pfNetdevName, pcidevPrefix, ibSriovCfgDir, strconv.Itoa(vfIndex), ibSriovPortAdminFile)
adminStateFile := fileObject{
Path: path,
}
state, err := adminStateFile.Read()
if err != nil {
return "", err
}
return state, nil
}
func ibSetPortAdminState(pfNetdevName string, vfIndex int, newState string) error {
path := filepath.Join(NetSysDir, pfNetdevName, pcidevPrefix, ibSriovCfgDir, strconv.Itoa(vfIndex), ibSriovPortAdminFile)
adminStateFile := fileObject{
Path: path,
}
return adminStateFile.Write(newState)
}
func ibSetNodeGuid(pfNetdevName string, vfIndex int, guid net.HardwareAddr) error {
path := filepath.Join(NetSysDir, pfNetdevName, pcidevPrefix, ibSriovCfgDir, strconv.Itoa(vfIndex), ibSriovNodeFile)
nodeGuidFile := fileObject{
Path: path,
}
kernelGuidFormat := guid.String()
return nodeGuidFile.Write(kernelGuidFormat)
}
func ibSetPortGuid(pfNetdevName string, vfIndex int, guid net.HardwareAddr) error {
path := filepath.Join(NetSysDir, pfNetdevName, pcidevPrefix, ibSriovCfgDir, strconv.Itoa(vfIndex), ibSriovPortFile)
portGuidFile := fileObject{
Path: path,
}
kernelGuidFormat := guid.String()
return portGuidFile.Write(kernelGuidFormat)
}