-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the virtual plugin support #262
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,16 @@ import ( | |
"errors" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
|
||
"github.com/golang/glog" | ||
"github.com/hashicorp/go-retryablehttp" | ||
dputils "github.com/intel/sriov-network-device-plugin/pkg/utils" | ||
"github.com/jaypipes/ghw" | ||
|
||
dputils "github.com/intel/sriov-network-device-plugin/pkg/utils" | ||
sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" | ||
) | ||
|
||
|
@@ -98,6 +101,13 @@ type OSPNetworkData struct { | |
// Omit Services | ||
} | ||
|
||
type OSPDevicesInfo map[string]*OSPDeviceInfo | ||
|
||
type OSPDeviceInfo struct { | ||
MacAddress string | ||
NetworkID string | ||
} | ||
|
||
// GetOpenstackData gets the metadata and network_data | ||
func GetOpenstackData() (metaData *OSPMetaData, networkData *OSPNetworkData, err error) { | ||
metaData, networkData, err = getOpenstackDataFromConfigDrive() | ||
|
@@ -183,32 +193,84 @@ func getOpenstackDataFromMetadataService() (metaData *OSPMetaData, networkData * | |
return metaData, networkData, nil | ||
} | ||
|
||
func parseOpenstackMetaData(pciAddr string, metaData *OSPMetaData, networkData *OSPNetworkData) (networkID string, macAddress string) { | ||
// CreateOpenstackDevicesInfo create the openstack device info map | ||
func CreateOpenstackDevicesInfo(metaData *OSPMetaData, networkData *OSPNetworkData) (OSPDevicesInfo, error) { | ||
glog.Infof("CreateOpenstackDevicesInfo()") | ||
devicesInfo := make(OSPDevicesInfo) | ||
if metaData == nil || networkData == nil { | ||
return | ||
return nil, nil | ||
} | ||
|
||
// use this for hw pass throw interfaces | ||
for _, device := range metaData.Devices { | ||
if pciAddr == device.Address { | ||
for _, link := range networkData.Links { | ||
if device.Mac == link.EthernetMac { | ||
for _, network := range networkData.Networks { | ||
if network.Link == link.ID { | ||
networkID = sriovnetworkv1.OpenstackNetworkID.String() + ":" + network.NetworkID | ||
macAddress = device.Mac | ||
} | ||
for _, link := range networkData.Links { | ||
if device.Mac == link.EthernetMac { | ||
for _, network := range networkData.Networks { | ||
if network.Link == link.ID { | ||
networkID := sriovnetworkv1.OpenstackNetworkID.String() + ":" + network.NetworkID | ||
devicesInfo[device.Address] = &OSPDeviceInfo{MacAddress: device.Mac, NetworkID: networkID} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return | ||
// for vhostuser interface type we check the interfaces on the node | ||
pci, err := ghw.PCI() | ||
if err != nil { | ||
return nil, fmt.Errorf("CreateOpenstackDevicesInfo(): error getting PCI info: %v", err) | ||
} | ||
|
||
devices := pci.ListDevices() | ||
if len(devices) == 0 { | ||
return nil, fmt.Errorf("CreateOpenstackDevicesInfo(): could not retrieve PCI devices") | ||
} | ||
|
||
for _, device := range devices { | ||
if _, exist := devicesInfo[device.Address]; exist { | ||
//we already discover the device via openstack metadata | ||
continue | ||
} | ||
|
||
devClass, err := strconv.ParseInt(device.Class.ID, 16, 64) | ||
if err != nil { | ||
glog.Warningf("CreateOpenstackDevicesInfo(): unable to parse device class for device %+v %q", device, err) | ||
continue | ||
} | ||
if devClass != netClass { | ||
// Not network device | ||
continue | ||
} | ||
|
||
macAddress := "" | ||
if name := tryToGetVirtualInterfaceName(device.Address); name != "" { | ||
if mac := getNetDevMac(name); mac != "" { | ||
macAddress = mac | ||
} | ||
} | ||
if macAddress == "" { | ||
// we didn't manage to find a mac address for the nic skipping | ||
continue | ||
} | ||
|
||
for _, link := range networkData.Links { | ||
if macAddress == link.EthernetMac { | ||
for _, network := range networkData.Networks { | ||
if network.Link == link.ID { | ||
networkID := sriovnetworkv1.OpenstackNetworkID.String() + ":" + network.NetworkID | ||
devicesInfo[device.Address] = &OSPDeviceInfo{MacAddress: macAddress, NetworkID: networkID} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return devicesInfo, err | ||
} | ||
|
||
// DiscoverSriovDevicesVirtual discovers VFs on a virtual platform | ||
func DiscoverSriovDevicesVirtual(platformType PlatformType, metaData *OSPMetaData, networkData *OSPNetworkData) ([]sriovnetworkv1.InterfaceExt, error) { | ||
glog.V(2).Info("DiscoverSriovDevicesVirtual") | ||
func DiscoverSriovDevicesVirtual(devicesInfo OSPDevicesInfo) ([]sriovnetworkv1.InterfaceExt, error) { | ||
glog.V(2).Info("DiscoverSriovDevicesVirtual()") | ||
pfList := []sriovnetworkv1.InterfaceExt{} | ||
|
||
pci, err := ghw.PCI() | ||
|
@@ -232,7 +294,13 @@ func DiscoverSriovDevicesVirtual(platformType PlatformType, metaData *OSPMetaDat | |
continue | ||
} | ||
|
||
netFilter, metaMac := parseOpenstackMetaData(device.Address, metaData, networkData) | ||
deviceInfo, exist := devicesInfo[device.Address] | ||
if !exist { | ||
glog.Warningf("DiscoverSriovDevicesVirtual(): unable to find device in devicesInfo list for pci %s", device.Address) | ||
continue | ||
} | ||
netFilter := deviceInfo.NetworkID | ||
metaMac := deviceInfo.MacAddress | ||
|
||
driver, err := dputils.GetDriverName(device.Address) | ||
if err != nil { | ||
|
@@ -249,7 +317,7 @@ func DiscoverSriovDevicesVirtual(platformType PlatformType, metaData *OSPMetaDat | |
if mtu := getNetdevMTU(device.Address); mtu > 0 { | ||
iface.Mtu = mtu | ||
} | ||
if name := tryGetInterfaceName(device.Address); name != "" { | ||
if name := tryToGetVirtualInterfaceName(device.Address); name != "" { | ||
iface.Name = name | ||
if iface.Mac = getNetDevMac(name); iface.Mac == "" { | ||
iface.Mac = metaMac | ||
|
@@ -277,6 +345,48 @@ func DiscoverSriovDevicesVirtual(platformType PlatformType, metaData *OSPMetaDat | |
return pfList, nil | ||
} | ||
|
||
func CreateOpenstackDevicesInfoFromNodeStatus(networkState *sriovnetworkv1.SriovNetworkNodeState) OSPDevicesInfo { | ||
devicesInfo := make(OSPDevicesInfo) | ||
for _, iface := range networkState.Status.Interfaces { | ||
devicesInfo[iface.PciAddress] = &OSPDeviceInfo{MacAddress: iface.Mac, NetworkID: iface.NetFilter} | ||
} | ||
|
||
return devicesInfo | ||
} | ||
|
||
// tryToGetVirtualInterfaceName get the interface name of a virtio interface | ||
func tryToGetVirtualInterfaceName(pciAddr string) string { | ||
glog.Infof("tryToGetVirtualInterfaceName() get interface name for device %s", pciAddr) | ||
|
||
// To support different driver that is not virtio-pci like mlx | ||
name := tryGetInterfaceName(pciAddr) | ||
if name != "" { | ||
return name | ||
} | ||
|
||
netDir, err := filepath.Glob(filepath.Join(sysBusPciDevices, pciAddr, "virtio*", "net")) | ||
if err != nil || len(netDir) < 1 { | ||
return "" | ||
} | ||
|
||
fInfos, err := ioutil.ReadDir(netDir[0]) | ||
if err != nil { | ||
glog.Warningf("tryToGetVirtualInterfaceName(): failed to read net directory %s: %q", netDir, err) | ||
return "" | ||
} | ||
|
||
names := make([]string, 0) | ||
for _, f := range fInfos { | ||
names = append(names, f.Name()) | ||
} | ||
|
||
if len(names) < 1 { | ||
return "" | ||
} | ||
|
||
return names[0] | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make this return an error instead of calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bn222 sorry I was not able to understand you will like this function to return (string,error) and just change
to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's correct. |
||
// SyncNodeStateVirtual attempt to update the node state to match the desired state | ||
// in virtual platforms | ||
func SyncNodeStateVirtual(newState *sriovnetworkv1.SriovNetworkNodeState) error { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,8 +297,11 @@ func validateNicModel(selector *sriovnetworkv1.SriovNetworkNicSelector, iface *s | |
return true | ||
} | ||
|
||
// Check the vendor and device ID of the VF only if we are on a virtual environment | ||
for key := range utils.PlatformMap { | ||
if strings.Contains(strings.ToLower(node.Spec.ProviderID), strings.ToLower(key)) && sriovnetworkv1.IsVfSupportedModel(iface.Vendor, iface.DeviceID) { | ||
if strings.Contains(strings.ToLower(node.Spec.ProviderID), strings.ToLower(key)) && | ||
selector.NetFilter != "" && selector.NetFilter == iface.NetFilter && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
sriovnetworkv1.IsVfSupportedModel(iface.Vendor, iface.DeviceID) { | ||
return true | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add to:
https://github.com/openshift/sriov-network-operator/blob/master/manifests/stable/supported-nic-ids_v1_configmap.yaml (once we backport it)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you clarify on the 1000 I see it configured as 0000
https://github.com/k8snetworkplumbingwg/sriov-network-operator/pull/271/files#r839536286
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add it when I rebase the openshift repo base on this PR.
The deviceID is 1000 I checked it again