Subject: kern/13146: st detach support
To: None <gnats-bugs@gnats.netbsd.org>
From: None <takashi.yamamoto@bigfoot.com>
List: netbsd-bugs
Date: 06/09/2001 12:54:41
>Number: 13146
>Category: kern
>Synopsis: st detach support
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: kern-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Fri Jun 08 20:54:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: YAMAMOTO Takashi
>Release: 1.5W
>Organization:
>Environment:
System: NetBSD capybara 1.5W NetBSD 1.5W (stg) #276: Sat Jun 9 12:44:28 JST 2001 takashi@capybara:/usr/src/sys/arch/i386/compile/stg i386
Architecture: i386
Machine: i386
>Description:
patches to make st driver support detaching.
i'm not sure about atapi, though.
>How-To-Repeat:
>Fix:
Index: st.c
===================================================================
RCS file: /cvs/cvsroot/syssrc/sys/dev/scsipi/st.c,v
retrieving revision 1.140
diff -u -r1.140 st.c
--- st.c 2001/05/30 20:28:17 1.140
+++ st.c 2001/06/09 03:50:01
@@ -72,6 +72,7 @@
#include <sys/device.h>
#include <sys/conf.h>
#include <sys/kernel.h>
+#include <sys/vnode.h>
#include <dev/scsipi/scsi_all.h>
#include <dev/scsipi/scsi_tape.h>
@@ -84,6 +85,7 @@
#define STMODE(z) ( minor(z) & 0x03)
#define STDSTY(z) ((minor(z) >> 2) & 0x03)
#define STUNIT(z) ((minor(z) >> 4) )
+#define STNMINOR 16
#define NORMAL_MODE 0
#define NOREW_MODE 1
@@ -409,6 +411,74 @@
rnd_attach_source(&st->rnd_source, st->sc_dev.dv_xname,
RND_TYPE_TAPE, 0);
#endif
+}
+
+int
+stactivate(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
+stdetach(self, flags)
+ struct device *self;
+ int flags;
+{
+ struct st_softc *st = (struct st_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 == stopen)
+ break;
+ for (cmaj = 0; cmaj <= nchrdev; cmaj++)
+ if (cdevsw[cmaj].d_open == stopen)
+ break;
+
+ s = splbio();
+
+ /* Kill off any queued buffers. */
+ while ((bp = BUFQ_FIRST(&st->buf_queue)) != NULL) {
+ BUFQ_REMOVE(&st->buf_queue, bp);
+ 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(st->sc_periph);
+
+ splx(s);
+
+ /* Nuke the vnodes for any open instances */
+ mn = STUNIT(self->dv_unit);
+ vdevgone(bmaj, mn, mn+STNMINOR-1, VBLK);
+ vdevgone(cmaj, mn, mn+STNMINOR-1, VCHR);
+
+
+#if NRND > 0
+ /* Unhook the entropy source. */
+ rnd_detach_source(&st->rnd_source);
+#endif
+
+ return (0);
}
/*
Index: st_atapi.c
===================================================================
RCS file: /cvs/cvsroot/syssrc/sys/dev/scsipi/st_atapi.c,v
retrieving revision 1.1
diff -u -r1.1 st_atapi.c
--- st_atapi.c 2001/05/04 07:48:57 1.1
+++ st_atapi.c 2001/06/09 03:50:02
@@ -71,7 +71,8 @@
int st_atapibus_match __P((struct device *, struct cfdata *, void *));
struct cfattach st_atapibus_ca = {
- sizeof(struct st_softc), st_atapibus_match, stattach
+ sizeof(struct st_softc), st_atapibus_match, stattach,
+ stdetach, stactivate
};
const struct scsipi_inquiry_pattern st_atapibus_patterns[] = {
Index: st_scsi.c
===================================================================
RCS file: /cvs/cvsroot/syssrc/sys/dev/scsipi/st_scsi.c,v
retrieving revision 1.1
diff -u -r1.1 st_scsi.c
--- st_scsi.c 2001/05/04 07:48:57 1.1
+++ st_scsi.c 2001/06/09 03:50:03
@@ -71,7 +71,8 @@
int st_scsibus_match __P((struct device *, struct cfdata *, void *));
struct cfattach st_scsibus_ca = {
- sizeof(struct st_softc), st_scsibus_match, stattach
+ sizeof(struct st_softc), st_scsibus_match, stattach,
+ stdetach, stactivate
};
const struct scsipi_inquiry_pattern st_scsibus_patterns[] = {
Index: stvar.h
===================================================================
RCS file: /cvs/cvsroot/syssrc/sys/dev/scsipi/stvar.h,v
retrieving revision 1.1
diff -u -r1.1 stvar.h
--- stvar.h 2001/05/04 07:48:57 1.1
+++ stvar.h 2001/06/09 03:50:04
@@ -136,5 +136,7 @@
void stattach __P((struct device *, struct device *, void *));
+int stactivate __P((struct device *, enum devact));
+int stdetach __P((struct device *, int));
extern struct cfdriver st_cd;
>Release-Note:
>Audit-Trail:
>Unformatted: