Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/pgoyette-localcount]: src/sys/dev Update vnd for using localcount(9)
details: https://anonhg.NetBSD.org/src/rev/4edfd52cc5b6
branches: pgoyette-localcount
changeset: 852861:4edfd52cc5b6
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Mon Jul 25 22:06:09 2016 +0000
description:
Update vnd for using localcount(9)
diffstat:
sys/dev/vnd.c | 155 ++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 118 insertions(+), 37 deletions(-)
diffs (truncated from 464 to 300 lines):
diff -r 58e19473cc4c -r 4edfd52cc5b6 sys/dev/vnd.c
--- a/sys/dev/vnd.c Mon Jul 25 03:40:52 2016 +0000
+++ b/sys/dev/vnd.c Mon Jul 25 22:06:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vnd.c,v 1.256.2.3 2016/07/19 06:26:58 pgoyette Exp $ */
+/* $NetBSD: vnd.c,v 1.256.2.4 2016/07/25 22:06:09 pgoyette Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
@@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.256.2.3 2016/07/19 06:26:58 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.256.2.4 2016/07/25 22:06:09 pgoyette Exp $");
#if defined(_KERNEL_OPT)
#include "opt_vnd.h"
@@ -324,6 +324,7 @@
static int
vndopen(dev_t dev, int flags, int mode, struct lwp *l)
{
+ device_t self;
int unit = vndunit(dev);
struct vnd_softc *sc;
int error = 0, part, pmask;
@@ -333,7 +334,7 @@
if (vnddebug & VDB_FOLLOW)
printf("vndopen(0x%"PRIx64", 0x%x, 0x%x, %p)\n", dev, flags, mode, l);
#endif
- sc = device_lookup_private(&vnd_cd, unit);
+ sc = device_lookup_private_acquire(&vnd_cd, unit, &self);
if (sc == NULL) {
sc = vnd_spawn(unit);
if (sc == NULL)
@@ -410,12 +411,14 @@
done:
mutex_exit(&sc->sc_dkdev.dk_openlock);
vndunlock(sc);
+ device_release(self);
return error;
}
static int
vndclose(dev_t dev, int flags, int mode, struct lwp *l)
{
+ device_t self;
int unit = vndunit(dev);
struct vnd_softc *sc;
int error = 0, part;
@@ -424,12 +427,17 @@
if (vnddebug & VDB_FOLLOW)
printf("vndclose(0x%"PRIx64", 0x%x, 0x%x, %p)\n", dev, flags, mode, l);
#endif
- sc = device_lookup_private(&vnd_cd, unit);
- if (sc == NULL)
+ sc = device_lookup_private_acquire(&vnd_cd, unit, &self);
+ if (sc == NULL) {
+ if (self != NULL)
+ device_release(self);
return ENXIO;
+ }
- if ((error = vndlock(sc)) != 0)
+ if ((error = vndlock(sc)) != 0) {
+ device_release(self);
return error;
+ }
mutex_enter(&sc->sc_dkdev.dk_openlock);
@@ -462,10 +470,12 @@
if ((error = vnd_destroy(sc->sc_dev)) != 0) {
aprint_error_dev(sc->sc_dev,
"unable to detach instance\n");
+ device_release(self);
return error;
}
}
+ device_release(self);
return 0;
}
@@ -475,9 +485,10 @@
static void
vndstrategy(struct buf *bp)
{
+ device_t self;
int unit = vndunit(bp->b_dev);
struct vnd_softc *vnd =
- device_lookup_private(&vnd_cd, unit);
+ device_lookup_private_acquire(&vnd_cd, unit, &self);
struct disklabel *lp;
daddr_t blkno;
int s = splbio();
@@ -561,12 +572,15 @@
bufq_put(vnd->sc_tab, bp);
wakeup(&vnd->sc_tab);
splx(s);
+ device_release(self);
return;
done:
bp->b_resid = bp->b_bcount;
biodone(bp);
splx(s);
+ if (self != NULL)
+ device_release(self);
}
static bool
@@ -981,6 +995,8 @@
static int
vndread(dev_t dev, struct uio *uio, int flags)
{
+ device_t self;
+ int error;
int unit = vndunit(dev);
struct vnd_softc *sc;
@@ -989,20 +1005,29 @@
printf("vndread(0x%"PRIx64", %p)\n", dev, uio);
#endif
- sc = device_lookup_private(&vnd_cd, unit);
- if (sc == NULL)
+ sc = device_lookup_private_acquire(&vnd_cd, unit, &self);
+ if (sc == NULL) {
+ if (self != NULL)
+ device_release(self);
return ENXIO;
+ }
- if ((sc->sc_flags & VNF_INITED) == 0)
+ if ((sc->sc_flags & VNF_INITED) == 0) {
+ device_release(self);
return ENXIO;
+ }
- return physio(vndstrategy, NULL, dev, B_READ, minphys, uio);
+ error = physio(vndstrategy, NULL, dev, B_READ, minphys, uio);
+ device_release(self);
+ return error;
}
/* ARGSUSED */
static int
vndwrite(dev_t dev, struct uio *uio, int flags)
{
+ device_t self;
+ int error;
int unit = vndunit(dev);
struct vnd_softc *sc;
@@ -1011,19 +1036,27 @@
printf("vndwrite(0x%"PRIx64", %p)\n", dev, uio);
#endif
- sc = device_lookup_private(&vnd_cd, unit);
- if (sc == NULL)
+ sc = device_lookup_private_acquire(&vnd_cd, unit, &self);
+ if (sc == NULL) {
+ if (self != NULL)
+ device_release(self);
return ENXIO;
+ }
- if ((sc->sc_flags & VNF_INITED) == 0)
+ if ((sc->sc_flags & VNF_INITED) == 0) {
+ device_release(self);
return ENXIO;
+ }
- return physio(vndstrategy, NULL, dev, B_WRITE, minphys, uio);
+ error = physio(vndstrategy, NULL, dev, B_WRITE, minphys, uio);
+ device_release(self);
+ return error;
}
static int
vnd_cget(struct lwp *l, int unit, int *un, struct vattr *va)
{
+ device_t self;
int error;
struct vnd_softc *vnd;
@@ -1032,16 +1065,22 @@
if (*un < 0)
return EINVAL;
- vnd = device_lookup_private(&vnd_cd, *un);
- if (vnd == NULL)
+ vnd = device_lookup_private_acquire(&vnd_cd, *un, &self);
+ if (vnd == NULL) {
+ if (self != NULL)
+ device_release(self);
return -1;
+ }
- if ((vnd->sc_flags & VNF_INITED) == 0)
+ if ((vnd->sc_flags & VNF_INITED) == 0) {
+ device_release(self);
return -1;
+ }
vn_lock(vnd->sc_vp, LK_SHARED | LK_RETRY);
error = VOP_GETATTR(vnd->sc_vp, va, l->l_cred);
VOP_UNLOCK(vnd->sc_vp);
+ device_release(self);
return error;
}
@@ -1117,6 +1156,7 @@
static int
vndioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
{
+ device_t self;
bool force;
int unit = vndunit(dev);
struct vnd_softc *vnd;
@@ -1175,8 +1215,11 @@
}
vnd = device_lookup_private(&vnd_cd, unit);
- if (vnd == NULL)
+ if (vnd == NULL) {
+ if (self != NULL)
+ device_release(self);
return ENXIO;
+ }
vio = (struct vnd_ioctl *)data;
/* Must be open for writes for these commands... */
@@ -1195,8 +1238,10 @@
#endif
case DIOCKLABEL:
case DIOCWLABEL:
- if ((flag & FWRITE) == 0)
+ if ((flag & FWRITE) == 0) {
+ device_release(self);
return EBADF;
+ }
}
/* Must be initialized for these... */
@@ -1219,25 +1264,31 @@
case ODIOCWDINFO:
case ODIOCGDEFLABEL:
#endif
- if ((vnd->sc_flags & VNF_INITED) == 0)
+ if ((vnd->sc_flags & VNF_INITED) == 0) {
+ device_release(self);
return ENXIO;
+ }
}
error = disk_ioctl(&vnd->sc_dkdev, dev, cmd, data, flag, l);
- if (error != EPASSTHROUGH)
+ if (error != EPASSTHROUGH) {
+ device_release(self);
return error;
-
+ }
switch (cmd) {
#ifdef VNDIOCSET50
case VNDIOCSET50:
#endif
case VNDIOCSET:
- if (vnd->sc_flags & VNF_INITED)
+ if (vnd->sc_flags & VNF_INITED) {
+ device_release(self);
return EBUSY;
-
- if ((error = vndlock(vnd)) != 0)
+ }
+ if ((error = vndlock(vnd)) != 0) {
+ device_release(self);
return error;
+ }
fflags = FREAD;
if ((vio->vnd_flags & VNDIOF_READONLY) == 0)
@@ -1499,6 +1550,7 @@
}
#endif /* VND_COMPRESSION */
vndunlock(vnd);
+ device_release(self);
return error;
#ifdef VNDIOCCLR50
@@ -1509,8 +1561,10 @@
pmask = (1 << part);
force = (vio->vnd_flags & VNDIOF_FORCE) != 0;
- if ((error = vnddoclear(vnd, pmask, minor(dev), force)) != 0)
+ if ((error = vnddoclear(vnd, pmask, minor(dev), force)) != 0) {
+ device_release(self);
return error;
Home |
Main Index |
Thread Index |
Old Index