summaryrefslogtreecommitdiffstats
path: root/sys/dev
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ata/wd.c18
-rw-r--r--sys/dev/flash.c18
-rw-r--r--sys/dev/vnd.c41
3 files changed, 34 insertions, 43 deletions
diff --git a/sys/dev/ata/wd.c b/sys/dev/ata/wd.c
index c24e4643394..145a42256b5 100644
--- a/sys/dev/ata/wd.c
+++ b/sys/dev/ata/wd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wd.c,v 1.103 2011/06/05 18:40:33 matthew Exp $ */
+/* $OpenBSD: wd.c,v 1.104 2011/06/19 04:35:06 deraadt Exp $ */
/* $NetBSD: wd.c,v 1.193 1999/02/28 17:15:27 explorer Exp $ */
/*
@@ -148,8 +148,6 @@ void wd_shutdown(void *);
cdev_decl(wd);
bdev_decl(wd);
-#define wdlock(wd) disk_lock(&(wd)->sc_dk)
-#define wdunlock(wd) disk_unlock(&(wd)->sc_dk)
#define wdlookup(unit) (struct wd_softc *)disk_lookup(&wd_cd, (unit))
@@ -666,7 +664,7 @@ wdopen(dev_t dev, int flag, int fmt, struct proc *p)
* If this is the first open of this device, add a reference
* to the adapter.
*/
- if ((error = wdlock(wd)) != 0)
+ if ((error = disk_lock(&wd->sc_dk)) != 0)
goto bad4;
if (wd->sc_dk.dk_openmask != 0) {
@@ -716,7 +714,7 @@ wdopen(dev_t dev, int flag, int fmt, struct proc *p)
wd->sc_dk.dk_openmask =
wd->sc_dk.dk_copenmask | wd->sc_dk.dk_bopenmask;
- wdunlock(wd);
+ disk_unlock(&wd->sc_dk);
device_unref(&wd->sc_dev);
return 0;
@@ -725,7 +723,7 @@ bad:
}
bad3:
- wdunlock(wd);
+ disk_unlock(&wd->sc_dk);
bad4:
device_unref(&wd->sc_dev);
return error;
@@ -743,7 +741,7 @@ wdclose(dev_t dev, int flag, int fmt, struct proc *p)
return ENXIO;
WDCDEBUG_PRINT(("wdclose\n"), DEBUG_FUNCS);
- if ((error = wdlock(wd)) != 0)
+ if ((error = disk_lock(&wd->sc_dk)) != 0)
goto exit;
switch (fmt) {
@@ -762,7 +760,7 @@ wdclose(dev_t dev, int flag, int fmt, struct proc *p)
/* XXXX Must wait for I/O to complete! */
}
- wdunlock(wd);
+ disk_unlock(&wd->sc_dk);
exit:
device_unref(&wd->sc_dev);
@@ -867,7 +865,7 @@ wdioctl(dev_t dev, u_long xfer, caddr_t addr, int flag, struct proc *p)
goto exit;
}
- if ((error = wdlock(wd)) != 0)
+ if ((error = disk_lock(&wd->sc_dk)) != 0)
goto exit;
error = setdisklabel(wd->sc_dk.dk_label,
@@ -880,7 +878,7 @@ wdioctl(dev_t dev, u_long xfer, caddr_t addr, int flag, struct proc *p)
wdstrategy, wd->sc_dk.dk_label);
}
- wdunlock(wd);
+ disk_unlock(&wd->sc_dk);
goto exit;
#ifdef notyet
diff --git a/sys/dev/flash.c b/sys/dev/flash.c
index 965052e5bfa..497ce1e659f 100644
--- a/sys/dev/flash.c
+++ b/sys/dev/flash.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: flash.c,v 1.21 2011/06/03 21:14:11 matthew Exp $ */
+/* $OpenBSD: flash.c,v 1.22 2011/06/19 04:35:03 deraadt Exp $ */
/*
* Copyright (c) 2005 Uwe Stuehler <uwe@openbsd.org>
@@ -54,8 +54,6 @@ int flash_wait_complete(struct flash_softc *);
cdev_decl(flash);
bdev_decl(flash);
-#define flashlock(sc) disk_lock(&(sc)->sc_dk)
-#define flashunlock(sc) disk_unlock(&(sc)->sc_dk)
#define flashlookup(unit) \
(struct flash_softc *)device_lookup(&flash_cd, (unit))
@@ -678,7 +676,7 @@ flashopen(dev_t dev, int oflags, int devtype, struct proc *p)
if (sc == NULL)
return ENXIO;
- if ((error = flashlock(sc)) != 0) {
+ if ((error = disk_lock(&sc->sc_dk)) != 0) {
device_unref(&sc->sc_dev);
return error;
}
@@ -698,14 +696,14 @@ flashopen(dev_t dev, int oflags, int devtype, struct proc *p)
sc->sc_flags |= FDK_SAFE;
if ((error = flashgetdisklabel(dev, sc,
sc->sc_dk.dk_label, 0)) != 0) {
- flashunlock(sc);
+ disk_unlock(&sc->sc_dk);
device_unref(&sc->sc_dev);
return error;
}
}
} else if (((sc->sc_flags & FDK_SAFE) == 0) !=
(flashsafe(dev) == 0)) {
- flashunlock(sc);
+ disk_unlock(&sc->sc_dk);
device_unref(&sc->sc_dev);
return EBUSY;
}
@@ -715,7 +713,7 @@ flashopen(dev_t dev, int oflags, int devtype, struct proc *p)
if (part != RAW_PART &&
(part >= sc->sc_dk.dk_label->d_npartitions ||
sc->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) {
- flashunlock(sc);
+ disk_unlock(&sc->sc_dk);
device_unref(&sc->sc_dev);
return ENXIO;
}
@@ -732,7 +730,7 @@ flashopen(dev_t dev, int oflags, int devtype, struct proc *p)
sc->sc_dk.dk_openmask =
sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
- flashunlock(sc);
+ disk_unlock(&sc->sc_dk);
device_unref(&sc->sc_dev);
return 0;
}
@@ -748,7 +746,7 @@ flashclose(dev_t dev, int fflag, int devtype, struct proc *p)
if (sc == NULL)
return ENXIO;
- if ((error = flashlock(sc)) != 0) {
+ if ((error = disk_lock(&sc->sc_dk)) != 0) {
device_unref(&sc->sc_dev);
return error;
}
@@ -770,7 +768,7 @@ flashclose(dev_t dev, int fflag, int devtype, struct proc *p)
/* XXX wait for I/O to complete? */
}
- flashunlock(sc);
+ disk_unlock(&sc->sc_dk);
device_unref(&sc->sc_dev);
return 0;
}
diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c
index 75c91dab9d3..9d0199deb3d 100644
--- a/sys/dev/vnd.c
+++ b/sys/dev/vnd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vnd.c,v 1.128 2011/06/19 04:29:41 deraadt Exp $ */
+/* $OpenBSD: vnd.c,v 1.129 2011/06/19 04:35:03 deraadt Exp $ */
/* $NetBSD: vnd.c,v 1.26 1996/03/30 23:06:11 christos Exp $ */
/*
@@ -61,7 +61,6 @@
#include <sys/mount.h>
#include <sys/vnode.h>
#include <sys/file.h>
-#include <sys/rwlock.h>
#include <sys/uio.h>
#include <sys/conf.h>
#include <sys/dkio.h>
@@ -105,7 +104,6 @@ struct vnd_softc {
struct vnode *sc_vp; /* vnode */
struct ucred *sc_cred; /* credentials */
blf_ctx *sc_keyctx; /* key context */
- struct rwlock sc_rwlock;
};
/* sc_flags */
@@ -128,9 +126,6 @@ int vndgetdisklabel(dev_t, struct vnd_softc *, struct disklabel *, int);
void vndencrypt(struct vnd_softc *, caddr_t, size_t, daddr64_t, int);
size_t vndbdevsize(struct vnode *, struct proc *);
-#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 *sc, caddr_t addr, size_t size, daddr64_t off,
int encrypt)
@@ -172,10 +167,10 @@ vndattach(int num)
for (i = 0; i < num; i++) {
struct vnd_softc *sc = &vnd_softc[i];
- rw_init(&sc->sc_rwlock, "vndlock");
sc->sc_dev.dv_unit = i;
snprintf(sc->sc_dev.dv_xname, sizeof(sc->sc_dev.dv_xname),
"vnd%d", i);
+ disk_construct(&sc->sc_dk);
device_ref(&sc->sc_dev);
}
numvnd = num;
@@ -194,7 +189,7 @@ vndopen(dev_t dev, int flags, int mode, struct proc *p)
return (ENXIO);
sc = &vnd_softc[unit];
- if ((error = vndlock(sc)) != 0)
+ if ((error = disk_lock(&sc->sc_dk)) != 0)
return (error);
if ((flags & FWRITE) && (sc->sc_flags & VNF_READONLY)) {
@@ -234,7 +229,7 @@ vndopen(dev_t dev, int flags, int mode, struct proc *p)
sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
bad:
- vndunlock(sc);
+ disk_unlock(&sc->sc_dk);
return (error);
}
@@ -281,7 +276,7 @@ vndclose(dev_t dev, int flags, int mode, struct proc *p)
return (ENXIO);
sc = &vnd_softc[unit];
- if ((error = vndlock(sc)) != 0)
+ if ((error = disk_lock(&sc->sc_dk)) != 0)
return (error);
part = DISKPART(dev);
@@ -299,7 +294,7 @@ vndclose(dev_t dev, int flags, int mode, struct proc *p)
sc->sc_dk.dk_openmask =
sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
- vndunlock(sc);
+ disk_unlock(&sc->sc_dk);
return (0);
}
@@ -487,12 +482,12 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
if (sc->sc_flags & VNF_INITED)
return (EBUSY);
- if ((error = vndlock(sc)) != 0)
+ if ((error = disk_lock(&sc->sc_dk)) != 0)
return (error);
if ((error = copyinstr(vio->vnd_file, sc->sc_file,
sizeof(sc->sc_file), NULL))) {
- vndunlock(sc);
+ disk_unlock(&sc->sc_dk);
return (error);
}
@@ -514,7 +509,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
error = vn_open(&nd, FREAD, 0);
}
if (error) {
- vndunlock(sc);
+ disk_unlock(&sc->sc_dk);
return (error);
}
@@ -525,7 +520,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
if (error) {
VOP_UNLOCK(nd.ni_vp, 0, p);
vn_close(nd.ni_vp, VNDRW(sc), p->p_ucred, p);
- vndunlock(sc);
+ disk_unlock(&sc->sc_dk);
return (error);
}
sc->sc_size = vattr.va_size / sc->sc_secsize;
@@ -534,7 +529,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
sc->sc_vp = nd.ni_vp;
if ((error = vndsetcred(sc, p->p_ucred)) != 0) {
(void) vn_close(nd.ni_vp, VNDRW(sc), p->p_ucred, p);
- vndunlock(sc);
+ disk_unlock(&sc->sc_dk);
return (error);
}
@@ -548,7 +543,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
vio->vnd_keylen)) != 0) {
(void) vn_close(nd.ni_vp, VNDRW(sc),
p->p_ucred, p);
- vndunlock(sc);
+ disk_unlock(&sc->sc_dk);
return (error);
}
@@ -569,7 +564,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
sc->sc_dk.dk_name = sc->sc_dev.dv_xname;
disk_attach(&sc->sc_dev, &sc->sc_dk);
- vndunlock(sc);
+ disk_unlock(&sc->sc_dk);
break;
@@ -577,7 +572,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
if ((sc->sc_flags & VNF_INITED) == 0)
return (ENXIO);
- if ((error = vndlock(sc)) != 0)
+ if ((error = disk_lock(&sc->sc_dk)) != 0)
return (error);
/*
@@ -590,7 +585,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
if ((sc->sc_dk.dk_openmask & ~pmask) ||
((sc->sc_dk.dk_bopenmask & pmask) &&
(sc->sc_dk.dk_copenmask & pmask))) {
- vndunlock(sc);
+ disk_unlock(&sc->sc_dk);
return (EBUSY);
}
@@ -605,7 +600,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
/* Detach the disk. */
disk_detach(&sc->sc_dk);
- vndunlock(sc);
+ disk_unlock(&sc->sc_dk);
break;
case VNDIOCGET:
@@ -672,7 +667,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
if ((flag & FWRITE) == 0)
return (EBADF);
- if ((error = vndlock(sc)) != 0)
+ if ((error = disk_lock(&sc->sc_dk)) != 0)
return (error);
error = setdisklabel(sc->sc_dk.dk_label,
@@ -683,7 +678,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
vndstrategy, sc->sc_dk.dk_label);
}
- vndunlock(sc);
+ disk_unlock(&sc->sc_dk);
return (error);
default: