Skip to contentSkip to conversation

cciss: Fix SCSI device reset handler

PATCH In review [email protected] 4 participants 9 messages May 27, 2009 – Jun 2, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 cciss: Fix SCSI device reset handler

Fix the SCSI reset error handler to send a working, properly addressed reset message to the target device and add code to wait for the target device to become ready by polling it with Test Unit Ready.

---

The existing reset code was broken in that it didn't bother to set the 8-byte LUN address to anything besides zero, so the command was addressed to the controller, which pretended to the driver that the command succeeded, while doing nothing. Ages ago I tested this code, but unbeknownst to me, my test was flawed, and what I thought was a tape drive getting reset was actually nothing of the sort. Unfortunately, there is still lots of Smartarray firmware that doesn't handle doing target resets right, and this code won't help in those cases, but it also shouldn't make things worse in those cases than they already are.

drivers/block/cciss.c renamed from drivers/block/cciss.c~cciss_fix_lun_reset +11 -3
diff -puN drivers/block/cciss.c~cciss_fix_lun_reset drivers/block/cciss.c
@@ -1979,6 +1979,13 @@ static int fill_cmd(CommandList_struct *
 			c->Request.CDB[0] = BMIC_WRITE;
 			c->Request.CDB[6] = BMIC_CACHE_FLUSH;
 			break;
+		case TEST_UNIT_READY:
+			memcpy(c->Header. LUN.LunAddrBytes, scsi3addr, 8);
+			c->Request.CDBLen = 6;
+			c->Request.Type.Attribute = ATTR_SIMPLE;
+			c->Request.Type.Direction = XFER_NONE;
+			c->Request.Timeout = 0;
+			break;
 		default:
 			printk(KERN_WARNING
 			       "cciss%d:  Unknown Command 0x%c\n", ctlr, cmd);
@@ -1997,13 +2004,14 @@ static int fill_cmd(CommandList_struct *
 			memcpy(&c->Request.CDB[4], buff, 8);
 			break;
 		case 1:	/* RESET message */
-			c->Request.CDBLen = 12;
+			memcpy(c->Header.LUN.LunAddrBytes, scsi3addr, 8);
+			c->Request.CDBLen = 16;
 			c->Request.Type.Attribute = ATTR_SIMPLE;
-			c->Request.Type.Direction = XFER_WRITE;
+			c->Request.Type.Direction = XFER_NONE;
 			c->Request.Timeout = 0;
 			memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB));
 			c->Request.CDB[0] = cmd;	/* reset */
-			c->Request.CDB[1] = 0x04;	/* reset a LUN */
+			c->Request.CDB[1] = 0x03;	/* reset a target */
 			break;
 		case 3:	/* No-Op message */
 			c->Request.CDBLen = 1;
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +79 -6

116 lines not on this page · raw message

diff -puN drivers/block/cciss.h~cciss_fix_lun_reset drivers/block/cciss.h _

