* [PATCH] [SCSI] Automatic LUN removal
@ 2013-02-14 16:36 Ewan D. Milne
2013-02-14 16:36 ` [PATCH] [SCSI] scsi_debug: Do not respond to INQUIRY commands with CHECK CONDITION when sense pending Ewan D. Milne
2013-02-14 16:36 ` [PATCH] [SCSI] sd: Do not return success from init_sd if DIF mempool allocation fails Ewan D. Milne
0 siblings, 2 replies; 6+ messages in thread
From: Ewan D. Milne @ 2013-02-14 16:36 UTC (permalink / raw)
To: linux-scsi
From: "Ewan D. Milne" <emilne@redhat.com>
This patch adds the capability to configure the kernel to
automatically remove LUNs when a rescan of a SCSI target
finds that LUNs that were previously reported are no longer
being reported. This is only done when a target is scanned
using REPORT LUNS, to avoid removing LUNs due to transport
errors (in other words, the target must be accessible).
Signed-off-by: Ewan D. Milne <emilne@redhat.com>
---
drivers/scsi/Kconfig | 8 +++++++
drivers/scsi/scsi_scan.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 5d1e614..9642c87 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -292,6 +292,14 @@ config SCSI_ENHANCED_UA
primarily useful when storage arrays that can be reconfigured
are attached to the system, otherwise you can say N here.
+config SCSI_AUTOMATIC_LUN_REMOVAL
+ bool "Automatic LUN removal"
+ depends on SCSI
+ help
+ If you want LUNs to be automatically removed when a SCSI target
+ is rescanned and the REPORT LUNS result indicates that LUNs are
+ no longer present, say Y. Otherwise, say N.
+
menu "SCSI Transports"
depends on SCSI
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 1bbbc43..a0d0d97 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1318,6 +1318,11 @@ static int scsi_report_lun_scan(struct scsi_target *starget, int bflags,
struct scsi_device *sdev;
struct Scsi_Host *shost = dev_to_shost(&starget->dev);
int ret = 0;
+#ifdef CONFIG_SCSI_AUTOMATIC_LUN_REMOVAL
+ unsigned long flags;
+ struct scsi_device *sdev_i;
+ bool found;
+#endif
/*
* Only support SCSI-3 and up devices if BLIST_NOREPORTLUN is not set.
@@ -1490,6 +1495,55 @@ static int scsi_report_lun_scan(struct scsi_target *starget, int bflags,
}
}
+#ifdef CONFIG_SCSI_AUTOMATIC_LUN_REMOVAL
+ /*
+ * See if all of the LUNs that we know about on the target are
+ * still being reported in the REPORT LUNS data. If any are not,
+ * they have been removed from the target. Remove those LUNs.
+ *
+ * We only do this for REPORT LUNS scanning, because we do not
+ * want to remove LUNs if they are inaccessible due to a transport
+ * error. Here, the target has responded to a command.
+ */
+restart:
+ spin_lock_irqsave(shost->host_lock, flags);
+ list_for_each_entry(sdev_i, &starget->devices, same_target_siblings) {
+ /*
+ * Don't remove the sdev used for the REPORT LUNS command here.
+ * It will be removed at the end of the function if necessary.
+ */
+ if (sdev_i == sdev)
+ continue;
+ if (sdev_i->sdev_state == SDEV_DEL)
+ continue;
+ found = 0;
+ for (lunp = &lun_data[1]; lunp <= &lun_data[num_luns]; lunp++) {
+ lun = scsilun_to_int(lunp);
+ if (memcmp(&lunp->scsi_lun[sizeof(lun)], "\0\0\0\0", 4))
+ continue;
+ else if (lun > sdev->host->max_lun)
+ continue;
+ else if (lun == sdev_i->lun) {
+ found = 1;
+ break;
+ }
+ }
+ if (!found) {
+ spin_unlock_irqrestore(shost->host_lock, flags);
+ sdev_printk(KERN_INFO, sdev_i,
+ "LUN %d is no longer present, removing\n",
+ sdev_i->lun);
+ __scsi_remove_device(sdev_i);
+ /*
+ * Once the device has been removed, the iterator
+ * is no longer valid and we have to start again.
+ */
+ goto restart;
+ }
+ }
+ spin_unlock_irqrestore(shost->host_lock, flags);
+#endif
+
out_err:
kfree(lun_data);
out:
--
1.7.11.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] [SCSI] scsi_debug: Do not respond to INQUIRY commands with CHECK CONDITION when sense pending
2013-02-14 16:36 [PATCH] [SCSI] Automatic LUN removal Ewan D. Milne
@ 2013-02-14 16:36 ` Ewan D. Milne
2013-02-14 21:46 ` Douglas Gilbert
2013-02-14 16:36 ` [PATCH] [SCSI] sd: Do not return success from init_sd if DIF mempool allocation fails Ewan D. Milne
1 sibling, 1 reply; 6+ messages in thread
From: Ewan D. Milne @ 2013-02-14 16:36 UTC (permalink / raw)
To: linux-scsi
From: "Ewan D. Milne" <emilne@redhat.com>
According to SPC, INQUIRY commands are not supposed to respond
with a CHECK CONDITION due to a pending UNIT ATTENTION. This
was causing failures when re-scanning a scsi_debug target.
Signed-off-by: Ewan D. Milne <emilne@redhat.com>
---
drivers/scsi/scsi_debug.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 8a6bf31..68f13be 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -4060,7 +4060,7 @@ write:
errsts = check_condition_result;
break;
}
- if (!errsts && devip->sense_pending) {
+ if (!errsts && devip->sense_pending && (*cmd != INQUIRY)) {
devip->sense_pending = 0;
errsts = check_condition_result;
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] [SCSI] sd: Do not return success from init_sd if DIF mempool allocation fails
2013-02-14 16:36 [PATCH] [SCSI] Automatic LUN removal Ewan D. Milne
2013-02-14 16:36 ` [PATCH] [SCSI] scsi_debug: Do not respond to INQUIRY commands with CHECK CONDITION when sense pending Ewan D. Milne
@ 2013-02-14 16:36 ` Ewan D. Milne
2013-04-05 15:02 ` Ewan Milne
1 sibling, 1 reply; 6+ messages in thread
From: Ewan D. Milne @ 2013-02-14 16:36 UTC (permalink / raw)
To: linux-scsi
From: "Ewan D. Milne" <emilne@redhat.com>
init_sd() was returning 0 if sd_cdb_cache or sd_cdb_pool could
not be allocated. Return -ENOMEM instead, since the sd_disk_class
and the blkdevs will be unregistered if this happens.
Signed-off-by: Ewan D. Milne <emilne@redhat.com>
---
drivers/scsi/sd.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 8551f3e..4943a4f 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2931,12 +2931,14 @@ static int __init init_sd(void)
0, 0, NULL);
if (!sd_cdb_cache) {
printk(KERN_ERR "sd: can't init extended cdb cache\n");
+ err = -ENOMEM;
goto err_out_class;
}
sd_cdb_pool = mempool_create_slab_pool(SD_MEMPOOL_SIZE, sd_cdb_cache);
if (!sd_cdb_pool) {
printk(KERN_ERR "sd: can't init extended cdb pool\n");
+ err = -ENOMEM;
goto err_out_cache;
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] [SCSI] scsi_debug: Do not respond to INQUIRY commands with CHECK CONDITION when sense pending
2013-02-14 16:36 ` [PATCH] [SCSI] scsi_debug: Do not respond to INQUIRY commands with CHECK CONDITION when sense pending Ewan D. Milne
@ 2013-02-14 21:46 ` Douglas Gilbert
2013-02-15 14:58 ` Ewan Milne
0 siblings, 1 reply; 6+ messages in thread
From: Douglas Gilbert @ 2013-02-14 21:46 UTC (permalink / raw)
To: Ewan D. Milne; +Cc: linux-scsi
On 13-02-14 11:36 AM, Ewan D. Milne wrote:
> From: "Ewan D. Milne" <emilne@redhat.com>
>
> According to SPC, INQUIRY commands are not supposed to respond
> with a CHECK CONDITION due to a pending UNIT ATTENTION. This
> was causing failures when re-scanning a scsi_debug target.
Good pick up. Reference: sam5r12.pdf section 5.14 on
Unit Attentions. And please add REPORT LUNS to your patch.
Doug Gilbert
> Signed-off-by: Ewan D. Milne <emilne@redhat.com>
> ---
> drivers/scsi/scsi_debug.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index 8a6bf31..68f13be 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -4060,7 +4060,7 @@ write:
> errsts = check_condition_result;
> break;
> }
> - if (!errsts && devip->sense_pending) {
> + if (!errsts && devip->sense_pending && (*cmd != INQUIRY)) {
> devip->sense_pending = 0;
> errsts = check_condition_result;
> }
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] [SCSI] scsi_debug: Do not respond to INQUIRY commands with CHECK CONDITION when sense pending
2013-02-14 21:46 ` Douglas Gilbert
@ 2013-02-15 14:58 ` Ewan Milne
0 siblings, 0 replies; 6+ messages in thread
From: Ewan Milne @ 2013-02-15 14:58 UTC (permalink / raw)
To: dgilbert; +Cc: linux-scsi
On Thu, 2013-02-14 at 16:46 -0500, Douglas Gilbert wrote:
> On 13-02-14 11:36 AM, Ewan D. Milne wrote:
> > From: "Ewan D. Milne" <emilne@redhat.com>
> >
> > According to SPC, INQUIRY commands are not supposed to respond
> > with a CHECK CONDITION due to a pending UNIT ATTENTION. This
> > was causing failures when re-scanning a scsi_debug target.
>
> Good pick up. Reference: sam5r12.pdf section 5.14 on
> Unit Attentions. And please add REPORT LUNS to your patch.
Will do, thanks.
-Ewan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] [SCSI] sd: Do not return success from init_sd if DIF mempool allocation fails
2013-02-14 16:36 ` [PATCH] [SCSI] sd: Do not return success from init_sd if DIF mempool allocation fails Ewan D. Milne
@ 2013-04-05 15:02 ` Ewan Milne
0 siblings, 0 replies; 6+ messages in thread
From: Ewan Milne @ 2013-04-05 15:02 UTC (permalink / raw)
To: linux-scsi
On Thu, 2013-02-14 at 11:36 -0500, Ewan D. Milne wrote:
> From: "Ewan D. Milne" <emilne@redhat.com>
>
> init_sd() was returning 0 if sd_cdb_cache or sd_cdb_pool could
> not be allocated. Return -ENOMEM instead, since the sd_disk_class
> and the blkdevs will be unregistered if this happens.
>
> Signed-off-by: Ewan D. Milne <emilne@redhat.com>
> ---
> drivers/scsi/sd.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 8551f3e..4943a4f 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -2931,12 +2931,14 @@ static int __init init_sd(void)
> 0, 0, NULL);
> if (!sd_cdb_cache) {
> printk(KERN_ERR "sd: can't init extended cdb cache\n");
> + err = -ENOMEM;
> goto err_out_class;
> }
>
> sd_cdb_pool = mempool_create_slab_pool(SD_MEMPOOL_SIZE, sd_cdb_cache);
> if (!sd_cdb_pool) {
> printk(KERN_ERR "sd: can't init extended cdb pool\n");
> + err = -ENOMEM;
> goto err_out_cache;
> }
>
Would someone mind looking at this patch and ACKing it if you
feel it is appropriate?
Thanks.
-Ewan D. Milne <emilne@redhat.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-04-05 15:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-14 16:36 [PATCH] [SCSI] Automatic LUN removal Ewan D. Milne
2013-02-14 16:36 ` [PATCH] [SCSI] scsi_debug: Do not respond to INQUIRY commands with CHECK CONDITION when sense pending Ewan D. Milne
2013-02-14 21:46 ` Douglas Gilbert
2013-02-15 14:58 ` Ewan Milne
2013-02-14 16:36 ` [PATCH] [SCSI] sd: Do not return success from init_sd if DIF mempool allocation fails Ewan D. Milne
2013-04-05 15:02 ` Ewan Milne
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).