From 1da8086afa10ba224272351f2e0033ddf8887b42 Mon Sep 17 00:00:00 2001 From: "James.Smart@Emulex.Com" Date: Fri, 10 Jun 2005 22:24:30 -0400 Subject: [PATCH] --- yaml --- r: 5751 b: refs/heads/master c: 5c44cd2afad3f7b015542187e147a820600172f1 h: refs/heads/master i: 5749: a9e875cf099afcf56f21f53faaebea5bb5f6d8d6 5747: 90f02a951e9da43f0d6a0cec98ef437451019c57 5743: 3a250189a4d78770f8ed556867af6bb9715443be v: v3 --- [refs] | 2 +- trunk/drivers/scsi/scsi_scan.c | 16 +++++++++++++++- trunk/drivers/scsi/scsi_transport_fc.c | 19 +++++++++++++++++++ trunk/include/scsi/scsi_transport.h | 8 ++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index e979633b072f..23389cca5e7d 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 9c472dd9197429a37691e91c938660a062bf20b0 +refs/heads/master: 5c44cd2afad3f7b015542187e147a820600172f1 diff --git a/trunk/drivers/scsi/scsi_scan.c b/trunk/drivers/scsi/scsi_scan.c index 2d3c4ac475f2..48edd67982a5 100644 --- a/trunk/drivers/scsi/scsi_scan.c +++ b/trunk/drivers/scsi/scsi_scan.c @@ -336,9 +336,23 @@ static struct scsi_target *scsi_alloc_target(struct device *parent, unsigned long flags; const int size = sizeof(struct scsi_target) + shost->transportt->target_size; - struct scsi_target *starget = kmalloc(size, GFP_ATOMIC); + struct scsi_target *starget; struct scsi_target *found_target; + /* + * Obtain the real parent from the transport. The transport + * is allowed to fail (no error) if there is nothing at that + * target id. + */ + if (shost->transportt->target_parent) { + spin_lock_irqsave(shost->host_lock, flags); + parent = shost->transportt->target_parent(shost, channel, id); + spin_unlock_irqrestore(shost->host_lock, flags); + if (!parent) + return NULL; + } + + starget = kmalloc(size, GFP_KERNEL); if (!starget) { printk(KERN_ERR "%s: allocation failure\n", __FUNCTION__); return NULL; diff --git a/trunk/drivers/scsi/scsi_transport_fc.c b/trunk/drivers/scsi/scsi_transport_fc.c index 35d1c1e8e345..e6412fce423c 100644 --- a/trunk/drivers/scsi/scsi_transport_fc.c +++ b/trunk/drivers/scsi/scsi_transport_fc.c @@ -1022,6 +1022,23 @@ static int fc_rport_match(struct attribute_container *cont, return &i->rport_attr_cont.ac == cont; } + +/* + * Must be called with shost->host_lock held + */ +static struct device *fc_target_parent(struct Scsi_Host *shost, + int channel, uint id) +{ + struct fc_rport *rport; + + list_for_each_entry(rport, &fc_host_rports(shost), peers) + if ((rport->channel == channel) && + (rport->scsi_target_id == id)) + return &rport->dev; + + return NULL; +} + struct scsi_transport_template * fc_attach_transport(struct fc_function_template *ft) { @@ -1057,6 +1074,8 @@ fc_attach_transport(struct fc_function_template *ft) /* Transport uses the shost workq for scsi scanning */ i->t.create_work_queue = 1; + + i->t.target_parent = fc_target_parent; /* * Setup SCSI Target Attributes. diff --git a/trunk/include/scsi/scsi_transport.h b/trunk/include/scsi/scsi_transport.h index a4f1837a33b1..f6e0bb484c63 100644 --- a/trunk/include/scsi/scsi_transport.h +++ b/trunk/include/scsi/scsi_transport.h @@ -29,6 +29,14 @@ struct scsi_transport_template { struct transport_container target_attrs; struct transport_container device_attrs; + /* + * If set, call target_parent prior to allocating a scsi_target, + * so we get the appropriate parent for the target. This function + * is required for transports like FC and iSCSI that do not put the + * scsi_target under scsi_host. + */ + struct device *(*target_parent)(struct Scsi_Host *, int, uint); + /* The size of the specific transport attribute structure (a * space of this size will be left at the end of the * scsi_* structure */