doug-gilbert / lsscsi

Author's own git mirror of his lsscsi subversion repository
https://sg.danny.cz/scsi/lsscsi.html
GNU General Public License v2.0
6 stars 3 forks source link

/dev/disk/by-id enumeration and duplicate IDs #2

Open tbzatek opened 1 year ago

tbzatek commented 1 year ago

There's a known design shortcoming related to udev and symlinks where symlinks get randomly overwritten in case of duplicate identifiers. This for example concerns /dev/disk/by-XXX that is heavily used by lsscsi for enumeration. As a result identifiers may be missing in its output for some devices.

The test case for example is as follows:

# modprobe scsi_debug add_host=3 num_tgts=4
# lsscsi -i
[6:0:0:0]    disk    Linux    scsi_debug       0191  /dev/sda   333333330000036b0
[6:0:1:0]    disk    Linux    scsi_debug       0191  /dev/sdb   33333333000003a98
[6:0:2:0]    disk    Linux    scsi_debug       0191  /dev/sdc   -
[6:0:3:0]    disk    Linux    scsi_debug       0191  /dev/sde   33333333000004268
[7:0:0:0]    disk    Linux    scsi_debug       0191  /dev/sdd   33333333000003e80
[7:0:1:0]    disk    Linux    scsi_debug       0191  /dev/sdf   -
[7:0:2:0]    disk    Linux    scsi_debug       0191  /dev/sdg   -
[7:0:3:0]    disk    Linux    scsi_debug       0191  /dev/sdh   -
[8:0:0:0]    disk    Linux    scsi_debug       0191  /dev/sdi   33333333000004650
[8:0:1:0]    disk    Linux    scsi_debug       0191  /dev/sdj   33333333000004a38
[8:0:2:0]    disk    Linux    scsi_debug       0191  /dev/sdk   33333333000004e20
[8:0:3:0]    disk    Linux    scsi_debug       0191  /dev/sdl   33333333000005208

Running udevadm trigger will regenerate the symlinks in different (random) order, resulting in the same number of missing identifiers on different devices each time.

Any suggestion for a workaround avoiding drastic changes to the lsscsi enumeration code?

doug-gilbert commented 1 year ago

Hard to know where to start with this one. Is fixing udev out of the question?? From the lsscsi perspective, after a long pause, there is finally work going on. The impetus for this is to add JSON output support but I am trying to clean up the code as I go. So drastic changes could be made. Perhaps if the documented procedure for the "-i" option fails (i.e. is about to output "-") then a fallback procedure could be undertaken. Anyway, just committed and pushed my working version to this mirror.

tbzatek commented 1 year ago

I'm not sure how to handle this issue. This is certainly a corner case and of low importance I guess.

Fixing udev is unrealistic and there's far too many users of /dev/disk/by-id that rely on similar way of enumeration to match the device<->identifier pair. Since lsscsi depends on udev already (and related udev rules), it might make sense to use udev db (through bindings) directly. That's quite a bit of work though.