summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2011-06-20 16:46:07 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2011-06-20 16:46:07 +0000
commit346ec16a196f8c215a22811c7a6c9cce7004588b (patch)
tree35feb6ede8dae50882f4b0d1ef1aa8e2b57ac85d
parentbd5acf2a2c4c90f86fb4194c64bd56ce84fa7f45 (diff)
for now, move back to a private rw_lock rather than the disk_lock.
we have problems with instantiating new disks ok matthew
-rw-r--r--sys/dev/vnd.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c
index 9b1f52c8e50..2c2348b0ec3 100644
--- a/sys/dev/vnd.c
+++ b/sys/dev/vnd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vnd.c,v 1.130 2011/06/19 04:55:33 deraadt Exp $ */
+/* $OpenBSD: vnd.c,v 1.131 2011/06/20 16:46:06 deraadt Exp $ */
/* $NetBSD: vnd.c,v 1.26 1996/03/30 23:06:11 christos Exp $ */
/*
@@ -61,6 +61,7 @@
#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>
@@ -104,6 +105,7 @@ 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 */
@@ -167,10 +169,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;
@@ -189,7 +191,7 @@ vndopen(dev_t dev, int flags, int mode, struct proc *p)
return (ENXIO);
sc = &vnd_softc[unit];
- if ((error = disk_lock(&sc->sc_dk)) != 0)
+ if ((error = rw_enter(&sc->sc_rwlock, RW_WRITE|RW_INTR)) != 0)
return (error);
if ((flags & FWRITE) && (sc->sc_flags & VNF_READONLY)) {
@@ -229,7 +231,7 @@ vndopen(dev_t dev, int flags, int mode, struct proc *p)
sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
bad:
- disk_unlock(&sc->sc_dk);
+ rw_exit_write(&sc->sc_rwlock);
return (error);
}
@@ -276,7 +278,7 @@ vndclose(dev_t dev, int flags, int mode, struct proc *p)
return (ENXIO);
sc = &vnd_softc[unit];
- disk_lock_nointr(&sc->sc_dk);
+ rw_enter(&sc->sc_rwlock, RW_WRITE);
part = DISKPART(dev);
@@ -293,7 +295,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;
- disk_unlock(&sc->sc_dk);
+ rw_exit_write(&sc->sc_rwlock);
return (0);
}
@@ -481,12 +483,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 = disk_lock(&sc->sc_dk)) != 0)
+ if ((error = rw_enter(&sc->sc_rwlock, RW_WRITE|RW_INTR)) != 0)
return (error);
if ((error = copyinstr(vio->vnd_file, sc->sc_file,
sizeof(sc->sc_file), NULL))) {
- disk_unlock(&sc->sc_dk);
+ rw_exit_write(&sc->sc_rwlock);
return (error);
}
@@ -508,7 +510,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
error = vn_open(&nd, FREAD, 0);
}
if (error) {
- disk_unlock(&sc->sc_dk);
+ rw_exit_write(&sc->sc_rwlock);
return (error);
}
@@ -519,7 +521,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);
- disk_unlock(&sc->sc_dk);
+ rw_exit_write(&sc->sc_rwlock);
return (error);
}
sc->sc_size = vattr.va_size / sc->sc_secsize;
@@ -528,7 +530,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);
- disk_unlock(&sc->sc_dk);
+ rw_exit_write(&sc->sc_rwlock);
return (error);
}
@@ -542,7 +544,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);
- disk_unlock(&sc->sc_dk);
+ rw_exit_write(&sc->sc_rwlock);
return (error);
}
@@ -563,7 +565,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);
- disk_unlock(&sc->sc_dk);
+ rw_exit_write(&sc->sc_rwlock);
break;
@@ -571,7 +573,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 = disk_lock(&sc->sc_dk)) != 0)
+ if ((error = rw_enter(&sc->sc_rwlock, RW_WRITE|RW_INTR)) != 0)
return (error);
/*
@@ -584,7 +586,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))) {
- disk_unlock(&sc->sc_dk);
+ rw_exit_write(&sc->sc_rwlock);
return (EBUSY);
}
@@ -599,7 +601,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
/* Detach the disk. */
disk_detach(&sc->sc_dk);
- disk_unlock(&sc->sc_dk);
+ rw_exit_write(&sc->sc_rwlock);
break;
case VNDIOCGET:
@@ -666,7 +668,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
if ((flag & FWRITE) == 0)
return (EBADF);
- if ((error = disk_lock(&sc->sc_dk)) != 0)
+ if ((error = rw_enter(&sc->sc_rwlock, RW_WRITE|RW_INTR)) != 0)
return (error);
error = setdisklabel(sc->sc_dk.dk_label,
@@ -677,7 +679,7 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
vndstrategy, sc->sc_dk.dk_label);
}
- disk_unlock(&sc->sc_dk);
+ rw_exit_write(&sc->sc_rwlock);
return (error);
default: