diff options
author | ken <ken@FreeBSD.org> | 1998-10-22 22:16:56 +0000 |
---|---|---|
committer | ken <ken@FreeBSD.org> | 1998-10-22 22:16:56 +0000 |
commit | 123c4e574210364558b003c3b4308600a6cbdf16 (patch) | |
tree | 37676d718bb5ecd358f7101d2d5f0f9d60810f82 /sys/cam/scsi/scsi_ch.c | |
parent | c4aa0cf6f77d3320883b9363e359ae996632fb1a (diff) | |
download | FreeBSD-src-123c4e574210364558b003c3b4308600a6cbdf16.zip FreeBSD-src-123c4e574210364558b003c3b4308600a6cbdf16.tar.gz |
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
Diffstat (limited to 'sys/cam/scsi/scsi_ch.c')
-rw-r--r-- | sys/cam/scsi/scsi_ch.c | 87 |
1 files changed, 45 insertions, 42 deletions
diff --git a/sys/cam/scsi/scsi_ch.c b/sys/cam/scsi/scsi_ch.c index 1f16eb3..32bb92d 100644 --- a/sys/cam/scsi/scsi_ch.c +++ b/sys/cam/scsi/scsi_ch.c @@ -24,7 +24,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: scsi_ch.c,v 1.3 1998/10/02 21:20:21 ken Exp $ + * $Id: scsi_ch.c,v 1.4 1998/10/15 17:46:26 ken Exp $ */ /* * Derived from the NetBSD SCSI changer driver. @@ -183,6 +183,7 @@ static d_close_t chclose; static d_ioctl_t chioctl; static periph_init_t chinit; static periph_ctor_t chregister; +static periph_oninv_t choninvalidate; static periph_dtor_t chcleanup; static periph_start_t chstart; static void chasync(void *callback_arg, u_int32_t code, @@ -286,13 +287,43 @@ chinit(void) } static void +choninvalidate(struct cam_periph *periph) +{ + struct ch_softc *softc; + struct ccb_setasync csa; + + softc = (struct ch_softc *)periph->softc; + + /* + * De-register any async callbacks. + */ + xpt_setup_ccb(&csa.ccb_h, periph->path, + /* priority */ 5); + csa.ccb_h.func_code = XPT_SASYNC_CB; + csa.event_enable = 0; + csa.callback = chasync; + csa.callback_arg = periph; + xpt_action((union ccb *)&csa); + + softc->flags |= CH_FLAG_INVALID; + + xpt_print_path(periph->path); + printf("lost device\n"); + +} + +static void chcleanup(struct cam_periph *periph) { + struct ch_softc *softc; + + softc = (struct ch_softc *)periph->softc; - cam_extend_release(chperiphs, periph->unit_number); - xpt_print_path(periph->path); - printf("removing device entry\n"); - free(periph->softc, M_DEVBUF); + devstat_remove_entry(&softc->device_stats); + cam_extend_release(chperiphs, periph->unit_number); + xpt_print_path(periph->path); + printf("removing device entry\n"); + free(softc, M_DEVBUF); } static void @@ -318,8 +349,9 @@ chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg) * this device and start the probe * process. */ - status = cam_periph_alloc(chregister, chcleanup, chstart, - "ch", CAM_PERIPH_BIO, cgd->ccb_h.path, + status = cam_periph_alloc(chregister, choninvalidate, + chcleanup, chstart, "ch", + CAM_PERIPH_BIO, cgd->ccb_h.path, chasync, AC_FOUND_DEVICE, cgd); if (status != CAM_REQ_CMP @@ -331,42 +363,8 @@ chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg) } case AC_LOST_DEVICE: - { - int s; - struct ch_softc *softc; - struct ccb_setasync csa; - - softc = (struct ch_softc *)periph->softc; - - /* - * Insure that no other async callbacks that - * might affect this peripheral can come through. - */ - s = splcam(); - - /* - * De-register any async callbacks. - */ - xpt_setup_ccb(&csa.ccb_h, periph->path, - /* priority */ 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = 0; - csa.callback = chasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); - - softc->flags |= CH_FLAG_INVALID; - - devstat_remove_entry(&softc->device_stats); - - xpt_print_path(periph->path); - printf("lost device\n"); - - splx(s); - cam_periph_invalidate(periph); break; - } case AC_TRANSFER_NEG: case AC_SENT_BDR: case AC_SCSI_AEN: @@ -445,6 +443,7 @@ chopen(dev_t dev, int flags, int fmt, struct proc *p) struct cam_periph *periph; struct ch_softc *softc; int unit, error; + int s; unit = CHUNIT(dev); periph = cam_extend_get(chperiphs, unit); @@ -454,8 +453,12 @@ chopen(dev_t dev, int flags, int fmt, struct proc *p) softc = (struct ch_softc *)periph->softc; - if (softc->flags & CH_FLAG_INVALID) + s = splsoftcam(); + if (softc->flags & CH_FLAG_INVALID) { + splx(s); return(ENXIO); + } + splx(s); if ((error = cam_periph_lock(periph, PRIBIO | PCATCH)) != 0) return (error); |