- if (tvp && (tvp->v_usecount>(UBCISVALID(tvp) ? 2 : 1)) &&
- !VTONFS(tvp)->n_sillyrename &&
- tvp->v_type != VDIR && !nfs_sillyrename(tdvp, tvp, tcnp)) {
- vput(tvp);
- tvp = NULL;
+ if (tvp && tvp != fvp) {
+ if (UBCISVALID(tvp)) {
+ /* regular files */
+ if (UBCINFOEXISTS(tvp))
+ inuse = (ubc_isinuse(tvp, 1)) ? 1 : 0;
+ else {
+ /* dead or dying vnode.With vnode locking panic instead of error */
+ error = EIO;
+ VOP_UNLOCK(tvp, 0, tcnp->cn_proc);
+ goto out;
+ }
+ } else {
+ /* UBC not in play */
+ if (tvp->v_usecount > 1)
+ inuse = 1;
+ }
+ }
+ if (inuse && !VTONFS(tvp)->n_sillyrename && tvp->v_type != VDIR) {
+ if (error = nfs_sillyrename(tdvp, tvp, tcnp)) {
+ /* sillyrename failed. Instead of pressing on, return error */
+ goto out; /* should not be ENOENT. */
+ } else {
+ /* sillyrename succeeded.*/
+ VOP_UNLOCK(tvp, 0, tcnp->cn_proc);
+ ubc_uncache(tvp); /* get the nfs turd file to disappear */
+ vrele(tvp);
+ tvp = NULL;
+ }