From 4659caa469c2dedd9d5063417c8da7cc4e37d7aa Mon Sep 17 00:00:00 2001 From: sos Date: Wed, 14 Mar 2001 12:05:44 +0000 Subject: Refine the detach/attach code. Proberly fail outstanding bio requests on devices that are detached. This makes it possible to change between disk/cdrom/dvd/whathaveyou in a notebook, just by suspending it, changing the device in the bay (or what you model calls it), unsuspend and the ATA driver will figure out what disappeared and properly fail those, and attach any new devices found. --- sys/dev/ata/atapi-tape.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'sys/dev/ata/atapi-tape.c') diff --git a/sys/dev/ata/atapi-tape.c b/sys/dev/ata/atapi-tape.c index af3e7af..7fa8fc5 100644 --- a/sys/dev/ata/atapi-tape.c +++ b/sys/dev/ata/atapi-tape.c @@ -101,7 +101,7 @@ astattach(struct atapi_softc *atp) printf("ast: out of memory\n"); return -1; } - bioq_init(&stp->bio_queue); + bioq_init(&stp->queue); stp->atp = atp; stp->lun = ata_get_lun(&ast_lun_map); if (ast_sense(stp)) { @@ -151,7 +151,13 @@ void astdetach(struct atapi_softc *atp) { struct ast_softc *stp = atp->driver; + struct bio *bp; + while ((bp = bioq_first(&stp->queue))) { + bp->bio_error = ENXIO; + bp->bio_flags |= BIO_ERROR; + biodone(bp); + } destroy_dev(stp->dev1); destroy_dev(stp->dev2); devstat_remove_entry(&stp->stats); @@ -414,6 +420,13 @@ aststrategy(struct bio *bp) struct ast_softc *stp = bp->bio_dev->si_drv1; int s; + if (stp->atp->flags & ATAPI_F_DETACHING) { + bp->bio_error = ENXIO; + bp->bio_flags |= BIO_ERROR; + biodone(bp); + return; + } + /* if it's a null transfer, return immediatly. */ if (bp->bio_bcount == 0) { bp->bio_resid = 0; @@ -447,7 +460,7 @@ aststrategy(struct bio *bp) } s = splbio(); - bioq_insert_tail(&stp->bio_queue, bp); + bioq_insert_tail(&stp->queue, bp); ata_start(stp->atp->controller); splx(s); } @@ -456,7 +469,7 @@ void ast_start(struct atapi_softc *atp) { struct ast_softc *stp = atp->driver; - struct bio *bp = bioq_first(&stp->bio_queue); + struct bio *bp = bioq_first(&stp->queue); u_int32_t blkcount; int8_t ccb[16]; @@ -470,7 +483,7 @@ ast_start(struct atapi_softc *atp) else ccb[0] = ATAPI_WRITE; - bioq_remove(&stp->bio_queue, bp); + bioq_remove(&stp->queue, bp); blkcount = bp->bio_bcount / stp->blksize; ccb[1] = 1; -- cgit v1.1