Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/scsipi Do not manipulate xs->bp in "generic" code --...
details: https://anonhg.NetBSD.org/src/rev/cd37705acff9
branches: trunk
changeset: 570016:cd37705acff9
user: mycroft <mycroft%NetBSD.org@localhost>
date: Fri Sep 17 23:10:50 2004 +0000
description:
Do not manipulate xs->bp in "generic" code -- do it only in the psw_done
routine. As part of this, pass down our pre-parsed error code -- though this
interface will probably change later to accomodate better error handling.
diffstat:
sys/dev/scsipi/cd.c | 92 ++++++++++++++++---------------------------
sys/dev/scsipi/cdvar.h | 5 +-
sys/dev/scsipi/if_se.c | 12 ++---
sys/dev/scsipi/scsipi_base.c | 27 +-----------
sys/dev/scsipi/scsipiconf.h | 6 +-
sys/dev/scsipi/sd.c | 92 ++++++++++++++++---------------------------
sys/dev/scsipi/sdvar.h | 7 +-
sys/dev/scsipi/ss.c | 28 +++++++++++-
sys/dev/scsipi/st.c | 36 ++++++++++-------
9 files changed, 130 insertions(+), 175 deletions(-)
diffs (truncated from 745 to 300 lines):
diff -r b1ac607885c6 -r cd37705acff9 sys/dev/scsipi/cd.c
--- a/sys/dev/scsipi/cd.c Fri Sep 17 23:04:02 2004 +0000
+++ b/sys/dev/scsipi/cd.c Fri Sep 17 23:10:50 2004 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: cd.c,v 1.205 2004/09/09 19:35:30 bouyer Exp $ */
+/* $NetBSD: cd.c,v 1.206 2004/09/17 23:10:50 mycroft Exp $ */
/*-
- * Copyright (c) 1998, 2001, 2003 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 2001, 2003, 2004 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -54,7 +54,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.205 2004/09/09 19:35:30 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.206 2004/09/17 23:10:50 mycroft Exp $");
#include "rnd.h"
@@ -107,14 +107,12 @@
/* leadout */
};
-static int cdlock(struct cd_softc *);
-static void cdunlock(struct cd_softc *);
static void cdstart(struct scsipi_periph *);
static void cdrestart(void *);
static void cdminphys(struct buf *);
static void cdgetdefaultlabel(struct cd_softc *, struct disklabel *);
static void cdgetdisklabel(struct cd_softc *);
-static void cddone(struct scsipi_xfer *);
+static void cddone(struct scsipi_xfer *, int);
static void cdbounce(struct buf *);
static int cd_interpret_sense(struct scsipi_xfer *);
static u_long cd_size(struct cd_softc *, int);
@@ -225,6 +223,8 @@
SC_DEBUG(periph, SCSIPI_DB2, ("cdattach: "));
+ lockinit(&cd->sc_lock, PRIBIO | PCATCH, "cdlock", 0, 0);
+
if (scsipi_periph_bustype(sa->sa_periph) == SCSIPI_BUSTYPE_SCSI &&
periph->periph_version == 0)
cd->flags |= CDF_ANCIENT;
@@ -295,6 +295,13 @@
bmaj = bdevsw_lookup_major(&cd_bdevsw);
cmaj = cdevsw_lookup_major(&cd_cdevsw);
+ /* Nuke the vnodes for any open instances */
+ for (i = 0; i < MAXPARTITIONS; i++) {
+ mn = CDMINOR(self->dv_unit, i);
+ vdevgone(bmaj, mn, mn, VBLK);
+ vdevgone(cmaj, mn, mn, VCHR);
+ }
+
/* kill any pending restart */
callout_stop(&cd->sc_callout);
@@ -315,12 +322,7 @@
splx(s);
- /* Nuke the vnodes for any open instances */
- for (i = 0; i < MAXPARTITIONS; i++) {
- mn = CDMINOR(self->dv_unit, i);
- vdevgone(bmaj, mn, mn, VBLK);
- vdevgone(cmaj, mn, mn, VCHR);
- }
+ lockmgr(&cd->sc_lock, LK_DRAIN, 0);
/* Detach from the disk list. */
disk_detach(&cd->sc_dk);
@@ -340,40 +342,6 @@
}
/*
- * Wait interruptibly for an exclusive lock.
- *
- * XXX
- * Several drivers do this; it should be abstracted and made MP-safe.
- */
-static int
-cdlock(struct cd_softc *cd)
-{
- int error;
-
- while ((cd->flags & CDF_LOCKED) != 0) {
- cd->flags |= CDF_WANTED;
- if ((error = tsleep(cd, PRIBIO | PCATCH, "cdlck", 0)) != 0)
- return (error);
- }
- cd->flags |= CDF_LOCKED;
- return (0);
-}
-
-/*
- * Unlock and wake up any waiters.
- */
-static void
-cdunlock(struct cd_softc *cd)
-{
-
- cd->flags &= ~CDF_LOCKED;
- if ((cd->flags & CDF_WANTED) != 0) {
- cd->flags &= ~CDF_WANTED;
- wakeup(cd);
- }
-}
-
-/*
* open the device. Make sure the partition info is a up-to-date as can be.
*/
static int
@@ -408,7 +376,7 @@
(error = scsipi_adapter_addref(adapt)) != 0)
return (error);
- if ((error = cdlock(cd)) != 0)
+ if ((error = lockmgr(&cd->sc_lock, LK_EXCLUSIVE, NULL)) != 0)
goto bad4;
if ((periph->periph_flags & PERIPH_OPEN) != 0) {
@@ -508,7 +476,7 @@
cd->sc_dk.dk_copenmask | cd->sc_dk.dk_bopenmask;
SC_DEBUG(periph, SCSIPI_DB3, ("open complete\n"));
- cdunlock(cd);
+ lockmgr(&cd->sc_lock, LK_RELEASE, NULL);
return (0);
bad2:
@@ -522,7 +490,7 @@
}
bad3:
- cdunlock(cd);
+ lockmgr(&cd->sc_lock, LK_RELEASE, NULL);
bad4:
if (cd->sc_dk.dk_openmask == 0)
scsipi_adapter_delref(adapt);
@@ -542,7 +510,7 @@
int part = CDPART(dev);
int error;
- if ((error = cdlock(cd)) != 0)
+ if ((error = lockmgr(&cd->sc_lock, LK_EXCLUSIVE, NULL)) != 0)
return (error);
switch (fmt) {
@@ -569,7 +537,7 @@
scsipi_adapter_delref(adapt);
}
- cdunlock(cd);
+ lockmgr(&cd->sc_lock, LK_RELEASE, NULL);
return (0);
}
@@ -908,16 +876,24 @@
}
static void
-cddone(struct scsipi_xfer *xs)
+cddone(struct scsipi_xfer *xs, int error)
{
struct cd_softc *cd = (void *)xs->xs_periph->periph_dev;
+ struct buf *bp = xs->bp;
- if (xs->bp != NULL) {
- disk_unbusy(&cd->sc_dk, xs->bp->b_bcount - xs->bp->b_resid,
- (xs->bp->b_flags & B_READ));
+ if (bp) {
+ bp->b_error = error;
+ bp->b_resid = xs->resid;
+ if (error)
+ bp->b_flags |= B_ERROR;
+
+ disk_unbusy(&cd->sc_dk, bp->b_bcount - bp->b_resid,
+ (bp->b_flags & B_READ));
#if NRND > 0
- rnd_add_uint32(&cd->rnd_source, xs->bp->b_rawblkno);
+ rnd_add_uint32(&cd->rnd_source, bp->b_rawblkno);
#endif
+
+ biodone(bp);
}
}
@@ -1253,7 +1229,7 @@
#endif
lp = (struct disklabel *)addr;
- if ((error = cdlock(cd)) != 0)
+ if ((error = lockmgr(&cd->sc_lock, LK_EXCLUSIVE, NULL)) != 0)
goto bad;
cd->flags |= CDF_LABELLING;
@@ -1265,7 +1241,7 @@
}
cd->flags &= ~CDF_LABELLING;
- cdunlock(cd);
+ lockmgr(&cd->sc_lock, LK_RELEASE, NULL);
bad:
#ifdef __HAVE_OLD_DISKLABEL
if (newlabel != NULL)
diff -r b1ac607885c6 -r cd37705acff9 sys/dev/scsipi/cdvar.h
--- a/sys/dev/scsipi/cdvar.h Fri Sep 17 23:04:02 2004 +0000
+++ b/sys/dev/scsipi/cdvar.h Fri Sep 17 23:10:50 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cdvar.h,v 1.21 2004/08/27 20:37:28 bouyer Exp $ */
+/* $NetBSD: cdvar.h,v 1.22 2004/09/17 23:10:50 mycroft Exp $ */
/*
* Copyright (c) 1997 Manuel Bouyer. All rights reserved.
@@ -34,10 +34,9 @@
struct cd_softc {
struct device sc_dev;
struct disk sc_dk;
+ struct lock sc_lock;
int flags;
-#define CDF_LOCKED 0x01
-#define CDF_WANTED 0x02
#define CDF_WLABEL 0x04 /* label is writable */
#define CDF_LABELLING 0x08 /* writing label */
#define CDF_ANCIENT 0x10 /* disk is ancient; for minphys */
diff -r b1ac607885c6 -r cd37705acff9 sys/dev/scsipi/if_se.c
--- a/sys/dev/scsipi/if_se.c Fri Sep 17 23:04:02 2004 +0000
+++ b/sys/dev/scsipi/if_se.c Fri Sep 17 23:10:50 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_se.c,v 1.47 2004/09/09 19:35:30 bouyer Exp $ */
+/* $NetBSD: if_se.c,v 1.48 2004/09/17 23:10:50 mycroft Exp $ */
/*
* Copyright (c) 1997 Ian W. Dall <ian.dall%dsto.defence.gov.au@localhost>
@@ -59,7 +59,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.47 2004/09/09 19:35:30 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.48 2004/09/17 23:10:50 mycroft Exp $");
#include "opt_inet.h"
#include "opt_atalk.h"
@@ -212,7 +212,7 @@
static void se_ifstart __P((struct ifnet *));
static void sestart __P((struct scsipi_periph *));
-static void sedone __P((struct scsipi_xfer *));
+static void sedone __P((struct scsipi_xfer *, int));
static int se_ioctl __P((struct ifnet *, u_long, caddr_t));
static void sewatchdog __P((struct ifnet *));
@@ -504,17 +504,15 @@
* Called from the scsibus layer via our scsi device switch.
*/
static void
-sedone(xs)
+sedone(xs, error)
struct scsipi_xfer *xs;
+ int error;
{
- int error;
struct se_softc *sc = (void *)xs->xs_periph->periph_dev;
struct scsipi_generic *cmd = xs->cmd;
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
int s;
- error = !(xs->error == XS_NOERROR);
-
s = splnet();
if(IS_SEND(cmd)) {
if (xs->error == XS_BUSY) {
diff -r b1ac607885c6 -r cd37705acff9 sys/dev/scsipi/scsipi_base.c
--- a/sys/dev/scsipi/scsipi_base.c Fri Sep 17 23:04:02 2004 +0000
+++ b/sys/dev/scsipi/scsipi_base.c Fri Sep 17 23:10:50 2004 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: scsipi_base.c,v 1.112 2004/09/09 19:35:31 bouyer Exp $ */
+/* $NetBSD: scsipi_base.c,v 1.113 2004/09/17 23:10:50 mycroft Exp $ */
/*-
- * Copyright (c) 1998, 1999, 2000, 2002, 2003 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 1999, 2000, 2002, 2003, 2004 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.112 2004/09/09 19:35:31 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.113 2004/09/17 23:10:50 mycroft Exp $");
#include "opt_scsi.h"
@@ -1444,7 +1444,6 @@
Home |
Main Index |
Thread Index |
Old Index