diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2006-05-18 00:10:06 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2006-05-18 00:10:06 +0000 |
commit | 1e8f3a0da51e1c05792a1bab4a9218fd17da6e09 (patch) | |
tree | ae99581443ad84e727b1f59978e8cc92c54ba498 /sys | |
parent | c8fdb4e9f8a004934c3bba2ae707f47541a81e80 (diff) |
Test the state of a disk *after* spinning it up and not before. This
prevents the issuing of sizing inquiries to non-existant or non-responsive
devices like empty slots on a USB card reader.
Also try to avoid *extremely* unlikely loop of scsi_start() commands, by
not using sd_interpret_sense() until after the disk is spinning.
ok dlg@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/scsi/sd.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c index d44a7e985a6..fc928eb261e 100644 --- a/sys/scsi/sd.c +++ b/sys/scsi/sd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sd.c,v 1.105 2006/05/11 00:45:59 krw Exp $ */ +/* $OpenBSD: sd.c,v 1.106 2006/05/18 00:10:05 krw Exp $ */ /* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */ /*- @@ -209,14 +209,15 @@ sdattach(parent, self, aux) */ printf("\n"); + /* Spin up the unit ready or not. */ + scsi_start(sc_link, SSS_START, scsi_autoconf | SCSI_SILENT | + SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_MEDIA_CHANGE); + + /* Check that it is still responding and ok. */ error = scsi_test_unit_ready(sd->sc_link, TEST_READY_RETRIES_DEFAULT, scsi_autoconf | SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_MEDIA_CHANGE | SCSI_SILENT); - /* Spin up the unit ready or not. */ - error = scsi_start(sc_link, SSS_START, scsi_autoconf | SCSI_SILENT | - SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_MEDIA_CHANGE); - if (error) result = SDGP_RESULT_OFFLINE; else @@ -362,7 +363,16 @@ sdopen(dev, flag, fmt, p) goto bad; } } else { - /* Use sd_interpret_sense() for sense errors. */ + /* Spin up the unit, ready or not. */ + scsi_start(sc_link, SSS_START, (rawopen ? SCSI_SILENT : 0) | + SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_MEDIA_CHANGE); + + /* Use sd_interpret_sense() for sense errors. + * + * But only after spinning the disk up! Just in case a broken + * device returns "Initialization command required." and causes + * a loop of scsi_start() calls. + */ sc_link->flags |= SDEV_OPEN; /* Check that it is still responding and ok. */ @@ -370,11 +380,6 @@ sdopen(dev, flag, fmt, p) TEST_READY_RETRIES_DEFAULT, (rawopen ? SCSI_SILENT : 0) | SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_MEDIA_CHANGE); - /* Spin up the unit, ready or not. */ - error = scsi_start(sc_link, SSS_START, - (rawopen ? SCSI_SILENT : 0) | SCSI_IGNORE_ILLEGAL_REQUEST | - SCSI_IGNORE_MEDIA_CHANGE); - if (error) { if (rawopen) { error = 0; |