Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/scsipi Implement detaching SCSI and ATAPI disks.



details:   https://anonhg.NetBSD.org/src/rev/6c726d04a03e
branches:  trunk
changeset: 476274:6c726d04a03e
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Sep 11 21:42:58 1999 +0000

description:
Implement detaching SCSI and ATAPI disks.

diffstat:

 sys/dev/scsipi/sd.c       |  91 +++++++++++++++++++++++++++++++++++++++++++++-
 sys/dev/scsipi/sd_atapi.c |   5 +-
 sys/dev/scsipi/sd_scsi.c  |   5 +-
 sys/dev/scsipi/sdvar.h    |   4 +-
 4 files changed, 98 insertions(+), 7 deletions(-)

diffs (200 lines):

diff -r 688f5246a303 -r 6c726d04a03e sys/dev/scsipi/sd.c
--- a/sys/dev/scsipi/sd.c       Sat Sep 11 21:39:53 1999 +0000
+++ b/sys/dev/scsipi/sd.c       Sat Sep 11 21:42:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sd.c,v 1.146 1999/08/26 09:28:17 hannken Exp $ */
+/*     $NetBSD: sd.c,v 1.147 1999/09/11 21:42:58 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -73,6 +73,7 @@
 #include <sys/disk.h>
 #include <sys/proc.h>
 #include <sys/conf.h>
+#include <sys/vnode.h>
 #if NRND > 0
 #include <sys/rnd.h>
 #endif
@@ -221,6 +222,79 @@
 #endif
 }
 
+int
+sdactivate(self, act)
+       struct device *self;
+       enum devact act;
+{
+       int rv = 0;
+
+       switch (act) {
+       case DVACT_ACTIVATE:
+               rv = EOPNOTSUPP;
+               break;
+
+       case DVACT_DEACTIVATE:
+               /*
+                * Nothing to do; we key off the device's DVF_ACTIVE.
+                */
+               break;
+       }
+       return (rv);
+}
+
+int
+sddetach(self, flags)
+       struct device *self;
+       int flags;
+{
+       struct sd_softc *sd = (struct sd_softc *) self;
+       struct buf *bp;
+       int s, bmaj, cmaj, mn;
+
+       /* locate the major number */
+       for (bmaj = 0; bmaj <= nblkdev; bmaj++)
+               if (bdevsw[bmaj].d_open == sdopen)
+                       break;
+       for (cmaj = 0; cmaj <= nchrdev; cmaj++)
+               if (cdevsw[cmaj].d_open == sdopen)
+                       break;
+
+       s = splbio();
+
+       /* Kill off any queued buffers. */
+       while ((bp = sd->buf_queue.b_actf) != NULL) {
+               sd->buf_queue.b_actf = bp->b_actf;
+               bp->b_error = EIO;
+               bp->b_flags |= B_ERROR;
+               bp->b_resid = bp->b_bcount;
+               biodone(bp);
+       }
+
+       /* Kill off any pending commands. */
+       scsipi_kill_pending(sd->sc_link);
+
+       splx(s);
+
+       /* Nuke the the vnodes for any open instances */
+       mn = self->dv_unit;
+       vdevgone(bmaj, mn, mn + (MAXPARTITIONS - 1), VBLK);
+       vdevgone(cmaj, mn, mn + (MAXPARTITIONS - 1), VCHR);
+
+       /* Detach from the disk list. */
+       disk_detach(&sd->sc_dk);
+
+       /* Get rid of the shutdown hook. */
+       shutdownhook_disestablish(sd->sc_sdhook);
+
+#if NRND > 0
+       /* Unhook the entropy source. */
+       rnd_detach_source(&sd->rnd_source);
+#endif
+
+       return (0);
+}
+
 /*
  * Wait interruptibly for an exclusive lock.
  *
@@ -278,6 +352,9 @@
        if (sd == NULL)
                return (ENXIO);
 
+       if ((sd->sc_dev.dv_flags & DVF_ACTIVE) == 0)
+               return (ENODEV);
+
        sc_link = sd->sc_link;
        part = SDPART(dev);
 
@@ -479,7 +556,8 @@
        /*
         * If the device has been made invalid, error out
         */
