Re: Questions about scsi_target_reap and starget/sdev lifecyle

Patrick Mansfield
2005-06-20T18:00:08Z

Hi Alan -

On Mon, Jun 20, 2005 at 12:35:02PM -0400, Alan Stern wrote:

> -/**
> - * scsi_scan_target - scan a target id, possibly including all LUNs on the
> - * target.
> - * @sdevsca: Scsi_Device handle for scanning
> - * @shost: host to scan
> - * @channel: channel to scan
> - * @id: target id to scan
> - *
> - * Description:
> - * Scan the target id on @shost, @channel, and @id. Scan at least LUN
> - * 0, and possibly all LUNs on the target id.
> - *
> - * Use the pre-allocated @sdevscan as a handle for the scanning. This
> - * function sets sdevscan->host, sdevscan->id and sdevscan->lun; the
> - * scanning functions modify sdevscan->lun.
> - *
> - * First try a REPORT LUN scan, if that does not scan the target, do a
> - * sequential scan of LUNs on the target id.
> - **/
> -void scsi_scan_target(struct device *parent, unsigned int channel,
> - unsigned int id, unsigned int lun, int rescan)
> +static void __scsi_scan_target(struct Scsi_Host *shost, unsigned int channel,
> + unsigned int id, unsigned int lun, int rescan)
> {
> - struct Scsi_Host *shost = dev_to_shost(parent);
> int bflags = 0;
> int res;
> struct scsi_device *sdev = NULL;
> @@ -1257,7 +1247,7 @@ void scsi_scan_target(struct device *par
> return;
>
>
> - starget = scsi_alloc_target(parent, channel, id);
> + starget = scsi_alloc_target(&shost->shost_gendev, channel, id);

For FC (and iSCSI), parent != &shost->shost_gendev. See user scanning
on FC thread / patches.

[kernel scsi]$ grep scsi_scan_target scsi_transport_fc.c
scsi_scan_target(&rport->dev, rport->channel, rport->scsi_target_id,

And &rport->dev is not &shost->shost_gendev :-(

> +
> +/**
> + * scsi_scan_target - scan a target id, possibly including all LUNs on the
> + * target.
> + * @parent: host to scan
> + * @channel: channel to scan
> + * @id: target id to scan
> + * @rescan: passed to LUN scanning routines
> + *
> + * Description:
> + * Scan the target id on @shost, @channel, and @id. Scan at least LUN
> + * 0, and possibly all LUNs on the target id.
> + *
> + * First try a REPORT LUN scan, if that does not scan the target, do a
> + * sequential scan of LUNs on the target id.
> + **/
> +void scsi_scan_target(struct device *parent, unsigned int channel,
> + unsigned int id, unsigned int lun, int rescan)
> +{
> + struct Scsi_Host *shost = dev_to_shost(parent);
> +
> + down(&shost->scan_mutex);
> + if (!test_bit(SHOST_REMOVE, &shost->shost_state))
> + __scsi_scan_target(shost, channel, id, lun, rescan);

And so parent still has to be passed down to __scsi_scan_target.

-- Patrick Mansfield