Skip to contentSkip to conversation

Signal when device is disconnected

DISCUSSION Phil Endecott 2 participants 2 messages May 13, 2009 SCSI

lore
Share & tools
lore
#0 lore raw

Dear Experts,

The proc/bus/usb API has an ioctl that can arrange for the application to receive a signal when the device is disconnected. Is there anything similar for the SCSI generic (or other SCSI) APIs?

Assuming that there isn't, I think I need to either poll the device to see if it's still there, or listen on a netlink socket for a removal uevent, or I need to find the USB device corresponding to the sg device that I'm using and use its signal-on-removal ioctl. In the latter case, is there a way to traverse from an sg device's /sys directory to the corresponding usb device's /sys directory? /sys seems to be full of symlinks but I can't find the one that I need in this case.

Basically I have a fairly simple user-space driver for a USB SCSI device that uses the SCSI-generic API, and I want it to terminate tidily when the device is detached.

Many thanks for any advice.

Phil.

(Please Cc: me in any replies.)

#1 lore raw
Quoted 7 lines · Phil Endecott

Dear Experts,

The proc/bus/usb API has an ioctl that can arrange for the application to receive a signal when the device is disconnected. Is there anything similar for the SCSI generic (or other SCSI) APIs?

Assuming that there isn't, I think I need to either poll the device to see if it's still there, or listen on a netlink socket for a removal uevent, or I need to find the USB device corresponding to the sg device that I'm using and use its signal-on-removal ioctl. In the latter case, is there a way to traverse from an sg device's /sys directory to the corresponding usb device's /sys directory? /sys seems to be full of symlinks but I can't find the one that I need in this case.

Basically I have a fairly simple user-space driver for a USB SCSI device that uses the SCSI-generic API, and I want it to terminate tidily when the device is detached.

Phil,
If you are using the lk 2.6 series (from around 2.6.15) then you could use the inotify mechanism (look at 'man inotify' to start with). For example, you could monitor the deletion of /sys/class/scsi_generic/sg1/dev or the corresponsing device
node: /dev/sg1 .

Doug Gilbert