Changeset View
Changeset View
Standalone View
Standalone View
sys/fs/nullfs/null_vnops.c
| Show First 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | |||||
| #include <sys/lock.h> | #include <sys/lock.h> | ||||
| #include <sys/malloc.h> | #include <sys/malloc.h> | ||||
| #include <sys/mount.h> | #include <sys/mount.h> | ||||
| #include <sys/mutex.h> | #include <sys/mutex.h> | ||||
| #include <sys/namei.h> | #include <sys/namei.h> | ||||
| #include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
| #include <sys/vnode.h> | #include <sys/vnode.h> | ||||
| #include <sys/stat.h> | #include <sys/stat.h> | ||||
| #include <sys/proc.h> | |||||
| #include <sys/smr.h> | |||||
| #include <fs/nullfs/null.h> | #include <fs/nullfs/null.h> | ||||
| #include <vm/vm.h> | #include <vm/vm.h> | ||||
| #include <vm/vm_extern.h> | #include <vm/vm_extern.h> | ||||
| #include <vm/vm_object.h> | #include <vm/vm_object.h> | ||||
| #include <vm/vnode_pager.h> | #include <vm/vnode_pager.h> | ||||
| VFS_SMR_DECLARE; | |||||
| static int null_bug_bypass = 0; /* for debugging: enables bypass printf'ing */ | static int null_bug_bypass = 0; /* for debugging: enables bypass printf'ing */ | ||||
| SYSCTL_INT(_debug, OID_AUTO, nullfs_bug_bypass, CTLFLAG_RW, | SYSCTL_INT(_debug, OID_AUTO, nullfs_bug_bypass, CTLFLAG_RW, | ||||
| &null_bug_bypass, 0, ""); | &null_bug_bypass, 0, ""); | ||||
| static bool null_smr_lock = true; | |||||
mjg: this is a profiling aid and wont be committed | |||||
| SYSCTL_BOOL(_debug, OID_AUTO, nullfs_smr_lock, CTLFLAG_RW, | |||||
| &null_smr_lock, 0, ""); | |||||
| /* | /* | ||||
| * Synchronize inotify flags with the lower vnode: | * Synchronize inotify flags with the lower vnode: | ||||
| * - If the upper vnode has the flag set and the lower does not, then the lower | * - If the upper vnode has the flag set and the lower does not, then the lower | ||||
| * vnode is unwatched and the upper vnode does not need to go through | * vnode is unwatched and the upper vnode does not need to go through | ||||
| * VOP_INOTIFY. | * VOP_INOTIFY. | ||||
| * - If the lower vnode is watched, then the upper vnode should go through | * - If the lower vnode is watched, then the upper vnode should go through | ||||
| * VOP_INOTIFY, so copy the flag up. | * VOP_INOTIFY, so copy the flag up. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 567 Lines • ▼ Show 20 Lines | null_rmdir(struct vop_rmdir_args *ap) | ||||
| return (null_bypass(&ap->a_gen)); | return (null_bypass(&ap->a_gen)); | ||||
| } | } | ||||
| /* | /* | ||||
| * We need to process our own vnode lock and then clear the | * We need to process our own vnode lock and then clear the | ||||
| * interlock flag as it applies only to our vnode, not the | * interlock flag as it applies only to our vnode, not the | ||||
| * vnodes below us on the stack. | * vnodes below us on the stack. | ||||
| */ | */ | ||||
| static int | |||||
| null_lock_smr(struct vnode *vp, int flags) | |||||
| { | |||||
| struct null_node *nn; | |||||
| struct vnode *lvp; | |||||
| int error; | |||||
| if (!atomic_load_bool(&null_smr_lock)) | |||||
| return (EAGAIN); | |||||
Not Done Inline ActionsThe initialization can be moved out of smr region. kib: The initialization can be moved out of smr region. | |||||
| vfs_smr_enter(); | |||||
| nn = VTONULL_SMR(vp); | |||||
| if (__predict_false(nn == NULL)) | |||||
| goto out_bad; | |||||
| lvp = nn->null_lowervp; | |||||
| if (__predict_false(lvp == NULL)) | |||||
| goto out_bad; | |||||
| if (__predict_false(!vhold_smr(lvp))) | |||||
| goto out_bad; | |||||
Not Done Inline Actionsout_bad can be removed. Initialize lvp with NULL, and re-assign it to NULL if vhold_smr() failed. kib: out_bad can be removed. Initialize lvp with NULL, and re-assign it to NULL if vhold_smr()… | |||||
Done Inline Actionsyou mean something like this? vfs_smr_enter();
lvp = NULL;
nn = VTONULL_SMR(ap->a_vp);
if (nn != NULL) {
lvp = nn->null_lowervp;
if (lvp != NULL) {
if (!vhold_smr(lvp)) {
lvp = NULL;
}
}
}
vfs_smr_exit();
return (lvp);i think that's less amenable to changes later anyway i'm not going to argue about this, just spell out the implementation you want and i'll include it mjg: you mean something like this?
```
vfs_smr_enter();
lvp = NULL… | |||||
Not Done Inline ActionsFor me, this version is more readable. I would even write if (lvp != NULL && !vhold_smr(lvp))
lvp = NULL;kib: For me, this version is more readable. I would even write
```
if (lvp != NULL && !vhold_smr… | |||||
| vfs_smr_exit(); | |||||
| error = VOP_LOCK(lvp, flags); | |||||
| if (VTONULL(vp) == NULL && error == 0) { | |||||
| VOP_UNLOCK(lvp); | |||||
| error = EAGAIN; | |||||
| } | |||||
| vdrop(lvp); | |||||
| return (error); | |||||
| out_bad: | |||||
| vfs_smr_exit(); | |||||
| return (EAGAIN); | |||||
| } | |||||
| static int | static int | ||||
| null_lock(struct vop_lock1_args *ap) | null_lock(struct vop_lock1_args *ap) | ||||
| { | { | ||||
| struct vnode *vp = ap->a_vp; | struct vnode *vp = ap->a_vp; | ||||
| int flags; | int flags; | ||||
| struct null_node *nn; | struct null_node *nn; | ||||
| struct vnode *lvp; | struct vnode *lvp; | ||||
| int error; | int error; | ||||
| if ((ap->a_flags & LK_INTERLOCK) == 0) | if ((ap->a_flags & LK_INTERLOCK) == 0) { | ||||
| VI_LOCK(vp); | error = null_lock_smr(vp, ap->a_flags); | ||||
| else | if (error == 0) | ||||
| return (error); | |||||
| VI_LOCK(vp); | |||||
| } else { | |||||
| ap->a_flags &= ~LK_INTERLOCK; | ap->a_flags &= ~LK_INTERLOCK; | ||||
| } | |||||
| flags = ap->a_flags; | flags = ap->a_flags; | ||||
| nn = VTONULL(vp); | nn = VTONULL(vp); | ||||
| /* | /* | ||||
| * If we're still active we must ask the lower layer to | * If we're still active we must ask the lower layer to | ||||
| * lock as ffs has special lock considerations in its | * lock as ffs has special lock considerations in its | ||||
| * vop lock. | * vop lock. | ||||
| */ | */ | ||||
| if (nn != NULL && (lvp = NULLVPTOLOWERVP(vp)) != NULL) { | if (nn != NULL && (lvp = NULLVPTOLOWERVP(vp)) != NULL) { | ||||
| Show All 32 Lines | if (VTONULL(vp) == NULL && error == 0) { | ||||
| panic("Unsupported lock request %d\n", | panic("Unsupported lock request %d\n", | ||||
| ap->a_flags); | ap->a_flags); | ||||
| } | } | ||||
| VOP_UNLOCK(lvp); | VOP_UNLOCK(lvp); | ||||
| error = vop_stdlock(ap); | error = vop_stdlock(ap); | ||||
| } | } | ||||
| vdrop(lvp); | vdrop(lvp); | ||||
| } else { | } else { | ||||
| VI_UNLOCK(vp); | VI_UNLOCK(vp); | ||||
Not Done Inline ActionsThat line could be moved at top of the block. olce: That line could be moved at top of the block. | |||||
| error = vop_stdlock(ap); | error = vop_stdlock(ap); | ||||
| } | } | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| /* | /* | ||||
| * We need to process our own vnode unlock and then clear the | * We need to process our own vnode unlock and then clear the | ||||
| * interlock flag as it applies only to our vnode, not the | * interlock flag as it applies only to our vnode, not the | ||||
| * vnodes below us on the stack. | * vnodes below us on the stack. | ||||
| */ | */ | ||||
| static int | static int | ||||
| null_unlock(struct vop_unlock_args *ap) | null_unlock(struct vop_unlock_args *ap) | ||||
| { | { | ||||
| struct vnode *vp = ap->a_vp; | struct vnode *vp = ap->a_vp; | ||||
| struct null_node *nn; | struct null_node *nn; | ||||
| struct vnode *lvp; | struct vnode *lvp; | ||||
| int error; | int error; | ||||
| nn = VTONULL(vp); | nn = VTONULL(vp); | ||||
| if (nn != NULL && (lvp = NULLVPTOLOWERVP(vp)) != NULL) { | if (nn != NULL && (lvp = NULLVPTOLOWERVP(vp)) != NULL) { | ||||
| vholdnz(lvp); | vholdnz(lvp); | ||||
| error = VOP_UNLOCK(lvp); | error = VOP_UNLOCK(lvp); | ||||
| vdrop(lvp); | vdrop(lvp); | ||||
mjgAuthorUnsubmitted Done Inline ActionsThis ref trip is no longer of any use, is it? mjg: This ref trip is no longer of any use, is it? | |||||
| } else { | } else { | ||||
| error = vop_stdunlock(ap); | error = vop_stdunlock(ap); | ||||
| } | } | ||||
Done Inline Actionsthis needs rewording. VOP_UNLOCK promises to not touch anything past unlock and this routine itself also does not mjg: this needs rewording. VOP_UNLOCK promises to not touch anything past unlock and this routine… | |||||
| return (error); | return (error); | ||||
| } | } | ||||
| /* | /* | ||||
| * Do not allow the VOP_INACTIVE to be passed to the lower layer, | * Do not allow the VOP_INACTIVE to be passed to the lower layer, | ||||
| * since the reference count on the lower vnode is not related to | * since the reference count on the lower vnode is not related to | ||||
| * ours. | * ours. | ||||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | else if (vp->v_writecount < 0) | ||||
| vp->v_writecount = 0; | vp->v_writecount = 0; | ||||
| VI_UNLOCK(vp); | VI_UNLOCK(vp); | ||||
| if ((xp->null_flags & NULLV_NOUNLOCK) != 0) | if ((xp->null_flags & NULLV_NOUNLOCK) != 0) | ||||
| vunref(lowervp); | vunref(lowervp); | ||||
| else | else | ||||
| vput(lowervp); | vput(lowervp); | ||||
| free(xp, M_NULLFSNODE); | uma_zfree_smr(null_node_zone, xp); | ||||
| return (0); | return (0); | ||||
| } | } | ||||
| static int | static int | ||||
| null_print(struct vop_print_args *ap) | null_print(struct vop_print_args *ap) | ||||
| { | { | ||||
| struct vnode *vp = ap->a_vp; | struct vnode *vp = ap->a_vp; | ||||
| ▲ Show 20 Lines • Show All 245 Lines • Show Last 20 Lines | |||||
this is a profiling aid and wont be committed