-       if ((sd->sc_link->flags & SDEV_MEDIA_LOADED) == 0) {
+       if ((sd->sc_link->flags & SDEV_MEDIA_LOADED) == 0 ||
+           (sd->sc_dev.dv_flags & DVF_ACTIVE) == 0) {
                if (sd->sc_link->flags & SDEV_OPEN)
                        bp->b_error = EIO;
                else
@@ -762,6 +840,9 @@
 
        SC_DEBUG(sd->sc_link, SDEV_DB2, ("sdioctl 0x%lx ", cmd));
 
+       if ((sd->sc_dev.dv_flags & DVF_ACTIVE) == 0)
+               return (ENODEV);
+
        /*
         * If the device is not valid, some IOCTLs can still be
         * handled on the raw partition. Check this here.
@@ -1073,6 +1154,9 @@
        if (sd == NULL)
                return (-1);
 
+       if ((sd->sc_dev.dv_flags & DVF_ACTIVE) == 0)
+               return (-1);
+
        part = SDPART(dev);
        omask = sd->sc_dk.dk_openmask & (1 << part);
 
@@ -1118,6 +1202,9 @@
        struct scsipi_xfer *xs; /* ... convenience */
        int     retval;
 
+       if ((sd->sc_dev.dv_flags & DVF_ACTIVE) == 0)
+               return (ENODEV);
+
        /* Check if recursive dump; if so, punt. */
        if (sddoingadump)
                return (EFAULT);
diff -r 688f5246a303 -r 6c726d04a03e sys/dev/scsipi/sd_atapi.c
--- a/sys/dev/scsipi/sd_atapi.c Sat Sep 11 21:39:53 1999 +0000
+++ b/sys/dev/scsipi/sd_atapi.c Sat Sep 11 21:42:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sd_atapi.c,v 1.3 1998/08/31 22:28:07 cgd Exp $ */
+/*     $NetBSD: sd_atapi.c,v 1.4 1999/09/11 21:42:58 thorpej Exp $     */
 
 /*
  * Copyright 1998
@@ -61,7 +61,8 @@
 void   sd_atapibus_attach __P((struct device *, struct device *, void *));
 
 struct cfattach sd_atapibus_ca = {
-       sizeof(struct sd_softc), sd_atapibus_match, sd_atapibus_attach
+       sizeof(struct sd_softc), sd_atapibus_match, sd_atapibus_attach,
+       sddetach, sdactivate,
 };
 
 struct scsipi_inquiry_pattern sd_atapibus_patterns[] = {
diff -r 688f5246a303 -r 6c726d04a03e sys/dev/scsipi/sd_scsi.c
--- a/sys/dev/scsipi/sd_scsi.c  Sat Sep 11 21:39:53 1999 +0000
+++ b/sys/dev/scsipi/sd_scsi.c  Sat Sep 11 21:42:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sd_scsi.c,v 1.9 1999/08/26 09:28:18 hannken Exp $      */
+/*     $NetBSD: sd_scsi.c,v 1.10 1999/09/11 21:42:58 thorpej Exp $     */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -75,7 +75,8 @@
 void   sd_scsibus_attach __P((struct device *, struct device *, void *));
 
 struct cfattach sd_scsibus_ca = {
-       sizeof(struct sd_softc), sd_scsibus_match, sd_scsibus_attach
+       sizeof(struct sd_softc), sd_scsibus_match, sd_scsibus_attach,
+       sddetach, sdactivate,
 };
 
 struct scsipi_inquiry_pattern sd_scsibus_patterns[] = {
diff -r 688f5246a303 -r 6c726d04a03e sys/dev/scsipi/sdvar.h
--- a/sys/dev/scsipi/sdvar.h    Sat Sep 11 21:39:53 1999 +0000
+++ b/sys/dev/scsipi/sdvar.h    Sat Sep 11 21:42:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sdvar.h,v 1.8 1999/08/26 09:28:18 hannken Exp $        */
+/*     $NetBSD: sdvar.h,v 1.9 1999/09/11 21:42:58 thorpej Exp $        */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -101,3 +101,5 @@
 
 void sdattach __P((struct device *, struct sd_softc *, struct scsipi_link *,
     const struct sd_ops *));
+int sdactivate __P((struct device *, enum devact));
+int sddetach __P((struct device *, int));



Home | Main Index | Thread Index | Old Index