aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2022-09-17 15:22:04 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2022-09-17 15:41:37 +0000
commita75d1ddd74312f5dd79bc1e965f7077679659f2e (patch)
tree497b828949aeecb5a6ad0d732709f95f2945e938
parent9e4f35ac25538fb426c459400f0c36e085546ffa (diff)
downloadsrc-a75d1ddd74312f5dd79bc1e965f7077679659f2e.tar.gz
src-a75d1ddd74312f5dd79bc1e965f7077679659f2e.zip
vfs: introduce V_PCATCH to stop abusing PCATCH
-rw-r--r--sys/contrib/openzfs/module/os/freebsd/zfs/zfs_file_os.c2
-rw-r--r--sys/fs/fdescfs/fdesc_vnops.c2
-rw-r--r--sys/fs/nfsserver/nfs_nfsdstate.c4
-rw-r--r--sys/fs/unionfs/union_subr.c6
-rw-r--r--sys/kern/uipc_usrreq.c2
-rw-r--r--sys/kern/vfs_acl.c4
-rw-r--r--sys/kern/vfs_aio.c2
-rw-r--r--sys/kern/vfs_extattr.c6
-rw-r--r--sys/kern/vfs_syscalls.c30
-rw-r--r--sys/kern/vfs_vnops.c22
-rw-r--r--sys/security/mac/mac_syscalls.c4
-rw-r--r--sys/sys/vnode.h2
12 files changed, 47 insertions, 39 deletions
diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_file_os.c b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_file_os.c
index fd86a75416e6..a6930cec517b 100644
--- a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_file_os.c
+++ b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_file_os.c
@@ -226,7 +226,7 @@ zfs_vop_fsync(vnode_t *vp)
struct mount *mp;
int error;
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
+ if ((error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH)) != 0)
goto drop;
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
error = VOP_FSYNC(vp, MNT_WAIT, curthread);
diff --git a/sys/fs/fdescfs/fdesc_vnops.c b/sys/fs/fdescfs/fdesc_vnops.c
index ae6d60d0fc55..7046bb6bf244 100644
--- a/sys/fs/fdescfs/fdesc_vnops.c
+++ b/sys/fs/fdescfs/fdesc_vnops.c
@@ -516,7 +516,7 @@ fdesc_setattr(struct vop_setattr_args *ap)
return (error);
}
vp = fp->f_vnode;
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) == 0) {
+ if ((error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH)) == 0) {
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
error = VOP_SETATTR(vp, ap->a_vap, ap->a_cred);
VOP_UNLOCK(vp);
diff --git a/sys/fs/nfsserver/nfs_nfsdstate.c b/sys/fs/nfsserver/nfs_nfsdstate.c
index d5d7f9fbd363..84da1d9561cd 100644
--- a/sys/fs/nfsserver/nfs_nfsdstate.c
+++ b/sys/fs/nfsserver/nfs_nfsdstate.c
@@ -8426,10 +8426,10 @@ tryagain2:
* NFS mount and they are not suspendable at this time.
*/
if (ret == 0)
- ret = vn_start_write(vp, &mp, V_WAIT | PCATCH);
+ ret = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
if (ret == 0) {
tvmp = dvp->v_mount;
- ret = vn_start_write(NULL, &tvmp, V_WAIT | PCATCH);
+ ret = vn_start_write(NULL, &tvmp, V_WAIT | V_PCATCH);
}
/*
diff --git a/sys/fs/unionfs/union_subr.c b/sys/fs/unionfs/union_subr.c
index ac00cc1bc093..0b9e8fde4b6a 100644
--- a/sys/fs/unionfs/union_subr.c
+++ b/sys/fs/unionfs/union_subr.c
@@ -907,7 +907,7 @@ unionfs_mkshadowdir(struct unionfs_mount *ump, struct vnode *udvp,
goto unionfs_mkshadowdir_abort;
}
- if ((error = vn_start_write(udvp, &mp, V_WAIT | PCATCH)))
+ if ((error = vn_start_write(udvp, &mp, V_WAIT | V_PCATCH)))
goto unionfs_mkshadowdir_abort;
unionfs_create_uppervattr_core(ump, &lva, &va, td);
@@ -962,7 +962,7 @@ unionfs_mkwhiteout(struct vnode *dvp, struct componentname *cnp,
return (EEXIST);
}
- if ((error = vn_start_write(dvp, &mp, V_WAIT | PCATCH)))
+ if ((error = vn_start_write(dvp, &mp, V_WAIT | V_PCATCH)))
goto unionfs_mkwhiteout_free_out;
error = VOP_WHITEOUT(dvp, &nd.ni_cnd, CREATE);
@@ -1160,7 +1160,7 @@ unionfs_copyfile(struct unionfs_node *unp, int docopy, struct ucred *cred,
if (error != 0)
return (error);
- if ((error = vn_start_write(udvp, &mp, V_WAIT | PCATCH)) != 0)
+ if ((error = vn_start_write(udvp, &mp, V_WAIT | V_PCATCH)) != 0)
return (error);
error = unionfs_vn_create_on_upper(&uvp, udvp, unp, &uva, td);
if (error != 0) {
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 1a4d2d5adc0a..00d7aa1fc968 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -611,7 +611,7 @@ restart:
error = EADDRINUSE;
goto error;
}
- error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH);
+ error = vn_start_write(NULL, &mp, V_XSLEEP | V_PCATCH);
if (error)
goto error;
goto restart;
diff --git a/sys/kern/vfs_acl.c b/sys/kern/vfs_acl.c
index 2e3abe007c2a..dffce9d29291 100644
--- a/sys/kern/vfs_acl.c
+++ b/sys/kern/vfs_acl.c
@@ -236,7 +236,7 @@ vacl_set_acl(struct thread *td, struct vnode *vp, acl_type_t type,
error = acl_copyin(aclp, inkernelacl, type);
if (error != 0)
goto out;
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
+ error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
if (error != 0)
goto out;
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
@@ -300,7 +300,7 @@ vacl_delete(struct thread *td, struct vnode *vp, acl_type_t type)
int error;
AUDIT_ARG_VALUE(type);
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
+ error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
if (error != 0)
return (error);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c
index c9489ee5b4ad..43e54e1ad9bf 100644
--- a/sys/kern/vfs_aio.c
+++ b/sys/kern/vfs_aio.c
@@ -724,7 +724,7 @@ aio_fsync_vnode(struct thread *td, struct vnode *vp, int op)
int error;
for (;;) {
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
+ error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
if (error != 0)
break;
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
diff --git a/sys/kern/vfs_extattr.c b/sys/kern/vfs_extattr.c
index 4c1851a52e88..d389b33d0634 100644
--- a/sys/kern/vfs_extattr.c
+++ b/sys/kern/vfs_extattr.c
@@ -125,7 +125,7 @@ sys_extattrctl(struct thread *td, struct extattrctl_args *uap)
goto out;
}
VOP_UNLOCK(nd.ni_vp);
- error = vn_start_write(nd.ni_vp, &mp_writable, V_WAIT | PCATCH);
+ error = vn_start_write(nd.ni_vp, &mp_writable, V_WAIT | V_PCATCH);
NDFREE(&nd, NDF_NO_VP_UNLOCK);
if (error)
goto out;
@@ -182,7 +182,7 @@ extattr_set_vp(struct vnode *vp, int attrnamespace, const char *attrname,
if (nbytes > IOSIZE_MAX)
return (EINVAL);
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
+ error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
if (error)
return (error);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
@@ -497,7 +497,7 @@ extattr_delete_vp(struct vnode *vp, int attrnamespace, const char *attrname,
struct mount *mp;
int error;
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
+ error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
if (error)
return (error);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 103f4dab519f..b3223e620962 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1389,7 +1389,7 @@ restart:
if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
NDFREE_PNBUF(&nd);
vput(nd.ni_dvp);
- if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
+ if ((error = vn_start_write(NULL, &mp, V_XSLEEP | V_PCATCH)) != 0)
return (error);
goto restart;
}
@@ -1476,7 +1476,7 @@ restart:
if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
NDFREE_PNBUF(&nd);
vput(nd.ni_dvp);
- if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
+ if ((error = vn_start_write(NULL, &mp, V_XSLEEP | V_PCATCH)) != 0)
return (error);
goto restart;
}
@@ -1660,7 +1660,7 @@ kern_linkat_vp(struct thread *td, struct vnode *vp, int fd, const char *path,
vput(nd.ni_dvp);
NDFREE_PNBUF(&nd);
error = vn_start_write(NULL, &mp,
- V_XSLEEP | PCATCH);
+ V_XSLEEP | V_PCATCH);
if (error != 0)
return (error);
return (EAGAIN);
@@ -1755,7 +1755,7 @@ restart:
if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
NDFREE_PNBUF(&nd);
vput(nd.ni_dvp);
- if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
+ if ((error = vn_start_write(NULL, &mp, V_XSLEEP | V_PCATCH)) != 0)
goto out;
goto restart;
}
@@ -1820,7 +1820,7 @@ restart:
if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
NDFREE_PNBUF(&nd);
vput(nd.ni_dvp);
- if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
+ if ((error = vn_start_write(NULL, &mp, V_XSLEEP | V_PCATCH)) != 0)
return (error);
goto restart;
}
@@ -1953,7 +1953,7 @@ restart:
else
vput(vp);
if ((error = vn_start_write(NULL, &mp,
- V_XSLEEP | PCATCH)) != 0) {
+ V_XSLEEP | V_PCATCH)) != 0) {
goto fdout;
}
goto restart;
@@ -2729,7 +2729,7 @@ setfflags(struct thread *td, struct vnode *vp, u_long flags)
return (error);
}
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
+ if ((error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH)) != 0)
return (error);
VATTR_NULL(&vattr);
vattr.va_flags = flags;
@@ -2860,7 +2860,7 @@ setfmode(struct thread *td, struct ucred *cred, struct vnode *vp, int mode)
struct vattr vattr;
int error;
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
+ if ((error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH)) != 0)
return (error);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
VATTR_NULL(&vattr);
@@ -2985,7 +2985,7 @@ setfown(struct thread *td, struct ucred *cred, struct vnode *vp, uid_t uid,
struct vattr vattr;
int error;
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
+ if ((error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH)) != 0)
return (error);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
VATTR_NULL(&vattr);
@@ -3199,7 +3199,7 @@ setutimes(struct thread *td, struct vnode *vp, const struct timespec *ts,
vattr.va_birthtime.tv_sec = VNOVAL;
vattr.va_birthtime.tv_nsec = 0;
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
+ if ((error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH)) != 0)
return (error);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
if (numtimes < 3 && VOP_GETATTR(vp, &vattr, td->td_ucred) == 0 &&
@@ -3471,7 +3471,7 @@ retry:
vp = nd.ni_vp;
NDFREE_PNBUF(&nd);
rl_cookie = vn_rangelock_wlock(vp, 0, OFF_MAX);
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) {
+ if ((error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH)) != 0) {
vn_rangelock_unlock(vp, rl_cookie);
vrele(vp);
return (error);
@@ -3554,7 +3554,7 @@ kern_fsync(struct thread *td, int fd, bool fullsync)
/* XXXKIB: compete outstanding aio writes */;
#endif
retry:
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
+ error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
if (error != 0)
goto drop;
vn_lock(vp, vn_lktype_write(mp, vp) | LK_RETRY);
@@ -3716,7 +3716,7 @@ again:
vrele(tond.ni_startdir);
if (fromnd.ni_startdir != NULL)
vrele(fromnd.ni_startdir);
- error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH);
+ error = vn_start_write(NULL, &mp, V_XSLEEP | V_PCATCH);
if (error != 0)
return (error);
goto again;
@@ -3839,7 +3839,7 @@ restart:
if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
NDFREE_PNBUF(&nd);
vput(nd.ni_dvp);
- if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
+ if ((error = vn_start_write(NULL, &mp, V_XSLEEP | V_PCATCH)) != 0)
return (error);
goto restart;
}
@@ -3948,7 +3948,7 @@ restart:
vrele(nd.ni_dvp);
else
vput(nd.ni_dvp);
- if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
+ if ((error = vn_start_write(NULL, &mp, V_XSLEEP | V_PCATCH)) != 0)
goto fdout;
goto restart;
}
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index a7ca547f571f..04e8cb0037a2 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -271,7 +271,7 @@ restart:
NDFREE_PNBUF(ndp);
vput(ndp->ni_dvp);
if ((error = vn_start_write(NULL, &mp,
- V_XSLEEP | PCATCH)) != 0)
+ V_XSLEEP | V_PCATCH)) != 0)
return (error);
NDREINIT(ndp);
goto restart;
@@ -654,7 +654,7 @@ vn_rdwr(enum uio_rw rw, struct vnode *vp, void *base, int len, off_t offset,
mp = NULL;
if (rw == UIO_WRITE) {
if (vp->v_type != VCHR &&
- (error = vn_start_write(vp, &mp, V_WAIT | PCATCH))
+ (error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH))
!= 0)
goto out;
lock_flags = vn_lktype_write(mp, vp);
@@ -1155,7 +1155,7 @@ vn_write(struct file *fp, struct uio *uio, struct ucred *active_cred, int flags,
mp = NULL;
need_finished_write = false;
if (vp->v_type != VCHR) {
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
+ error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
if (error != 0)
goto unlock;
need_finished_write = true;
@@ -1619,7 +1619,7 @@ retry:
* might happen partly before and partly after the truncation.
*/
rl_cookie = vn_rangelock_wlock(vp, 0, OFF_MAX);
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
+ error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
if (error)
goto out1;
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
@@ -1877,7 +1877,7 @@ vn_start_write_refed(struct mount *mp, int flags, bool mplocked)
mp->mnt_susp_owner != curthread) {
mflags = 0;
if ((mp->mnt_vfc->vfc_flags & VFCF_SBDRY) != 0) {
- if (flags & PCATCH)
+ if (flags & V_PCATCH)
mflags |= PCATCH;
}
mflags |= (PUSER - 1);
@@ -1908,6 +1908,9 @@ vn_start_write(struct vnode *vp, struct mount **mpp, int flags)
struct mount *mp;
int error;
+ KASSERT((flags & ~V_VALID_FLAGS) == 0,
+ ("%s: invalid flags passed %d\n", __func__, flags));
+
error = 0;
/*
* If a vnode is provided, get and return the mount point that
@@ -1950,6 +1953,9 @@ vn_start_secondary_write(struct vnode *vp, struct mount **mpp, int flags)
struct mount *mp;
int error, mflags;
+ KASSERT((flags & ~V_VALID_FLAGS) == 0,
+ ("%s: invalid flags passed %d\n", __func__, flags));
+
retry:
if (vp != NULL) {
if ((error = VOP_GETWRITEMOUNT(vp, mpp)) != 0) {
@@ -1992,7 +1998,7 @@ vn_start_secondary_write(struct vnode *vp, struct mount **mpp, int flags)
*/
mflags = 0;
if ((mp->mnt_vfc->vfc_flags & VFCF_SBDRY) != 0) {
- if (flags & PCATCH)
+ if (flags & V_PCATCH)
mflags |= PCATCH;
}
mflags |= (PUSER - 1) | PDROP;
@@ -3473,7 +3479,7 @@ vn_fallocate(struct file *fp, off_t offset, off_t len, struct thread *td)
bwillwrite();
mp = NULL;
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
+ error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
if (error != 0)
break;
error = vn_lock(vp, LK_EXCLUSIVE);
@@ -3541,7 +3547,7 @@ vn_deallocate_impl(struct vnode *vp, off_t *offset, off_t *length, int flags,
if ((ioflag & IO_NODELOCKED) == 0) {
bwillwrite();
if ((error = vn_start_write(vp, &mp,
- V_WAIT | PCATCH)) != 0)
+ V_WAIT | V_PCATCH)) != 0)
goto out;
vn_lock(vp, vn_lktype_write(mp, vp) | LK_RETRY);
}
diff --git a/sys/security/mac/mac_syscalls.c b/sys/security/mac/mac_syscalls.c
index d8979a70b72d..9bc334686aa4 100644
--- a/sys/security/mac/mac_syscalls.c
+++ b/sys/security/mac/mac_syscalls.c
@@ -430,7 +430,7 @@ sys___mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
break;
}
vp = fp->f_vnode;
- error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
+ error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
if (error != 0) {
mac_vnode_label_free(intlabel);
break;
@@ -536,7 +536,7 @@ kern___mac_set_path(struct thread *td, const char *path_p, struct mac *mac_p,
NDINIT(&nd, LOOKUP, LOCKLEAF | follow, UIO_USERSPACE, path_p);
error = namei(&nd);
if (error == 0) {
- error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH);
+ error = vn_start_write(nd.ni_vp, &mp, V_WAIT | V_PCATCH);
if (error == 0) {
error = vn_setlabel(nd.ni_vp, intlabel,
td->td_ucred);
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index 30b74fef0902..4ae3dd22a390 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -431,6 +431,8 @@ extern int vttoif_tab[];
#define V_WAIT 0x0001 /* vn_start_write: sleep for suspend */
#define V_NOWAIT 0x0002 /* vn_start_write: don't sleep for suspend */
#define V_XSLEEP 0x0004 /* vn_start_write: just return after sleep */
+#define V_PCATCH 0x0008 /* vn_start_write: make the sleep interruptible */
+#define V_VALID_FLAGS (V_WAIT | V_NOWAIT | V_XSLEEP | V_PCATCH)
#define VR_START_WRITE 0x0001 /* vfs_write_resume: start write atomically */
#define VR_NO_SUSPCLR 0x0002 /* vfs_write_resume: do not clear suspension */