summaryrefslogtreecommitdiffstats
path: root/sys/dev/md
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2009-03-11 14:13:47 +0000
committerjhb <jhb@FreeBSD.org>2009-03-11 14:13:47 +0000
commit520acdaf6926bd9375ce8e27092559997f111882 (patch)
tree9729e7549d110dca0074d289abb6591d48654669 /sys/dev/md
parent8609dfd41ccae53505ee519fd6426fc876675ebd (diff)
downloadFreeBSD-src-520acdaf6926bd9375ce8e27092559997f111882.zip
FreeBSD-src-520acdaf6926bd9375ce8e27092559997f111882.tar.gz
Add a new internal mount flag (MNTK_EXTENDED_SHARED) to indicate that a
filesystem supports additional operations using shared vnode locks. Currently this is used to enable shared locks for open() and close() of read-only file descriptors. - When an ISOPEN namei() request is performed with LOCKSHARED, use a shared vnode lock for the leaf vnode only if the mount point has the extended shared flag set. - Set LOCKSHARED in vn_open_cred() for requests that specify O_RDONLY but not O_CREAT. - Use a shared vnode lock around VOP_CLOSE() if the file was opened with O_RDONLY and the mountpoint has the extended shared flag set. - Adjust md(4) to upgrade the vnode lock on the vnode it gets back from vn_open() since it now may only have a shared vnode lock. - Don't enable shared vnode locks on FIFO vnodes in ZFS and UFS since FIFO's require exclusive vnode locks for their open() and close() routines. (My recent MPSAFE patches for UDF and cd9660 already included this change.) - Enable extended shared operations on UFS, cd9660, and UDF. Submitted by: ups Reviewed by: pjd (ZFS bits) MFC after: 1 month
Diffstat (limited to 'sys/dev/md')
-rw-r--r--sys/dev/md/md.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c
index d3e3da8..48d48fd 100644
--- a/sys/dev/md/md.c
+++ b/sys/dev/md/md.c
@@ -924,12 +924,20 @@ mdcreate_vnode(struct md_s *sc, struct md_ioctl *mdio, struct thread *td)
return (error);
vfslocked = NDHASGIANT(&nd);
NDFREE(&nd, NDF_ONLY_PNBUF);
- if (nd.ni_vp->v_type != VREG ||
- (error = VOP_GETATTR(nd.ni_vp, &vattr, td->td_ucred))) {
- VOP_UNLOCK(nd.ni_vp, 0);
- (void)vn_close(nd.ni_vp, flags, td->td_ucred, td);
- VFS_UNLOCK_GIANT(vfslocked);
- return (error ? error : EINVAL);
+ if (nd.ni_vp->v_type != VREG) {
+ error = EINVAL;
+ goto bad;
+ }
+ error = VOP_GETATTR(nd.ni_vp, &vattr, td->td_ucred);
+ if (error != 0)
+ goto bad;
+ if (VOP_ISLOCKED(nd.ni_vp) != LK_EXCLUSIVE) {
+ vn_lock(nd.ni_vp, LK_UPGRADE | LK_RETRY);
+ if (nd.ni_vp->v_iflag & VI_DOOMED) {
+ /* Forced unmount. */
+ error = EBADF;
+ goto bad;
+ }
}
nd.ni_vp->v_vflag |= VV_MD;
VOP_UNLOCK(nd.ni_vp, 0);
@@ -948,13 +956,15 @@ mdcreate_vnode(struct md_s *sc, struct md_ioctl *mdio, struct thread *td)
sc->vnode = NULL;
vn_lock(nd.ni_vp, LK_EXCLUSIVE | LK_RETRY);
nd.ni_vp->v_vflag &= ~VV_MD;
- VOP_UNLOCK(nd.ni_vp, 0);
- (void)vn_close(nd.ni_vp, flags, td->td_ucred, td);
- VFS_UNLOCK_GIANT(vfslocked);
- return (error);
+ goto bad;
}
VFS_UNLOCK_GIANT(vfslocked);
return (0);
+bad:
+ VOP_UNLOCK(nd.ni_vp, 0);
+ (void)vn_close(nd.ni_vp, flags, td->td_ucred, td);
+ VFS_UNLOCK_GIANT(vfslocked);
+ return (error);
}
static int
OpenPOWER on IntegriCloud