Skip to content

Commit 31175eb

Browse files
authored
Merge pull request #782 from ykulazhenkov/pr-fix-getdevlinkdeviceparam
Fix: GetDevlinkDeviceParam to handle edge-cases correctly
2 parents 6f44ae5 + 61aacb5 commit 31175eb

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

pkg/host/internal/network/network.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,12 @@ func (n *network) GetDevlinkDeviceParam(pciAddr, paramName string) (string, erro
264264
funcLog.Error(err, "GetDevlinkDeviceParam(): fail to get devlink device param")
265265
return "", err
266266
}
267-
if len(param.Values) == 0 {
268-
err = fmt.Errorf("param %s has no value", paramName)
269-
funcLog.Error(err, "GetDevlinkDeviceParam(): error")
270-
return "", err
267+
if len(param.Values) == 0 || param.Values[0].Data == nil {
268+
funcLog.Info("GetDevlinkDeviceParam(): WARNING: can't read devlink parameter from the device, an empty value received")
269+
return "", nil
271270
}
272271
var value string
272+
var ok bool
273273
switch param.Type {
274274
case nl.DEVLINK_PARAM_TYPE_U8, nl.DEVLINK_PARAM_TYPE_U16, nl.DEVLINK_PARAM_TYPE_U32:
275275
var valData uint64
@@ -281,14 +281,22 @@ func (n *network) GetDevlinkDeviceParam(pciAddr, paramName string) (string, erro
281281
case uint32:
282282
valData = uint64(v)
283283
default:
284-
return "", fmt.Errorf("unexpected uint type type")
284+
return "", fmt.Errorf("value is not uint")
285285
}
286286
value = strconv.FormatUint(valData, 10)
287287

288288
case nl.DEVLINK_PARAM_TYPE_STRING:
289-
value = param.Values[0].Data.(string)
289+
value, ok = param.Values[0].Data.(string)
290+
if !ok {
291+
return "", fmt.Errorf("value is not a string")
292+
}
290293
case nl.DEVLINK_PARAM_TYPE_BOOL:
291-
value = strconv.FormatBool(param.Values[0].Data.(bool))
294+
var boolValue bool
295+
boolValue, ok = param.Values[0].Data.(bool)
296+
if !ok {
297+
return "", fmt.Errorf("value is not a bool")
298+
}
299+
value = strconv.FormatBool(boolValue)
292300
default:
293301
return "", fmt.Errorf("unknown value type: %d", param.Type)
294302
}

pkg/host/internal/sriov/sriov.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ func (s *sriov) configureHWOptionsForSwitchdev(iface *sriovnetworkv1.Interface)
376376
log.Log.Error(err, "configureHWOptionsForSwitchdev(): fail to read current flow steering mode for the device", "device", iface.PciAddress)
377377
return err
378378
}
379+
if currentFlowSteeringMode == "" {
380+
log.Log.V(2).Info("configureHWOptionsForSwitchdev(): can't detect current flow_steering_mode mode for the device, skip",
381+
"device", iface.PciAddress)
382+
return nil
383+
}
379384
if currentFlowSteeringMode == desiredFlowSteeringMode {
380385
return nil
381386
}

0 commit comments

Comments
 (0)