Expose AER data in pci_device.go
The current pci_device.go can be extended to expose AER data for supproted devices. The implementation will be similar to that in https://github.com/prometheus/procfs/blob/master/sysfs/net_class_aer.go I will work on this.
I also think the net_class_aer implementation should have ideally be done in pci_device. Should I move that? Thoughts on this?
Unless there is a clear functional benefit I wouldn't refactor working code just for organizational reasons.
My defence is that AER is a PCIe feature and not specific to class/net. In the future, we might have to implement it for all other classes as well (nvme, sas, gpus etc).
If we dont refactor net_class_aer.go, most of the logic will have to be duplicated. We cannot use the same parsors as it expects a "device" subdirectory - since it uses /sys/class/ directories instead of /sys/bus/pci/device directory.
That is perhaps a good enough argument :)
I'm no expert of the sys/ tree but iiuc whether you look in /sys/class/net or /sys/bus/pci/devices/, the files should be the same since the dir structure is mostly a bunch of sym links. E.g.:
jan@apollo ~ % la /sys/class/net/enp35s0/device :(
lrwxrwxrwx 1 root root 0 Dec 4 16:42 /sys/class/net/enp35s0/device -> ../../../0000:23:00.0
jan@apollo ~ % la /sys/class/net/enp35s0/device/
total 0
drwxr-xr-x 8 root root 0 Dec 4 16:45 .
drwxr-xr-x 8 root root 0 Dec 4 16:45 ..
-r--r--r-- 1 root root 4096 Dec 4 16:45 aer_dev_correctable
-r--r--r-- 1 root root 4096 Dec 4 16:45 aer_dev_fatal
-r--r--r-- 1 root root 4096 Dec 4 16:45 aer_dev_nonfatal
-r--r--r-- 1 root root 4096 Dec 4 16:45 ari_enabled
-rw-r--r-- 1 root root 4096 Dec 4 16:45 broken_parity_status
-r--r--r-- 1 root root 4096 Dec 4 16:45 class
-rw-r--r-- 1 root root 4096 Dec 4 16:45 config
-r--r--r-- 1 root root 4096 Dec 4 16:45 consistent_dma_mask_bits
-r--r--r-- 1 root root 4096 Dec 4 16:45 current_link_speed
-r--r--r-- 1 root root 4096 Dec 4 16:45 current_link_width
-rw-r--r-- 1 root root 4096 Dec 4 16:45 d3cold_allowed
-r--r--r-- 1 root root 4096 Dec 4 16:45 device
-r--r--r-- 1 root root 4096 Dec 4 16:45 dma_mask_bits
lrwxrwxrwx 1 root root 0 Dec 4 16:45 driver -> ../../../../../../bus/pci/drivers/igb
-rw-r--r-- 1 root root 4096 Dec 4 16:45 driver_override
-rw-r--r-- 1 root root 4096 Dec 4 16:45 enable
lrwxrwxrwx 1 root root 0 Dec 4 16:45 firmware_node -> ../../../../../LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:37/device:39/device:3d/device:3f
lrwxrwxrwx 1 root root 0 Dec 4 16:45 iommu -> ../../../../0000:00:00.2/iommu/ivhd0
lrwxrwxrwx 1 root root 0 Dec 4 16:45 iommu_group -> ../../../../../../kernel/iommu_groups/10
-r--r--r-- 1 root root 4096 Dec 4 16:45 irq
drwxr-xr-x 2 root root 0 Dec 4 16:45 link
....
jan@apollo ~ % la /sys/bus/pci/devices/0000:23:00.0/
total 0
drwxr-xr-x 8 root root 0 Dec 4 16:45 .
drwxr-xr-x 8 root root 0 Dec 4 16:45 ..
-r--r--r-- 1 root root 4096 Dec 4 16:45 aer_dev_correctable
-r--r--r-- 1 root root 4096 Dec 4 16:45 aer_dev_fatal
-r--r--r-- 1 root root 4096 Dec 4 16:45 aer_dev_nonfatal
-r--r--r-- 1 root root 4096 Dec 4 16:45 ari_enabled
-rw-r--r-- 1 root root 4096 Dec 4 16:45 broken_parity_status
-r--r--r-- 1 root root 4096 Dec 4 16:45 class
-rw-r--r-- 1 root root 4096 Dec 4 16:45 config
-r--r--r-- 1 root root 4096 Dec 4 16:45 consistent_dma_mask_bits
-r--r--r-- 1 root root 4096 Dec 4 16:45 current_link_speed
-r--r--r-- 1 root root 4096 Dec 4 16:45 current_link_width
-rw-r--r-- 1 root root 4096 Dec 4 16:45 d3cold_allowed
-r--r--r-- 1 root root 4096 Dec 4 16:45 device
-r--r--r-- 1 root root 4096 Dec 4 16:45 dma_mask_bits
lrwxrwxrwx 1 root root 0 Dec 4 16:45 driver -> ../../../../../../bus/pci/drivers/igb
-rw-r--r-- 1 root root 4096 Dec 4 16:45 driver_override
-rw-r--r-- 1 root root 4096 Dec 4 16:45 enable
lrwxrwxrwx 1 root root 0 Dec 4 16:45 firmware_node -> ../../../../../LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:37/device:39/device:3d/device:3f
lrwxrwxrwx 1 root root 0 Dec 4 16:45 iommu -> ../../../../0000:00:00.2/iommu/ivhd0
lrwxrwxrwx 1 root root 0 Dec 4 16:45 iommu_group -> ../../../../../../kernel/iommu_groups/10
-r--r--r-- 1 root root 4096 Dec 4 16:45 irq
drwxr-xr-x 2 root root 0 Dec 4 16:45 link
...
So does it matter really for the file parser where is reads the files?
https://github.com/prometheus/procfs/blob/master/sysfs/net_class_aer.go#L136 https://github.com/prometheus/procfs/blob/master/sysfs/net_class_aer.go#L188
We have hardcoded device in the path construction inside the parsers. This works for /sys/class/*/* (used in net_class_aer.go), but not for /sys/bus/pci/devices/* (used in pci_device.go).
Will have to move the path construction outside to use them in both the modules.
Or pull the aer_* file parsing out into a separate function and call that from net_class_aer.go and pci_device.go?
If you move the parsing to a unified /sys/bus/pci/devices/ parser you'll have to retrieve the interface name (at least for net_class)