From f81fe4b4eef87b68b6c59247463c1ce78c20646b Mon Sep 17 00:00:00 2001 From: Constantine Sapuntzakis Date: Thu, 11 Dec 1997 04:25:47 +0000 Subject: Fix rename in a better way --- sys/ufs/ufs/ufs_lookup.c | 7 ++----- sys/ufs/ufs/ufs_vnops.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'sys') diff --git a/sys/ufs/ufs/ufs_lookup.c b/sys/ufs/ufs/ufs_lookup.c index 625452d69de..4fbea26ed9d 100644 --- a/sys/ufs/ufs/ufs_lookup.c +++ b/sys/ufs/ufs/ufs_lookup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufs_lookup.c,v 1.9 1997/12/11 01:03:17 csapuntz Exp $ */ +/* $OpenBSD: ufs_lookup.c,v 1.10 1997/12/11 04:25:45 csapuntz Exp $ */ /* $NetBSD: ufs_lookup.c,v 1.7 1996/02/09 22:36:06 christos Exp $ */ /* @@ -888,16 +888,13 @@ ufs_direnter(dvp, tvp, dirp, cnp, newdirbp) */ if (error == 0 && dp->i_endoff && dp->i_endoff < dp->i_ffs_size) { -#if 0 /* This code is breaking rename */ if (tvp != NULL) VOP_UNLOCK(tvp, 0, p); -#endif error = VOP_TRUNCATE(dvp, (off_t)dp->i_endoff, IO_SYNC, cr, p); -#if 0 + if (tvp != NULL) vn_lock(tvp, LK_EXCLUSIVE | LK_RETRY, p); -#endif } return (error); } diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c index 1f71e54da9d..d7c65524ce4 100644 --- a/sys/ufs/ufs/ufs_vnops.c +++ b/sys/ufs/ufs/ufs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufs_vnops.c,v 1.17 1997/12/02 17:11:13 csapuntz Exp $ */ +/* $OpenBSD: ufs_vnops.c,v 1.18 1997/12/11 04:25:46 csapuntz Exp $ */ /* $NetBSD: ufs_vnops.c,v 1.18 1996/05/11 18:28:04 mycroft Exp $ */ /* @@ -919,8 +919,11 @@ abortit: (void) relookup(fdvp, &fvp, fcnp); return (VOP_REMOVE(fdvp, fvp, fcnp)); } + if ((error = vn_lock(fvp, LK_EXCLUSIVE, p)) != 0) goto abortit; + + /* fvp, tdvp, tvp now locked */ dp = VTOI(fdvp); ip = VTOI(fvp); if ((ip->i_ffs_flags & (IMMUTABLE | APPEND)) || @@ -954,6 +957,7 @@ abortit: oldparent = dp->i_number; doingdirectory++; } + /* Why? */ vrele(fdvp); /* @@ -994,6 +998,8 @@ abortit: */ error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_proc); VOP_UNLOCK(fvp, 0, p); + + /* tdvp and tvp locked */ if (oldparent != dp->i_number) newparent = dp->i_number; if (doingdirectory && newparent) { @@ -1001,6 +1007,8 @@ abortit: goto bad; if (xp != NULL) vput(tvp); + + /* Only tdvp is locked */ if ((error = ufs_checkpath(ip, dp, tcnp->cn_cred)) != 0) goto out; if ((tcnp->cn_flags & SAVESTART) == 0) @@ -1042,7 +1050,7 @@ abortit: goto bad; } ufs_makedirentry(ip, tcnp, &newdir); - if ((error = ufs_direnter(tdvp, fvp, &newdir, tcnp, NULL)) != 0) { + if ((error = ufs_direnter(tdvp, NULL, &newdir, tcnp, NULL)) != 0) { if (doingdirectory && newparent) { dp->i_effnlink--; dp->i_ffs_nlink--; -- cgit v1.2.3