[systemd-devel] LibUdev: serial not displayed properly for scsi devices

Martin Wilck mwilck at suse.de
Thu Feb 7 21:08:18 UTC 2019


On Thu, 2019-02-07 at 14:39 +0000, Sven Wiltink wrote:
> Hey all,
> 
> We've been running into the issue where lblk -O outputs the wwn
> instead of the serial for scsi devices. After some debugging I've
> come to the conclusing that /lib/udev/scsi_id is the underlying
> cause. It outputs the wwn of a disk in the ID_SERIAL_SHORT field, but
> does also export the actual serial in a separate field
> (ID_SCSI_SERIAL).

This is not a bug.

Check the code in scsi_serial.c to see that this is is done on purpose.
ID_SERIAL does *not* represent the hardware serial number, it is rather
something like "the best unique identifier for the device at hand".
This is typically an NAA identifier from the VPD page 0x83 ("device
identification"). VPD 0x83 may contain multiple identifiers, out of
which the code uses the "best" one according to a hard-coded internal
priority list (id_search_list in scsi_serial.c). ID_SERIAL_SHORT just
strips the first byte (NAA type) off ID_SERIAL.

You can override this behavior by using the parameter "-p 0x80" for
scsi_id, which forces scsi_id to use VPD page 0x80 ("serial number").

Don't be confused by the name ID_SERIAL, which is just historic AFAICT.
The variable name ID_SERIAL was introduced in 2005, in udev 59 (!).

https://git.kernel.org/pub/scm/linux/hotplug/udev.git/commit/?id=34129109a1f5dca72af2f3f2d3d14a9a0d0c43f6

The name might have been chosen after the variable name "serial" that
the code printed, but even at that time, the algorithm described above
was already followed.


> 
> I am unsure if the fix should be in udev or lsblk, but I wanted to
> bring it up for discussion because the serial not being displayed
> properly.

Yes, lsblk should be fixed (if anything). We can't change udev in this
regard. Too much code depends on the given semantics of ID_SERIAL.

Regards,
Martin




More information about the systemd-devel mailing list