diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2007-03-25 18:02:38 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2007-03-25 18:02:38 +0000 |
commit | c670dd91e076dfadb95c3b7f6a4be3ef7c6a5fe1 (patch) | |
tree | ffb265f097ca3dab6428c112f2a5ea51337eab7e | |
parent | 30dc9e31de293d613a88a45085166c1affa3da2e (diff) |
use a rwlock instead of the homegrown approach
ok art pedro thib
-rw-r--r-- | sys/dev/vnd.c | 47 |
1 files changed, 8 insertions, 39 deletions
diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c index 2e8c3e37640..49225c16800 100644 --- a/sys/dev/vnd.c +++ b/sys/dev/vnd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vnd.c,v 1.70 2007/02/26 11:25:23 pedro Exp $ */ +/* $OpenBSD: vnd.c,v 1.71 2007/03/25 18:02:37 tedu Exp $ */ /* $NetBSD: vnd.c,v 1.26 1996/03/30 23:06:11 christos Exp $ */ /* @@ -132,13 +132,12 @@ struct vnd_softc { struct ucred *sc_cred; /* credentials */ struct buf sc_tab; /* transfer queue */ blf_ctx *sc_keyctx; /* key context */ + struct rwlock sc_rwlock; }; /* sc_flags */ #define VNF_ALIVE 0x0001 #define VNF_INITED 0x0002 -#define VNF_WANTED 0x0040 -#define VNF_LOCKED 0x0080 #define VNF_LABELLING 0x0100 #define VNF_WLABEL 0x0200 #define VNF_HAVELABEL 0x0400 @@ -163,8 +162,8 @@ void vndshutdown(void); void vndgetdisklabel(dev_t, struct vnd_softc *); void vndencrypt(struct vnd_softc *, caddr_t, size_t, daddr_t, int); -int vndlock(struct vnd_softc *); -void vndunlock(struct vnd_softc *); +#define vndlock(sc) rw_enter(&sc->sc_rwlock, RW_WRITE|RW_INTR) +#define vndunlock(sc) rw_exit_write(&sc->sc_rwlock) void vndencrypt(struct vnd_softc *vnd, caddr_t addr, size_t size, daddr_t off, @@ -193,6 +192,7 @@ vndattach(int num) { char *mem; u_long size; + int i; if (num <= 0) return; @@ -204,6 +204,9 @@ vndattach(int num) } bzero(mem, size); vnd_softc = (struct vnd_softc *)mem; + for (i = 0; i < num; i++) { + rw_init(&vnd_softc[i].sc_rwlock, "vndlock"); + } numvnd = num; pool_init(&vndbufpl, sizeof(struct vndbuf), 0, 0, 0, "vndbufpl", NULL); @@ -1017,37 +1020,3 @@ vnddump(dev_t dev, daddr_t blkno, caddr_t va, size_t size) /* Not implemented. */ return (ENXIO); } - -/* - * Wait interruptibly for an exclusive lock. - * - * XXX - * Several drivers do this; it should be abstracted and made MP-safe. - */ -int -vndlock(struct vnd_softc *sc) -{ - int error; - - while ((sc->sc_flags & VNF_LOCKED) != 0) { - sc->sc_flags |= VNF_WANTED; - if ((error = tsleep(sc, PRIBIO | PCATCH, "vndlck", 0)) != 0) - return (error); - } - sc->sc_flags |= VNF_LOCKED; - return (0); -} - -/* - * Unlock and wake up any waiters. - */ -void -vndunlock(struct vnd_softc *sc) -{ - - sc->sc_flags &= ~VNF_LOCKED; - if ((sc->sc_flags & VNF_WANTED) != 0) { - sc->sc_flags &= ~VNF_WANTED; - wakeup(sc); - } -} |