Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F155108998
D33128.id99050.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D33128.id99050.diff
View Options
diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c
--- a/sys/kern/vfs_default.c
+++ b/sys/kern/vfs_default.c
@@ -1293,91 +1293,77 @@
vop_stdis_text(struct vop_is_text_args *ap)
{
- return (ap->a_vp->v_writecount < 0);
+ return (atomic_load_int(&ap->a_vp->v_writecount) < 0);
}
int
vop_stdset_text(struct vop_set_text_args *ap)
{
struct vnode *vp;
- int error, n;
+ int n;
vp = ap->a_vp;
- /*
- * Avoid the interlock if execs are already present.
- */
n = atomic_load_int(&vp->v_writecount);
for (;;) {
- if (n > -1) {
- break;
- }
- if (atomic_fcmpset_int(&vp->v_writecount, &n, n - 1)) {
- return (0);
+ if (__predict_false(n > 0)) {
+ return (ETXTBSY);
}
- }
- VI_LOCK(vp);
- if (vp->v_writecount > 0) {
- error = ETXTBSY;
- } else {
/*
- * If requested by fs, keep a use reference to the
- * vnode until the last text reference is released.
+ * Transition point, we may need to grab a reference on the vnode.
*/
- if ((vn_irflag_read(vp) & VIRF_TEXT_REF) != 0) {
- if (vp->v_writecount == 0) {
- vrefl(vp);
+ if (n == 0) {
+ if (atomic_fcmpset_int(&vp->v_writecount, &n, -1)) {
+ if ((vn_irflag_read(vp) & VIRF_TEXT_REF) != 0) {
+ vref(vp);
+ }
+ return (0);
}
+ continue;
}
- atomic_subtract_int(&vp->v_writecount, 1);
- error = 0;
+ MPASS(n < 0);
+ if (atomic_fcmpset_int(&vp->v_writecount, &n, n - 1)) {
+ return (0);
+ }
}
- VI_UNLOCK(vp);
- return (error);
+ __assert_unreachable();
}
static int
vop_stdunset_text(struct vop_unset_text_args *ap)
{
struct vnode *vp;
- int error, n;
- bool last;
+ int n;
vp = ap->a_vp;
- /*
- * Avoid the interlock if this is not the last exec.
- */
n = atomic_load_int(&vp->v_writecount);
for (;;) {
- if (n >= -1) {
- break;
- }
- if (atomic_fcmpset_int(&vp->v_writecount, &n, n + 1)) {
- return (0);
+ if (__predict_false(n >= 0)) {
+ return (EINVAL);
}
- }
- last = false;
- VI_LOCK(vp);
- if (vp->v_writecount < 0) {
- if ((vn_irflag_read(vp) & VIRF_TEXT_REF) != 0) {
- if (vp->v_writecount == -1) {
- last = true;
+ /*
+ * Transition point, we may need to release a reference on the vnode.
+ */
+ if (n == -1) {
+ if (atomic_fcmpset_int(&vp->v_writecount, &n, 0)) {
+ if ((vn_irflag_read(vp) & VIRF_TEXT_REF) != 0) {
+ vunref(vp);
+ }
+ return (0);
}
+ continue;
}
- atomic_add_int(&vp->v_writecount, 1);
- error = 0;
- } else {
- error = EINVAL;
+ MPASS(n < -1);
+ if (atomic_fcmpset_int(&vp->v_writecount, &n, n + 1)) {
+ return (0);
+ }
}
- VI_UNLOCK(vp);
- if (last)
- vunref(vp);
- return (error);
+ __assert_unreachable();
}
static int __always_inline
@@ -1400,20 +1386,25 @@
}
#endif
- VI_LOCK_FLAGS(vp, MTX_DUPOK);
- if (__predict_false(vp->v_writecount < 0)) {
- error = ETXTBSY;
- } else {
- VNASSERT(vp->v_writecount + ap->a_inc >= 0, vp,
- ("neg writecount increment %d", ap->a_inc));
- if (handle_msync && vp->v_writecount == 0) {
- vlazy(vp);
+ for (;;) {
+ if (__predict_false(n < 0)) {
+ return (ETXTBSY);
+ }
+
+ VNASSERT(n + ap->a_inc >= 0, vp,
+ ("neg writecount increment %d + %d = %d", n, ap->a_inc,
+ n + ap->a_inc));
+ if (n == 0) {
+ if (handle_msync && vp->v_writecount == 0) {
+ vlazy(vp);
+ }
+ }
+
+ if (atomic_fcmpset_int(&vp->v_writecount, &n, n + ap->a_inc)) {
+ return (0);
}
- vp->v_writecount += ap->a_inc;
- error = 0;
}
- VI_UNLOCK(vp);
- return (error);
+ __assert_unreachable();
}
int
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, May 2, 11:29 AM (16 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32617166
Default Alt Text
D33128.id99050.diff (3 KB)
Attached To
Mode
D33128: vfs: fully lockless v_writecount adjustment
Attached
Detach File
Event Timeline
Log In to Comment