Skip to content

Commit 34aa654

Browse files
bvanasscheChristoph Hellwig
authored andcommitted
IB/srp: Avoid that I/O hangs due to a cable pull during LUN scanning
If a cable is pulled during LUN scanning it can happen that the SRP rport and the SCSI host have been created but no LUNs have been added to the SCSI host. Since multipathd only sends SCSI commands to a SCSI target if one or more SCSI devices are present and since there is no keepalive mechanism for IB queue pairs this means that after a LUN scan failed and after a reconnect has succeeded no data will be sent over the QP and hence that a subsequent cable pull will not be detected. Avoid this by not creating an rport or SCSI host if a cable is pulled during a SCSI LUN scan. Note: so far the above behavior has only been observed with the kernel module parameter ch_count set to a value >= 2. Signed-off-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Sagi Grimberg <sagig@mellanox.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 205619f commit 34aa654

2 files changed

Lines changed: 52 additions & 9 deletions

File tree

‎drivers/infiniband/ulp/srp/ib_srp.c‎

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,10 @@ static int srp_rport_reconnect(struct srp_rport *rport)
11111111
int i, ret;
11121112

11131113
srp_disconnect_target(target);
1114+
1115+
if (target->state == SRP_TARGET_SCANNING)
1116+
return -ENODEV;
1117+
11141118
/*
11151119
* Now get a new local CM ID so that we avoid confusing the target in
11161120
* case things are really fouled up. Doing so also ensures that all CM
@@ -2585,11 +2589,23 @@ static struct scsi_host_template srp_template = {
25852589
.shost_attrs = srp_host_attrs
25862590
};
25872591

2592+
static int srp_sdev_count(struct Scsi_Host *host)
2593+
{
2594+
struct scsi_device *sdev;
2595+
int c = 0;
2596+
2597+
shost_for_each_device(sdev, host)
2598+
c++;
2599+
2600+
return c;
2601+
}
2602+
25882603
static int srp_add_target(struct srp_host *host, struct srp_target_port *target)
25892604
{
25902605
struct srp_rport_identifiers ids;
25912606
struct srp_rport *rport;
25922607

2608+
target->state = SRP_TARGET_SCANNING;
25932609
sprintf(target->target_name, "SRP.T10:%016llX",
25942610
(unsigned long long) be64_to_cpu(target->id_ext));
25952611

@@ -2612,11 +2628,26 @@ static int srp_add_target(struct srp_host *host, struct srp_target_port *target)
26122628
list_add_tail(&target->list, &host->target_list);
26132629
spin_unlock(&host->target_lock);
26142630

2615-
target->state = SRP_TARGET_LIVE;
2616-
26172631
scsi_scan_target(&target->scsi_host->shost_gendev,
26182632
0, target->scsi_id, SCAN_WILD_CARD, 0);
26192633

2634+
if (!target->connected || target->qp_in_error) {
2635+
shost_printk(KERN_INFO, target->scsi_host,
2636+
PFX "SCSI scan failed - removing SCSI host\n");
2637+
srp_queue_remove_work(target);
2638+
goto out;
2639+
}
2640+
2641+
pr_debug(PFX "%s: SCSI scan succeeded - detected %d LUNs\n",
2642+
dev_name(&target->scsi_host->shost_gendev),
2643+
srp_sdev_count(target->scsi_host));
2644+
2645+
spin_lock_irq(&target->lock);
2646+
if (target->state == SRP_TARGET_SCANNING)
2647+
target->state = SRP_TARGET_LIVE;
2648+
spin_unlock_irq(&target->lock);
2649+
2650+
out:
26202651
return 0;
26212652
}
26222653

@@ -2960,6 +2991,12 @@ static ssize_t srp_create_target(struct device *dev,
29602991
target->tl_retry_count = 7;
29612992
target->queue_size = SRP_DEFAULT_QUEUE_SIZE;
29622993

2994+
/*
2995+
* Avoid that the SCSI host can be removed by srp_remove_target()
2996+
* before this function returns.
2997+
*/
2998+
scsi_host_get(target->scsi_host);
2999+
29633000
mutex_lock(&host->add_target_mutex);
29643001

29653002
ret = srp_parse_options(buf, target);
@@ -3022,18 +3059,23 @@ static ssize_t srp_create_target(struct device *dev,
30223059
if (ret)
30233060
goto err_disconnect;
30243061

3025-
shost_printk(KERN_DEBUG, target->scsi_host, PFX
3026-
"new target: id_ext %016llx ioc_guid %016llx pkey %04x service_id %016llx sgid %pI6 dgid %pI6\n",
3027-
be64_to_cpu(target->id_ext),
3028-
be64_to_cpu(target->ioc_guid),
3029-
be16_to_cpu(target->path.pkey),
3030-
be64_to_cpu(target->service_id),
3031-
target->path.sgid.raw, target->path.dgid.raw);
3062+
if (target->state != SRP_TARGET_REMOVED) {
3063+
shost_printk(KERN_DEBUG, target->scsi_host, PFX
3064+
"new target: id_ext %016llx ioc_guid %016llx pkey %04x service_id %016llx sgid %pI6 dgid %pI6\n",
3065+
be64_to_cpu(target->id_ext),
3066+
be64_to_cpu(target->ioc_guid),
3067+
be16_to_cpu(target->path.pkey),
3068+
be64_to_cpu(target->service_id),
3069+
target->path.sgid.raw, target->orig_dgid);
3070+
}
30323071

30333072
ret = count;
30343073

30353074
out:
30363075
mutex_unlock(&host->add_target_mutex);
3076+
3077+
scsi_host_put(target->scsi_host);
3078+
30373079
return ret;
30383080

30393081
err_disconnect:

‎drivers/infiniband/ulp/srp/ib_srp.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ enum {
7373
};
7474

7575
enum srp_target_state {
76+
SRP_TARGET_SCANNING,
7677
SRP_TARGET_LIVE,
7778
SRP_TARGET_REMOVED,
7879
};

0 commit comments

Comments
 (0)