Subject: Re: Long rewind time on atapi tape drive
To: Bill Stouder-Studenmund <wrstuden@netbsd.org>
From: Paul Goyette <paul@whooppee.com>
List: current-users
Date: 10/10/2007 11:55:20
Based on this suggestion, the following patch seems reasonable.  should 
I submit a PR for this?

Index: st.c
===================================================================
RCS file: /cvsroot/src/sys/dev/scsipi/st.c,v
retrieving revision 1.201
diff -u -p -r1.201 st.c
--- st.c	6 Oct 2007 12:52:43 -0000	1.201
+++ st.c	10 Oct 2007 18:53:05 -0000
@@ -1934,6 +1934,7 @@ st_rewind(struct st_softc *st, u_int imm
  	struct scsi_rewind cmd;
  	int error;
  	int nmarks;
+	int timeout;

  	error = st_check_eod(st, FALSE, &nmarks, flags);
  	if (error) {
@@ -1943,6 +1944,12 @@ st_rewind(struct st_softc *st, u_int imm
  	}
  	st->flags &= ~ST_PER_ACTION;

+	/* If requestor asked for immediate response, set a short timeout */
+	if (immediate)
+		timeout = ST_CTL_TIME;
+	else
+		timeout = ST_SPC_TIME;
+
  	/*
  	 * ATAPI tapes always need immediate to be set
  	 */
@@ -1954,7 +1961,7 @@ st_rewind(struct st_softc *st, u_int imm
  	cmd.byte2 = immediate;

  	error = scsipi_command(st->sc_periph, (void *)&cmd, sizeof(cmd), 0, 0,
-	    ST_RETRIES, immediate ? ST_CTL_TIME: ST_SPC_TIME, NULL, flags);
+	    ST_RETRIES, timeout, NULL, flags);
  	if (error) {
  		printf("%s: error %d trying to rewind\n",
  		    st->sc_dev.dv_xname, error);

On Wed, 10 Oct 2007, Bill Stouder-Studenmund wrote:

> On Tue, Oct 09, 2007 at 08:57:23AM -0700, Paul Goyette wrote:
>> I've got a Travan-20 tape drive that frequently takes longer than one
>> minute (sometimes as much as two full minutes) to rewind the tape,
>> resulting in a lost interrupt:
>>
>> 	viaide0:0:0: lost interrupt
>> 	        type: atapi tc_bcount: 0 tc_skip: 0
>>
>> If this is done as part of a "mt rewoff" (rewind and offline) command,
>> the offline part never happens and the tape is not unloaded.
>>
>> I've narrowed this down to the following code in sys/dev/scsipi/st.c
>>
>> /*
>>  *  Rewind the device
>>  */
>> static int
>> st_rewind(struct st_softc *st, u_int immediate, int flags)
>> {
>> 	struct scsi_rewind cmd;
>> 	int error;
>> 	int nmarks;
>>
>> 	...
>>
>> 	/*
>> 	 * ATAPI tapes always need immediate to be set
>> 	 */
>> 	if (scsipi_periph_bustype(st->sc_periph) == SCSIPI_BUSTYPE_ATAPI)
>> 		immediate = SR_IMMED;
>>
>> 	memset(&cmd, 0, sizeof(cmd));
>> 	cmd.opcode = REWIND;
>> 	cmd.byte2 = immediate;
>>
>> 	error = scsipi_command(st->sc_periph, (void *)&cmd, sizeof(cmd), 0,
>> 	0,
>> 	    ST_RETRIES, immediate ? ST_CTL_TIME: ST_SPC_TIME, NULL, flags);
>> 	...
>>
>> ST_SPC_TIME is a fairly long (4 hours!) delay which might be rather
>> excessive to wait, but ST_CTL_TIME is only 30 seconds which is
>> definitely not enough time for the tape to rewind.
>>
>> Is this really the right thing to do?  If so, is it unreasonable to
>> increase the value of ST_CTL_TIME to something closer to the typical
>> reality of two minutes?
>
> I think the thing to do is dig back and see where ST_CTL_TIME vs
> ST_SPC_TIME came from. ST_CTL_TIME may make sense when immediate is set.
>
> I expect though that the thing to do is figure out the timeout based on
> what was passed in for immediate, _then_ have atapi set immediate.
>
> I agree that the bus being atapi shouldn't mean we always do a 30 second
> time out. I'm just not sure if there aren't times we will still actually
> want that 30 second time out. Maybe there aren't but we should understand
> that explicitly. :-)
>
> Take care,
>
> Bill
>

----------------------------------------------------------------------
|   Paul Goyette   | PGP DSS Key fingerprint: |  E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 |  paul@whooppee.com   |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette@juniper.net |
----------------------------------------------------------------------