Skip to content

Commit 9b0219b

Browse files
authored
Fix: Use base16 to convert pci sriov_vf_device (#762)
* base16 for sriov vf device Signed-off-by: Jain Johny <[email protected]> * log device location on error Signed-off-by: Jain Johny <[email protected]> * fix test case Signed-off-by: Jain Johny <[email protected]> --------- Signed-off-by: Jain Johny <[email protected]>
1 parent b8b5106 commit 9b0219b

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

sysfs/pci_device.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
214214
}
215215
value, err := strconv.ParseInt(valueStr, 0, 32)
216216
if err != nil {
217-
return nil, fmt.Errorf("failed to parse %q: %w", valueStr, err)
217+
return nil, fmt.Errorf("failed to parse %s %q %s: %w", f, valueStr, device.Location, err)
218218
}
219219

220220
switch f {
@@ -263,7 +263,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
263263
}
264264
value, err := strconv.ParseFloat(strings.TrimSpace(values[0]), 64)
265265
if err != nil {
266-
return nil, fmt.Errorf("failed to parse %s %q: %w", f, valueStr, err)
266+
return nil, fmt.Errorf("failed to parse %s %q %s: %w", f, valueStr, device.Location, err)
267267
}
268268
v := float64(value)
269269
switch f {
@@ -276,7 +276,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
276276
case "max_link_width", "current_link_width":
277277
value, err := strconv.ParseInt(valueStr, 10, 64)
278278
if err != nil {
279-
return nil, fmt.Errorf("failed to parse %s %q: %w", f, valueStr, err)
279+
return nil, fmt.Errorf("failed to parse %s %q %s: %w", f, valueStr, device.Location, err)
280280
}
281281
v := float64(value)
282282
switch f {
@@ -289,7 +289,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
289289
case "numa_node":
290290
value, err := strconv.ParseInt(valueStr, 10, 32)
291291
if err != nil {
292-
return nil, fmt.Errorf("failed to parse %s %q: %w", f, valueStr, err)
292+
return nil, fmt.Errorf("failed to parse %s %q %s: %w", f, valueStr, device.Location, err)
293293
}
294294
v := int32(value)
295295
device.NumaNode = &v
@@ -304,7 +304,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
304304
if os.IsNotExist(err) {
305305
continue // SR-IOV files are optional
306306
}
307-
return nil, fmt.Errorf("failed to read SR-IOV file %q: %w", name, err)
307+
return nil, fmt.Errorf("failed to read SR-IOV file %q %s: %w", name, device.Location, err)
308308
}
309309

310310
valueStr = strings.TrimSpace(valueStr)
@@ -317,55 +317,55 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
317317
// sriov_drivers_autoprobe is a boolean (0 or 1)
318318
value, err := strconv.ParseInt(valueStr, 10, 32)
319319
if err != nil {
320-
return nil, fmt.Errorf("failed to parse SR-IOV boolean %q: %w", valueStr, err)
320+
return nil, fmt.Errorf("failed to parse SR-IOV drivers autoprobe %q %s: %w", valueStr, device.Location, err)
321321
}
322322
v := value != 0
323323
device.SriovDriversAutoprobe = &v
324324

325325
case "sriov_numvfs":
326326
value, err := strconv.ParseUint(valueStr, 10, 32)
327327
if err != nil {
328-
return nil, fmt.Errorf("failed to parse SR-IOV integer %q: %w", valueStr, err)
328+
return nil, fmt.Errorf("failed to parse SR-IOV numvfs %q %s: %w", valueStr, device.Location, err)
329329
}
330330
v := uint32(value)
331331
device.SriovNumvfs = &v
332332

333333
case "sriov_offset":
334334
value, err := strconv.ParseUint(valueStr, 10, 32)
335335
if err != nil {
336-
return nil, fmt.Errorf("failed to parse SR-IOV integer %q: %w", valueStr, err)
336+
return nil, fmt.Errorf("failed to parse SR-IOV offset %q %s: %w", valueStr, device.Location, err)
337337
}
338338
v := uint32(value)
339339
device.SriovOffset = &v
340340

341341
case "sriov_stride":
342342
value, err := strconv.ParseUint(valueStr, 10, 32)
343343
if err != nil {
344-
return nil, fmt.Errorf("failed to parse SR-IOV integer %q: %w", valueStr, err)
344+
return nil, fmt.Errorf("failed to parse SR-IOV stride %q %s: %w", valueStr, device.Location, err)
345345
}
346346
v := uint32(value)
347347
device.SriovStride = &v
348348

349349
case "sriov_totalvfs":
350350
value, err := strconv.ParseUint(valueStr, 10, 32)
351351
if err != nil {
352-
return nil, fmt.Errorf("failed to parse SR-IOV integer %q: %w", valueStr, err)
352+
return nil, fmt.Errorf("failed to parse SR-IOV totalvfs %q %s: %w", valueStr, device.Location, err)
353353
}
354354
v := uint32(value)
355355
device.SriovTotalvfs = &v
356356

357357
case "sriov_vf_device":
358-
value, err := strconv.ParseUint(valueStr, 10, 32)
358+
value, err := strconv.ParseUint(valueStr, 16, 32)
359359
if err != nil {
360-
return nil, fmt.Errorf("failed to parse SR-IOV integer %q: %w", valueStr, err)
360+
return nil, fmt.Errorf("failed to parse SR-IOV vf device %q %s: %w", valueStr, device.Location, err)
361361
}
362362
v := uint32(value)
363363
device.SriovVfDevice = &v
364364

365365
case "sriov_vf_total_msix":
366366
value, err := strconv.ParseUint(valueStr, 10, 64)
367367
if err != nil {
368-
return nil, fmt.Errorf("failed to parse SR-IOV integer %q: %w", valueStr, err)
368+
return nil, fmt.Errorf("failed to parse SR-IOV vf total msix %q %s: %w", valueStr, device.Location, err)
369369
}
370370
v := uint64(value)
371371
device.SriovVfTotalMsix = &v
@@ -380,7 +380,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
380380
if os.IsNotExist(err) {
381381
continue // Power management files are optional
382382
}
383-
return nil, fmt.Errorf("failed to read power management file %q: %w", name, err)
383+
return nil, fmt.Errorf("failed to read power management file %q %s: %w", name, device.Location, err)
384384
}
385385

386386
valueStr = strings.TrimSpace(valueStr)
@@ -393,7 +393,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
393393
// d3cold_allowed is a boolean (0 or 1)
394394
value, err := strconv.ParseInt(valueStr, 10, 32)
395395
if err != nil {
396-
return nil, fmt.Errorf("failed to parse d3cold_allowed boolean %q: %w", valueStr, err)
396+
return nil, fmt.Errorf("failed to parse d3cold_allowed boolean %q %s: %w", valueStr, device.Location, err)
397397
}
398398
v := value != 0
399399
device.D3coldAllowed = &v

sysfs/pci_device_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestPciDevices(t *testing.T) {
4545
SriovOffset = uint32(8)
4646
SriovStride = uint32(1)
4747
SriovTotalvfs = uint32(128)
48-
SriovVfDevice = uint32(1889)
48+
SriovVfDevice = uint32(0x1889)
4949
SriovVfTotalMsix = uint64(4294967033)
5050

5151
// Optional device test values

0 commit comments

Comments
 (0)