* Handle ->v_usecount transitioning to 0. * * By releasing the last usecount we take ownership of the hold count which * provides liveness of the vnode, meaning we have to vdrop. * * For all vnodes we may need to perform inactive processing. It requires an * exclusive lock on the vnode, while it is legal to call here with only a * shared lock (or no locks). If locking the vnode in an expect
| 3141 | * can be found by other code. |
| 3142 | */ |
| 3143 | static void |
| 3144 | vput_final(struct vnode *vp, enum vput_op func) |
| 3145 | { |
| 3146 | int error; |
| 3147 | bool want_unlock; |
| 3148 | |
| 3149 | CTR2(KTR_VFS, "%s: vp %p", __func__, vp); |
| 3150 | VNPASS(vp->v_holdcnt > 0, vp); |
| 3151 | |
| 3152 | VI_LOCK(vp); |
| 3153 | |
| 3154 | /* |
| 3155 | * By the time we got here someone else might have transitioned |
| 3156 | * the count back to > 0. |
| 3157 | */ |
| 3158 | if (vp->v_usecount > 0) |
| 3159 | goto out; |
| 3160 | |
| 3161 | /* |
| 3162 | * If the vnode is doomed vgone already performed inactive processing |
| 3163 | * (if needed). |
| 3164 | */ |
| 3165 | if (VN_IS_DOOMED(vp)) |
| 3166 | goto out; |
| 3167 | |
| 3168 | if (__predict_true(VOP_NEED_INACTIVE(vp) == 0)) |
| 3169 | goto out; |
| 3170 | |
| 3171 | if (vp->v_iflag & VI_DOINGINACT) |
| 3172 | goto out; |
| 3173 | |
| 3174 | /* |
| 3175 | * Locking operations here will drop the interlock and possibly the |
| 3176 | * vnode lock, opening a window where the vnode can get doomed all the |
| 3177 | * while ->v_usecount is 0. Set VI_OWEINACT to let vgone know to |
| 3178 | * perform inactive. |
| 3179 | */ |
| 3180 | vp->v_iflag |= VI_OWEINACT; |
| 3181 | want_unlock = false; |
| 3182 | error = 0; |
| 3183 | switch (func) { |
| 3184 | case VRELE: |
| 3185 | switch (VOP_ISLOCKED(vp)) { |
| 3186 | case LK_EXCLUSIVE: |
| 3187 | break; |
| 3188 | case LK_EXCLOTHER: |
| 3189 | case 0: |
| 3190 | want_unlock = true; |
| 3191 | error = vn_lock(vp, LK_EXCLUSIVE | LK_INTERLOCK); |
| 3192 | VI_LOCK(vp); |
| 3193 | break; |
| 3194 | default: |
| 3195 | /* |
| 3196 | * The lock has at least one sharer, but we have no way |
| 3197 | * to conclude whether this is us. Play it safe and |
| 3198 | * defer processing. |
| 3199 | */ |
| 3200 | error = EAGAIN; |