Skip to content

Commit

Permalink
Merge pull request #782 from ykulazhenkov/pr-fix-getdevlinkdeviceparam
Browse files Browse the repository at this point in the history
Fix: GetDevlinkDeviceParam to handle edge-cases correctly
  • Loading branch information
e0ne authored Oct 2, 2024
2 parents 6f44ae5 + 61aacb5 commit 31175eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pkg/host/internal/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ func (n *network) GetDevlinkDeviceParam(pciAddr, paramName string) (string, erro
funcLog.Error(err, "GetDevlinkDeviceParam(): fail to get devlink device param")
return "", err
}
if len(param.Values) == 0 {
err = fmt.Errorf("param %s has no value", paramName)
funcLog.Error(err, "GetDevlinkDeviceParam(): error")
return "", err
if len(param.Values) == 0 || param.Values[0].Data == nil {
funcLog.Info("GetDevlinkDeviceParam(): WARNING: can't read devlink parameter from the device, an empty value received")
return "", nil
}
var value string
var ok bool
switch param.Type {
case nl.DEVLINK_PARAM_TYPE_U8, nl.DEVLINK_PARAM_TYPE_U16, nl.DEVLINK_PARAM_TYPE_U32:
var valData uint64
Expand All @@ -281,14 +281,22 @@ func (n *network) GetDevlinkDeviceParam(pciAddr, paramName string) (string, erro
case uint32:
valData = uint64(v)
default:
return "", fmt.Errorf("unexpected uint type type")
return "", fmt.Errorf("value is not uint")
}
value = strconv.FormatUint(valData, 10)

case nl.DEVLINK_PARAM_TYPE_STRING:
value = param.Values[0].Data.(string)
value, ok = param.Values[0].Data.(string)
if !ok {
return "", fmt.Errorf("value is not a string")
}
case nl.DEVLINK_PARAM_TYPE_BOOL:
value = strconv.FormatBool(param.Values[0].Data.(bool))
var boolValue bool
boolValue, ok = param.Values[0].Data.(bool)
if !ok {
return "", fmt.Errorf("value is not a bool")
}
value = strconv.FormatBool(boolValue)
default:
return "", fmt.Errorf("unknown value type: %d", param.Type)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/host/internal/sriov/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ func (s *sriov) configureHWOptionsForSwitchdev(iface *sriovnetworkv1.Interface)
log.Log.Error(err, "configureHWOptionsForSwitchdev(): fail to read current flow steering mode for the device", "device", iface.PciAddress)
return err
}
if currentFlowSteeringMode == "" {
log.Log.V(2).Info("configureHWOptionsForSwitchdev(): can't detect current flow_steering_mode mode for the device, skip",
"device", iface.PciAddress)
return nil
}
if currentFlowSteeringMode == desiredFlowSteeringMode {
return nil
}
Expand Down

0 comments on commit 31175eb

Please sign in to comment.