#1 lore raw
Quoted 13 lines · On Wed, 27 May 2009 15:30:07 -0500 [email protected] wrote:
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +13 -0
+static int wait_for_device_to_become_ready(ctlr_info_t *h,
+	unsigned char lunaddr[])
+{
+	int rc;
+	int count = 0;
+	int waittime = HZ;
+	CommandList_struct *c;
+
+	c = cmd_alloc(h, 1);
+	if (!c) {
+		printk(KERN_WARNING "cciss%d: out of memory in "
+			"wait_for_device_to_become_ready.\n", h->ctlr);
+		return IO_ERROR;

drivers/block/cciss_scsi.c cciss_seq_tape_report(struct seq_file *s · line 1612

Quoted 10 lines
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +10 -0
+	}
+
+	/* Send test unit ready until device ready, or give up. */
+	while (count < 20) {
+
+		/* Wait for a bit.  do this first, because if we send
+		 * the TUR right away, the reset will just abort it.
+		 */
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(waittime);

That's schedule_timeout_interruptible().

The problem with interruptible sleeps of this nature is that they are no-ops if the calling process happens to have signal_pending(). I suspect that this condition will break your driver.

If so, switching to schedule_timeout_uninterruptible() will unbreak it.

#2 lore raw
Quoted 29 lines · Andrew Morton
Quoted 13 lines · On Wed, 27 May 2009 15:30:07 -0500 [email protected] wrote:
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +13 -0
+static int wait_for_device_to_become_ready(ctlr_info_t *h,
+	unsigned char lunaddr[])
+{
+	int rc;
+	int count = 0;
+	int waittime = HZ;
+	CommandList_struct *c;
+
+	c = cmd_alloc(h, 1);
+	if (!c) {
+		printk(KERN_WARNING "cciss%d: out of memory in "
+			"wait_for_device_to_become_ready.\n", h->ctlr);
+		return IO_ERROR;

drivers/block/cciss_scsi.c cciss_seq_tape_report(struct seq_file *s · line 1612

Quoted 10 lines
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +10 -0
+	}
+
+	/* Send test unit ready until device ready, or give up. */
+	while (count < 20) {
+
+		/* Wait for a bit.  do this first, because if we send
+		 * the TUR right away, the reset will just abort it.
+		 */
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(waittime);

That's schedule_timeout_interruptible().

Quoted 5 lines

The problem with interruptible sleeps of this nature is that they are no-ops if the calling process happens to have signal_pending(). I suspect that this condition will break your driver.

If so, switching to schedule_timeout_uninterruptible() will unbreak it.

I added Stephens patch and your fixup.

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 30 lines · Jens Axboe
Quoted 29 lines · Andrew Morton
Quoted 13 lines · On Wed, 27 May 2009 15:30:07 -0500 [email protected] wrote:
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +13 -0
+static int wait_for_device_to_become_ready(ctlr_info_t *h,
+	unsigned char lunaddr[])
+{
+	int rc;
+	int count = 0;
+	int waittime = HZ;
+	CommandList_struct *c;
+
+	c = cmd_alloc(h, 1);
+	if (!c) {
+		printk(KERN_WARNING "cciss%d: out of memory in "
+			"wait_for_device_to_become_ready.\n", h->ctlr);
+		return IO_ERROR;

drivers/block/cciss_scsi.c cciss_seq_tape_report(struct seq_file *s · line 1612

Quoted 10 lines
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +10 -0
+	}
+
+	/* Send test unit ready until device ready, or give up. */
+	while (count < 20) {
+
+		/* Wait for a bit.  do this first, because if we send
+		 * the TUR right away, the reset will just abort it.
+		 */
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(waittime);

That's schedule_timeout_interruptible().

Quoted 11 lines
Quoted 5 lines

The problem with interruptible sleeps of this nature is that they are no-ops if the calling process happens to have signal_pending(). I suspect that this condition will break your driver.

If so, switching to schedule_timeout_uninterruptible() will unbreak it.

I added Stephens patch and your fixup.

Signature · 1 line
Jens Axboe

Thanks, Jens.

#4 lore raw
In reply to Jens Axboe
Quoted 30 lines · On Tue, 2 Jun 2009 14:50:11 +0200 Jens Axboe <[email protected]> wrote:
Quoted 29 lines · Andrew Morton
Quoted 13 lines · On Wed, 27 May 2009 15:30:07 -0500 [email protected] wrote:
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +13 -0
+static int wait_for_device_to_become_ready(ctlr_info_t *h,
+	unsigned char lunaddr[])
+{
+	int rc;
+	int count = 0;
+	int waittime = HZ;
+	CommandList_struct *c;
+
+	c = cmd_alloc(h, 1);
+	if (!c) {
+		printk(KERN_WARNING "cciss%d: out of memory in "
+			"wait_for_device_to_become_ready.\n", h->ctlr);
+		return IO_ERROR;

drivers/block/cciss_scsi.c cciss_seq_tape_report(struct seq_file *s · line 1612

Quoted 10 lines
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +10 -0
+	}
+
+	/* Send test unit ready until device ready, or give up. */
+	while (count < 20) {
+
+		/* Wait for a bit.  do this first, because if we send
+		 * the TUR right away, the reset will just abort it.
+		 */
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(waittime);

That's schedule_timeout_interruptible().

Quoted 7 lines
Quoted 5 lines

The problem with interruptible sleeps of this nature is that they are no-ops if the calling process happens to have signal_pending(). I suspect that this condition will break your driver.

If so, switching to schedule_timeout_uninterruptible() will unbreak it.

I added Stephens patch and your fixup.

My cciss-fix-scsi-device-reset-handler-fix.patch was a simple cleanup - it uses schedule_timeout_interruptible().

I believe that this should be changed to schedule_timeout_uninterruptible() for the above reasons, but the cciss guys fell asleep on me.

#5 lore raw
Quoted 39 lines · Andrew Morton
Quoted 36 lines · On Tue, 2 Jun 2009 14:50:11 +0200 Jens Axboe <[email protected]> wrote:
Quoted 34 lines · Andrew Morton
Quoted 13 lines · On Wed, 27 May 2009 15:30:07 -0500 [email protected] wrote:
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +13 -0
+static int wait_for_device_to_become_ready(ctlr_info_t *h,
+	unsigned char lunaddr[])
+{
+	int rc;
+	int count = 0;
+	int waittime = HZ;
+	CommandList_struct *c;
+
+	c = cmd_alloc(h, 1);
+	if (!c) {
+		printk(KERN_WARNING "cciss%d: out of memory in "
+			"wait_for_device_to_become_ready.\n", h->ctlr);
+		return IO_ERROR;

drivers/block/cciss_scsi.c cciss_seq_tape_report(struct seq_file *s · line 1612

Quoted 10 lines
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +10 -0
+	}
+
+	/* Send test unit ready until device ready, or give up. */
+	while (count < 20) {
+
+		/* Wait for a bit.  do this first, because if we send
+		 * the TUR right away, the reset will just abort it.
+		 */
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(waittime);

That's schedule_timeout_interruptible().

The problem with interruptible sleeps of this nature is that they are no-ops if the calling process happens to have signal_pending(). I suspect that this condition will break your driver.

If so, switching to schedule_timeout_uninterruptible() will unbreak it.

Quoted 8 lines
Quoted 1 line

I added Stephens patch and your fixup.

My cciss-fix-scsi-device-reset-handler-fix.patch was a simple cleanup - it uses schedule_timeout_interruptible().

I believe that this should be changed to schedule_timeout_uninterruptible() for the above reasons, but the cciss guys fell asleep on me.

It's an improvement, none the less. And I bet it should just be uninterruptible sleep, unless it has a good reason to accept signals. Mike? Stephen?

Signature · 1 line
Jens Axboe
#6 lore raw
Quoted 45 lines · Jens Axboe
Quoted 44 lines · Andrew Morton
Quoted 30 lines · On Tue, 2 Jun 2009 14:50:11 +0200 Jens Axboe <[email protected]> wrote:
Quoted 29 lines · Andrew Morton
Quoted 13 lines · On Wed, 27 May 2009 15:30:07 -0500 [email protected] wrote:
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +13 -0
+static int wait_for_device_to_become_ready(ctlr_info_t *h,
+	unsigned char lunaddr[])
+{
+	int rc;
+	int count = 0;
+	int waittime = HZ;
+	CommandList_struct *c;
+
+	c = cmd_alloc(h, 1);
+	if (!c) {
+		printk(KERN_WARNING "cciss%d: out of memory in "
+			"wait_for_device_to_become_ready.\n", h->ctlr);
+		return IO_ERROR;

drivers/block/cciss_scsi.c cciss_seq_tape_report(struct seq_file *s · line 1612

Quoted 10 lines
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +10 -0
+	}
+
+	/* Send test unit ready until device ready, or give up. */
+	while (count < 20) {
+
+		/* Wait for a bit.  do this first, because if we send
+		 * the TUR right away, the reset will just abort it.
+		 */
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(waittime);

That's schedule_timeout_interruptible().

Quoted 7 lines
Quoted 5 lines

The problem with interruptible sleeps of this nature is that they are no-ops if the calling process happens to have signal_pending(). I suspect that this condition will break your driver.

If so, switching to schedule_timeout_uninterruptible() will unbreak it.

I added Stephens patch and your fixup.

My cciss-fix-scsi-device-reset-handler-fix.patch was a simple cleanup - it uses schedule_timeout_interruptible().

Quoted 11 lines
Quoted 3 lines

I believe that this should be changed to schedule_timeout_uninterruptible() for the above reasons, but the cciss guys fell asleep on me.

It's an improvement, none the less. And I bet it should just be uninterruptible sleep, unless it has a good reason to accept signals. Mike? Stephen?

Signature · 1 line
Jens Axboe

Sorry for the slow reply.

No good reason that I know to accept signals, I'll defer to your judgement on that. When I wrote that schedule_timeout_... line, I was vaguely wondering if it was quite right.

That being said, I'm working on a set of patches to make the cciss SCSI error handling stuff work with interrupts enabled, which means making similar changes to sendcmd_withirq() as I already
did to sendcmd() among some other stuff. I didn't notice until
just a few days ago that since sometime in 2.4 kernels you no longer need to do the SCSI error handling with interrupts disabled as in 2.2 kernels. Mike asked me why we did it with interrupts disabled, and I went looking in the docs to try to find where it said we needed to do that, and... oh, that requirement is gone.

So, if I rewrite the stuff to work with interrupts enabled, would that change which kind of schedule_timeout() should be used? Or is that unrelated, and it depends whether you plan to do something with signals? I'm not all that clear when to use one vs. tha other.

-- steve

#7 lore raw
Quoted 76 lines · On Tue, Jun 02 2009, [email protected] wrote:
Quoted 45 lines · Jens Axboe
Quoted 44 lines · Andrew Morton
Quoted 30 lines · On Tue, 2 Jun 2009 14:50:11 +0200 Jens Axboe <[email protected]> wrote:
Quoted 29 lines · Andrew Morton
Quoted 13 lines · On Wed, 27 May 2009 15:30:07 -0500 [email protected] wrote:
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +13 -0
+static int wait_for_device_to_become_ready(ctlr_info_t *h,
+	unsigned char lunaddr[])
+{
+	int rc;
+	int count = 0;
+	int waittime = HZ;
+	CommandList_struct *c;
+
+	c = cmd_alloc(h, 1);
+	if (!c) {
+		printk(KERN_WARNING "cciss%d: out of memory in "
+			"wait_for_device_to_become_ready.\n", h->ctlr);
+		return IO_ERROR;

drivers/block/cciss_scsi.c cciss_seq_tape_report(struct seq_file *s · line 1612

Quoted 10 lines
drivers/block/cciss_scsi.c renamed from drivers/block/cciss_scsi.c~cciss_fix_lun_reset +10 -0
+	}
+
+	/* Send test unit ready until device ready, or give up. */
+	while (count < 20) {
+
+		/* Wait for a bit.  do this first, because if we send
+		 * the TUR right away, the reset will just abort it.
+		 */
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(waittime);

That's schedule_timeout_interruptible().

Quoted 7 lines
Quoted 5 lines

The problem with interruptible sleeps of this nature is that they are no-ops if the calling process happens to have signal_pending(). I suspect that this condition will break your driver.

If so, switching to schedule_timeout_uninterruptible() will unbreak it.

I added Stephens patch and your fixup.

My cciss-fix-scsi-device-reset-handler-fix.patch was a simple cleanup - it uses schedule_timeout_interruptible().

Quoted 11 lines
Quoted 3 lines

I believe that this should be changed to schedule_timeout_uninterruptible() for the above reasons, but the cciss guys fell asleep on me.

It's an improvement, none the less. And I bet it should just be uninterruptible sleep, unless it has a good reason to accept signals. Mike? Stephen?

Signature · 1 line
Jens Axboe

Sorry for the slow reply.

No good reason that I know to accept signals, I'll defer to your judgement on that. When I wrote that schedule_timeout_... line, I was vaguely wondering if it was quite right.

That being said, I'm working on a set of patches to make the cciss SCSI error handling stuff work with interrupts enabled, which means making similar changes to sendcmd_withirq() as I already
did to sendcmd() among some other stuff. I didn't notice until
just a few days ago that since sometime in 2.4 kernels you no longer need to do the SCSI error handling with interrupts disabled as in 2.2 kernels. Mike asked me why we did it with interrupts disabled, and I went looking in the docs to try to find where it said we needed to do that, and... oh, that requirement is gone.

Quoted 5 lines

So, if I rewrite the stuff to work with interrupts enabled, would that change which kind of schedule_timeout() should be used? Or is that unrelated, and it depends whether you plan to do something with signals? I'm not all that clear when to use one vs. tha other.

For short sleeps and sleeps that are outside of direct process context, an uninterruptible sleep is typically the right thing to do. Since this function is invoked from the scsi eh, doing signal enabled sleeps are pointless.

Signature · 1 line
Jens Axboe
#8 lore raw
Quoted 83 lines · Jens Axboe
Quoted 76 lines · On Tue, Jun 02 2009, [email protected] wrote:
Quoted 45 lines · Jens Axboe
Quoted 44 lines · Andrew Morton
Quoted 30 lines · On Tue, 2 Jun 2009 14:50:11 +0200 Jens Axboe <[email protected]> wrote:
Quoted 29 lines · Andrew Morton
Quoted 13 lines · On Wed, 27 May 2009 15:30:07 -0500 [email protected] wrote:
(quoted diff) +13 -0
+static int wait_for_device_to_become_ready(ctlr_info_t *h,
+	unsigned char lunaddr[])
+{
+	int rc;
+	int count = 0;
+	int waittime = HZ;
+	CommandList_struct *c;
+
+	c = cmd_alloc(h, 1);
+	if (!c) {
+		printk(KERN_WARNING "cciss%d: out of memory in "
+			"wait_for_device_to_become_ready.\n", h->ctlr);
+		return IO_ERROR;

Review

Quoted 10 lines
(quoted diff) +10 -0
+	}
+
+	/* Send test unit ready until device ready, or give up. */
+	while (count < 20) {
+
+		/* Wait for a bit.  do this first, because if we send
+		 * the TUR right away, the reset will just abort it.
+		 */
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(waittime);

That's schedule_timeout_interruptible().

Quoted 7 lines
Quoted 5 lines

The problem with interruptible sleeps of this nature is that they are no-ops if the calling process happens to have signal_pending(). I suspect that this condition will break your driver.

If so, switching to schedule_timeout_uninterruptible() will unbreak it.

I added Stephens patch and your fixup.

My cciss-fix-scsi-device-reset-handler-fix.patch was a simple cleanup - it uses schedule_timeout_interruptible().

Quoted 11 lines
Quoted 3 lines

I believe that this should be changed to schedule_timeout_uninterruptible() for the above reasons, but the cciss guys fell asleep on me.

It's an improvement, none the less. And I bet it should just be uninterruptible sleep, unless it has a good reason to accept signals. Mike? Stephen?

Signature · 1 line
Jens Axboe

Sorry for the slow reply.

No good reason that I know to accept signals, I'll defer to your judgement on that. When I wrote that schedule_timeout_... line, I was vaguely wondering if it was quite right.

That being said, I'm working on a set of patches to make the cciss SCSI error handling stuff work with interrupts enabled, which means making similar changes to sendcmd_withirq() as I already
did to sendcmd() among some other stuff. I didn't notice until
just a few days ago that since sometime in 2.4 kernels you no longer need to do the SCSI error handling with interrupts disabled as in 2.2 kernels. Mike asked me why we did it with interrupts disabled, and I went looking in the docs to try to find where it said we needed to do that, and... oh, that requirement is gone.

Quoted 5 lines

So, if I rewrite the stuff to work with interrupts enabled, would that change which kind of schedule_timeout() should be used? Or is that unrelated, and it depends whether you plan to do something with signals? I'm not all that clear when to use one vs. tha other.

Quoted 4 lines

For short sleeps and sleeps that are outside of direct process context, an uninterruptible sleep is typically the right thing to do. Since this function is invoked from the scsi eh, doing signal enabled sleeps are pointless.

Ok, thanks.

I think in a few days I should have five or six more patches to clean up some of the sendcmd_() junk a little bit, and get the SCSI error handling stuff working with interrupts enabled, and I think that may allow the weird thing where we stow away completed commands that sendcmd() scoops up inadvertently for later processing to be removed, which would be nice.

-- steve

Quoted 4 lines
Signature · 2 lines
-- 
Jens Axboe