Skip to content
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
30 changes: 15 additions & 15 deletions sysfs/pci_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
}
value, err := strconv.ParseInt(valueStr, 0, 32)
if err != nil {
return nil, fmt.Errorf("failed to parse %q: %w", valueStr, err)
return nil, fmt.Errorf("failed to parse %s %q %s: %w", f, valueStr, device.Location, err)
}

switch f {
Expand Down Expand Up @@ -263,7 +263,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
}
value, err := strconv.ParseFloat(strings.TrimSpace(values[0]), 64)
if err != nil {
return nil, fmt.Errorf("failed to parse %s %q: %w", f, valueStr, err)
return nil, fmt.Errorf("failed to parse %s %q %s: %w", f, valueStr, device.Location, err)
}
v := float64(value)
switch f {
Expand All @@ -276,7 +276,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
case "max_link_width", "current_link_width":
value, err := strconv.ParseInt(valueStr, 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse %s %q: %w", f, valueStr, err)
return nil, fmt.Errorf("failed to parse %s %q %s: %w", f, valueStr, device.Location, err)
}
v := float64(value)
switch f {
Expand All @@ -289,7 +289,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
case "numa_node":
value, err := strconv.ParseInt(valueStr, 10, 32)
if err != nil {
return nil, fmt.Errorf("failed to parse %s %q: %w", f, valueStr, err)
return nil, fmt.Errorf("failed to parse %s %q %s: %w", f, valueStr, device.Location, err)
}
v := int32(value)
device.NumaNode = &v
Expand All @@ -304,7 +304,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
if os.IsNotExist(err) {
continue // SR-IOV files are optional
}
return nil, fmt.Errorf("failed to read SR-IOV file %q: %w", name, err)
return nil, fmt.Errorf("failed to read SR-IOV file %q %s: %w", name, device.Location, err)
}

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

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

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

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

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

case "sriov_vf_device":
value, err := strconv.ParseUint(valueStr, 10, 32)
value, err := strconv.ParseUint(valueStr, 16, 32)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SuperQ this fixes #761 . Value in this file doesn't have 0x prefix which led to the mistake.

if err != nil {
return nil, fmt.Errorf("failed to parse SR-IOV integer %q: %w", valueStr, err)
return nil, fmt.Errorf("failed to parse SR-IOV vf device %q %s: %w", valueStr, device.Location, err)
}
v := uint32(value)
device.SriovVfDevice = &v

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

valueStr = strings.TrimSpace(valueStr)
Expand All @@ -393,7 +393,7 @@ func (fs FS) parsePciDevice(name string) (*PciDevice, error) {
// d3cold_allowed is a boolean (0 or 1)
value, err := strconv.ParseInt(valueStr, 10, 32)
if err != nil {
return nil, fmt.Errorf("failed to parse d3cold_allowed boolean %q: %w", valueStr, err)
return nil, fmt.Errorf("failed to parse d3cold_allowed boolean %q %s: %w", valueStr, device.Location, err)
}
v := value != 0
device.D3coldAllowed = &v
Expand Down
2 changes: 1 addition & 1 deletion sysfs/pci_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestPciDevices(t *testing.T) {
SriovOffset = uint32(8)
SriovStride = uint32(1)
SriovTotalvfs = uint32(128)
SriovVfDevice = uint32(1889)
SriovVfDevice = uint32(0x1889)
SriovVfTotalMsix = uint64(4294967033)

// Optional device test values
Expand Down