question about sd_sync_cache and shutdown

Mike Christie
2006-07-12T00:57:41Z

Currently, if we remove a host, target, transport object like session or
rport or scsi_device sd_shutdown will get called but
scsi_disk_get_from_dev will return NULL and we hit this return statement

static void sd_shutdown(struct device *dev)
{
struct scsi_device *sdp = to_scsi_device(dev);
struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);

if (!sdkp)
return; /* this can happen */

The reason is that __scsi_remove_device calls scsi_device_set_state and
sets the state to SDEV_CANCEL then it calls device_del. then when
scsi_disk_get_from_dev is called in sd.c it eventually calls
scsi_device_get which checks if the state is SDEV_CANCEL and it so
returns NULL.

My question is if this a bug or expected behavior? It seems like a bug
because for a orderly removal of some object, like someone shutting down
a iscsi session, we are going to hit that path, but the command will not
get sent. However, for unorderly removal, like ripping out a usb device
or FC rport or iSCSI session being removed due to dev_loss_tmp expiring
then we do not want the command sent. So it seems like it may be
intended behavior.