diff options
| author | hannken <hannken@NetBSD.org> | 2011-10-14 09:23:28 +0000 |
|---|---|---|
| committer | hannken <hannken@NetBSD.org> | 2011-10-14 09:23:28 +0000 |
| commit | 6e75bb0dfb296e532c3571fbc1a833003faf481a (patch) | |
| tree | 51f5f0ca283056d92e4b486cdbe9478c271243b9 /sys/dev | |
| parent | c8937d29ec57fb2b042e9dea3d3acdecfcbf991f (diff) | |
Change the vnode locking protocol of VOP_GETATTR() to request at least
a shared lock. Make all calls outside of file systems respect it.
The calls from file systems need review.
No objections from tech-kern.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/ccd.c | 9 | ||||
| -rw-r--r-- | sys/dev/cgd.c | 9 | ||||
| -rw-r--r-- | sys/dev/dm/dm_target_linear.c | 7 | ||||
| -rw-r--r-- | sys/dev/dm/dm_target_snapshot.c | 21 | ||||
| -rw-r--r-- | sys/dev/dm/dm_target_stripe.c | 7 | ||||
| -rw-r--r-- | sys/dev/raidframe/rf_copyback.c | 9 | ||||
| -rw-r--r-- | sys/dev/raidframe/rf_disks.c | 9 | ||||
| -rw-r--r-- | sys/dev/raidframe/rf_reconstruct.c | 9 | ||||
| -rw-r--r-- | sys/dev/vnd.c | 10 |
9 files changed, 62 insertions, 28 deletions
diff --git a/sys/dev/ccd.c b/sys/dev/ccd.c index 68281444b47..b982fd04c52 100644 --- a/sys/dev/ccd.c +++ b/sys/dev/ccd.c @@ -1,4 +1,4 @@ -/* $NetBSD: ccd.c,v 1.141 2011/07/04 16:06:45 joerg Exp $ */ +/* $NetBSD: ccd.c,v 1.142 2011/10/14 09:23:29 hannken Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 1999, 2007, 2009 The NetBSD Foundation, Inc. @@ -88,7 +88,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.141 2011/07/04 16:06:45 joerg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.142 2011/10/14 09:23:29 hannken Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -310,7 +310,10 @@ ccdinit(struct ccd_softc *cs, char **cpaths, struct vnode **vpp, /* * XXX: Cache the component's dev_t. */ - if ((error = VOP_GETATTR(vpp[ix], &va, l->l_cred)) != 0) { + vn_lock(vpp[ix], LK_SHARED | LK_RETRY); + error = VOP_GETATTR(vpp[ix], &va, l->l_cred); + VOP_UNLOCK(vpp[ix]); + if (error != 0) { #ifdef DEBUG if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) printf("%s: %s: getattr failed %s = %d\n", diff --git a/sys/dev/cgd.c b/sys/dev/cgd.c index 93d11b29459..bb7635c5693 100644 --- a/sys/dev/cgd.c +++ b/sys/dev/cgd.c @@ -1,4 +1,4 @@ -/* $NetBSD: cgd.c,v 1.74 2011/06/21 06:23:38 jruoho Exp $ */ +/* $NetBSD: cgd.c,v 1.75 2011/10/14 09:23:30 hannken Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.74 2011/06/21 06:23:38 jruoho Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.75 2011/10/14 09:23:30 hannken Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -773,7 +773,10 @@ cgdinit(struct cgd_softc *cs, const char *cpath, struct vnode *vp, cs->sc_tpath = malloc(cs->sc_tpathlen, M_DEVBUF, M_WAITOK); memcpy(cs->sc_tpath, tmppath, cs->sc_tpathlen); - if ((ret = VOP_GETATTR(vp, &va, l->l_cred)) != 0) + vn_lock(vp, LK_SHARED | LK_RETRY); + ret = VOP_GETATTR(vp, &va, l->l_cred); + VOP_UNLOCK(vp); + if (ret != 0) goto bail; cs->sc_tdev = va.va_rdev; diff --git a/sys/dev/dm/dm_target_linear.c b/sys/dev/dm/dm_target_linear.c index a9b121f704c..7a03f173fe2 100644 --- a/sys/dev/dm/dm_target_linear.c +++ b/sys/dev/dm/dm_target_linear.c @@ -1,4 +1,4 @@ -/* $NetBSD: dm_target_linear.c,v 1.12 2010/12/23 14:58:13 mlelstv Exp $ */ +/* $NetBSD: dm_target_linear.c,v 1.13 2011/10/14 09:23:30 hannken Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -201,7 +201,10 @@ dm_target_linear_deps(dm_table_entry_t * table_en, prop_array_t prop_array) tlc = table_en->target_config; - if ((error = VOP_GETATTR(tlc->pdev->pdev_vnode, &va, curlwp->l_cred)) != 0) + vn_lock(tlc->pdev->pdev_vnode, LK_SHARED | LK_RETRY); + error = VOP_GETATTR(tlc->pdev->pdev_vnode, &va, curlwp->l_cred); + VOP_UNLOCK(tlc->pdev->pdev_vnode); + if (error != 0) return error; prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev); diff --git a/sys/dev/dm/dm_target_snapshot.c b/sys/dev/dm/dm_target_snapshot.c index 99cee510f0e..72d7cd43848 100644 --- a/sys/dev/dm/dm_target_snapshot.c +++ b/sys/dev/dm/dm_target_snapshot.c @@ -1,4 +1,4 @@ -/* $NetBSD: dm_target_snapshot.c,v 1.14 2010/12/23 14:58:13 mlelstv Exp $ */ +/* $NetBSD: dm_target_snapshot.c,v 1.15 2011/10/14 09:23:30 hannken Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -357,15 +357,21 @@ dm_target_snapshot_deps(dm_table_entry_t * table_en, tsc = table_en->target_config; - if ((error = VOP_GETATTR(tsc->tsc_snap_dev->pdev_vnode, &va, curlwp->l_cred)) != 0) + vn_lock(tsc->tsc_snap_dev->pdev_vnode, LK_SHARED | LK_RETRY); + error = VOP_GETATTR(tsc->tsc_snap_dev->pdev_vnode, &va, curlwp->l_cred); + VOP_UNLOCK(tsc->tsc_snap_dev->pdev_vnode); + if (error != 0) return error; prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev); if (tsc->tsc_persistent_dev) { - if ((error = VOP_GETATTR(tsc->tsc_cow_dev->pdev_vnode, &va, - curlwp->l_cred)) != 0) + vn_lock(tsc->tsc_cow_dev->pdev_vnode, LK_SHARED | LK_RETRY); + error = VOP_GETATTR(tsc->tsc_cow_dev->pdev_vnode, &va, + curlwp->l_cred); + VOP_UNLOCK(tsc->tsc_cow_dev->pdev_vnode); + if (error != 0) return error; prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev); @@ -534,8 +540,11 @@ dm_target_snapshot_orig_deps(dm_table_entry_t * table_en, tsoc = table_en->target_config; - if ((error = VOP_GETATTR(tsoc->tsoc_real_dev->pdev_vnode, &va, - curlwp->l_cred)) != 0) + vn_lock(tsoc->tsoc_real_dev->pdev_vnode, LK_SHARED | LK_RETRY); + error = VOP_GETATTR(tsoc->tsoc_real_dev->pdev_vnode, &va, + curlwp->l_cred); + VOP_UNLOCK(tsoc->tsoc_real_dev->pdev_vnode); + if (error != 0) return error; prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev); diff --git a/sys/dev/dm/dm_target_stripe.c b/sys/dev/dm/dm_target_stripe.c index 84d356e8b34..a56838d87b3 100644 --- a/sys/dev/dm/dm_target_stripe.c +++ b/sys/dev/dm/dm_target_stripe.c @@ -1,4 +1,4 @@ -/*$NetBSD: dm_target_stripe.c,v 1.15 2011/08/27 17:09:09 ahoka Exp $*/ +/*$NetBSD: dm_target_stripe.c,v 1.16 2011/10/14 09:23:30 hannken Exp $*/ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -329,7 +329,10 @@ dm_target_stripe_deps(dm_table_entry_t * table_en, prop_array_t prop_array) tsc = table_en->target_config; TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) { - if ((error = VOP_GETATTR(tlc->pdev->pdev_vnode, &va, curlwp->l_cred)) != 0) + vn_lock(tlc->pdev->pdev_vnode, LK_SHARED | LK_RETRY); + error = VOP_GETATTR(tlc->pdev->pdev_vnode, &va, curlwp->l_cred); + VOP_UNLOCK(tlc->pdev->pdev_vnode); + if (error != 0) return error; prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev); diff --git a/sys/dev/raidframe/rf_copyback.c b/sys/dev/raidframe/rf_copyback.c index a3460d6e5cf..656d5fb1e78 100644 --- a/sys/dev/raidframe/rf_copyback.c +++ b/sys/dev/raidframe/rf_copyback.c @@ -1,4 +1,4 @@ -/* $NetBSD: rf_copyback.c,v 1.48 2011/08/03 14:44:38 oster Exp $ */ +/* $NetBSD: rf_copyback.c,v 1.49 2011/10/14 09:23:30 hannken Exp $ */ /* * Copyright (c) 1995 Carnegie-Mellon University. * All rights reserved. @@ -38,7 +38,7 @@ ****************************************************************************/ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rf_copyback.c,v 1.48 2011/08/03 14:44:38 oster Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rf_copyback.c,v 1.49 2011/10/14 09:23:30 hannken Exp $"); #include <dev/raidframe/raidframevar.h> @@ -160,7 +160,10 @@ rf_CopybackReconstructedData(RF_Raid_t *raidPtr) /* Ok, so we can at least do a lookup... How about actually * getting a vp for it? */ - if ((retcode = VOP_GETATTR(vp, &va, curlwp->l_cred)) != 0) + vn_lock(vp, LK_SHARED | LK_RETRY); + retcode = VOP_GETATTR(vp, &va, curlwp->l_cred); + VOP_UNLOCK(vp); + if (retcode != 0) return; retcode = rf_getdisksize(vp, &raidPtr->Disks[fcol]); if (retcode) { diff --git a/sys/dev/raidframe/rf_disks.c b/sys/dev/raidframe/rf_disks.c index 2b4f5d8b456..be0757d1581 100644 --- a/sys/dev/raidframe/rf_disks.c +++ b/sys/dev/raidframe/rf_disks.c @@ -1,4 +1,4 @@ -/* $NetBSD: rf_disks.c,v 1.81 2011/08/03 14:44:38 oster Exp $ */ +/* $NetBSD: rf_disks.c,v 1.82 2011/10/14 09:23:30 hannken Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. * All rights reserved. @@ -60,7 +60,7 @@ ***************************************************************/ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rf_disks.c,v 1.81 2011/08/03 14:44:38 oster Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rf_disks.c,v 1.82 2011/10/14 09:23:30 hannken Exp $"); #include <dev/raidframe/raidframevar.h> @@ -630,7 +630,10 @@ rf_ConfigureDisk(RF_Raid_t *raidPtr, char *bf, RF_RaidDisk_t *diskPtr, raidPtr->bytesPerSector = diskPtr->blockSize; if (diskPtr->status == rf_ds_optimal) { - if ((error = VOP_GETATTR(vp, &va, curlwp->l_cred)) != 0) + vn_lock(vp, LK_SHARED | LK_RETRY); + error = VOP_GETATTR(vp, &va, curlwp->l_cred); + VOP_UNLOCK(vp); + if (error != 0) return (error); raidPtr->raid_cinfo[col].ci_vp = vp; diff --git a/sys/dev/raidframe/rf_reconstruct.c b/sys/dev/raidframe/rf_reconstruct.c index 1504366d8d3..06943be4c67 100644 --- a/sys/dev/raidframe/rf_reconstruct.c +++ b/sys/dev/raidframe/rf_reconstruct.c @@ -1,4 +1,4 @@ -/* $NetBSD: rf_reconstruct.c,v 1.116 2011/08/03 15:00:29 oster Exp $ */ +/* $NetBSD: rf_reconstruct.c,v 1.117 2011/10/14 09:23:30 hannken Exp $ */ /* * Copyright (c) 1995 Carnegie-Mellon University. * All rights reserved. @@ -33,7 +33,7 @@ ************************************************************/ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rf_reconstruct.c,v 1.116 2011/08/03 15:00:29 oster Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rf_reconstruct.c,v 1.117 2011/10/14 09:23:30 hannken Exp $"); #include <sys/param.h> #include <sys/time.h> @@ -456,7 +456,10 @@ rf_ReconstructInPlace(RF_Raid_t *raidPtr, RF_RowCol_t col) /* Ok, so we can at least do a lookup... How about actually getting a vp for it? */ - if ((retcode = VOP_GETATTR(vp, &va, curlwp->l_cred)) != 0) { + vn_lock(vp, LK_SHARED | LK_RETRY); + retcode = VOP_GETATTR(vp, &va, curlwp->l_cred); + VOP_UNLOCK(vp); + if (retcode != 0) { vn_close(vp, FREAD | FWRITE, kauth_cred_get()); rf_lock_mutex2(raidPtr->mutex); raidPtr->reconInProgress--; diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c index 1241c8387b6..9c40d466cc5 100644 --- a/sys/dev/vnd.c +++ b/sys/dev/vnd.c @@ -1,4 +1,4 @@ -/* $NetBSD: vnd.c,v 1.218 2011/06/29 09:12:42 hannken Exp $ */ +/* $NetBSD: vnd.c,v 1.219 2011/10/14 09:23:30 hannken 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.218 2011/06/29 09:12:42 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.219 2011/10/14 09:23:30 hannken Exp $"); #if defined(_KERNEL_OPT) #include "opt_vnd.h" @@ -918,6 +918,7 @@ vndwrite(dev_t dev, struct uio *uio, int flags) static int vnd_cget(struct lwp *l, int unit, int *un, struct vattr *va) { + int error; struct vnd_softc *vnd; if (*un == -1) @@ -932,7 +933,10 @@ vnd_cget(struct lwp *l, int unit, int *un, struct vattr *va) if ((vnd->sc_flags & VNF_INITED) == 0) return -1; - return VOP_GETATTR(vnd->sc_vp, va, l->l_cred); + vn_lock(vnd->sc_vp, LK_SHARED | LK_RETRY); + error = VOP_GETATTR(vnd->sc_vp, va, l->l_cred); + VOP_UNLOCK(vnd->sc_vp); + return error; } static int |
