On 10/2/18 11:04 PM, Chris.Moore@xxxxxxxxxxxxx wrote:
I'm working on LLDD for a SAS/SATA host adapter, and trying to understand how the system handles link loss and recovery.
Say I have a device that gets recognized and attached as sd 12:0:4:0, at /dev/sdb.
The drive goes offline temporarily, then comes back online.
When it does, it comes back as sd 12:0:5:0, and maybe /dev/sdb, maybe /dev/sdc.
I'm not sure how the Id gets assigned. Since this is the same drive, is there
some way my driver can tell libsas and/or SCSI core that it's the same drive coming back?
Or is there no way to control that?
Not really. The target device is getting destroyed once the device
disconnects, and when it reconnects a new structure is allocated. But as
the target number is a simple counter it gets increased up each allocation.
I looked into /dev/disk/by-id, but that also didn't quite do what I expected. If I open
/dev/disk/by-id/some_identifier, that's a symlink to, say, /dev/sdb.
Yes.
/dev/sdb goes away, comes back as /dev/sdc, but my process doesn't know that, it still
has /dev/disk/by-id/some_identifier opened and so it will never recover without closing and reopening the file.
Simply don't keep hold of the symlink; once you have opened you'll miss
any updates to the symlink itself.
So better to open the symlink, check the device, do whatever needs to be
done, and _close the symlink_ again.
Then you can listen for udev events telling you when a device appears or
vanishes.
Cheers,
Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
hare@xxxxxxx +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)