Skip to content
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

Fix: GetDevlinkDeviceParam to handle edge-cases correctly #782

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 == "" {
adrianchiris marked this conversation as resolved.
Show resolved Hide resolved
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
Loading