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

More reliable vendor/serial/path extraction via udev #59

Closed
jpo-joyent opened this issue Sep 19, 2018 · 1 comment · Fixed by #63
Closed

More reliable vendor/serial/path extraction via udev #59

jpo-joyent opened this issue Sep 19, 2018 · 1 comment · Fixed by #63

Comments

@jpo-joyent
Copy link
Contributor

Ghw is currently relying on udev's population of /dev/disk/by-id/... to extract serial information (see https://github.com/jaypipes/ghw/blob/85a00ff/block_linux.go#L80-L129). This means two things:

  • parsing serial numbers themselves containing - or _ can lead to incorrect results
  • we already have a dependency on udev

Udev also exposes this information in a less-ambiguous less-fragile-to-parse way under /run/udev/data/....

This data is indexed by major:minor device numbers, which can be found by e.g.:

$ cat /sys/class/block/sdj/dev
8:144

(or just stating the device node under /dev/...)

Then, you have convenient access to all of:

$ cat /run/udev/data/b8:144
S:disk/by-id/scsi-35000cca08062c3d4
S:disk/by-id/wwn-0x5000cca08062c3d4
S:disk/by-path/pci-0000:03:00.0-sas-0x5000cca08062c3d5-lun-0
S:disk/by-path/pci-0000:03:00.0-sas-exp0x500056b3896bccff-phy8-lun-0
W:34
I:414515
E:ID_BUS=scsi
E:ID_FS_TYPE=
E:ID_MODEL=HUC101812CSS200
E:ID_MODEL_ENC=HUC101812CSS200\x20
E:ID_PATH=pci-0000:03:00.0-sas-0x5000cca08062c3d5-lun-0
E:ID_PATH_TAG=pci-0000_03_00_0-sas-0x5000cca08062c3d5-lun-0
E:ID_REVISION=FU29
E:ID_SAS_PATH=pci-0000:03:00.0-sas-exp0x500056b3896bccff-phy8-lun-0
E:ID_SCSI=1
E:ID_SCSI_SERIAL=0EHS9UWF
E:ID_SERIAL=35000cca08062c3d4
E:ID_SERIAL_SHORT=5000cca08062c3d4
E:ID_TYPE=disk
E:ID_VENDOR=HGST
E:ID_VENDOR_ENC=HGST\x20\x20\x20\x20
E:ID_WWN=0x5000cca08062c3d4
E:ID_WWN_WITH_EXTENSION=0x5000cca08062c3d4
E:MPATH_SBIN_PATH=/sbin
G:systemd

Still all as non-root ;)

@jaypipes
Copy link
Owner

@jpo-joyent Hi! This is awesome information! :) Wish I had known about it earlier.

I'll see what I can do about using these new filepaths for grabbing information about block devices (and other devices).

Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants