diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c index e46223dc5dca..afa236b4a16e 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: tmpfs_vnops.c,v 1.10 2005/09/15 12:34:35 yamt Exp $ */ +/* $NetBSD: tmpfs_vnops.c,v 1.11 2005/09/23 14:27:55 jmmv Exp $ */ /* * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.10 2005/09/15 12:34:35 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.11 2005/09/23 14:27:55 jmmv Exp $"); #include #include @@ -845,6 +845,14 @@ tmpfs_rename(void *v) } KASSERT(de->td_node == fnode); + /* If we need to move the directory between entries, lock the + * source so that we can safely operate on it. */ + if (fdnode != tdnode) { + error = vn_lock(fdvp, LK_EXCLUSIVE | LK_RETRY); + if (error != 0) + goto out_locked; + } + /* Ensure that we have enough memory to hold the new name, if it * has to be changed. */ if (fcnp->cn_namelen != tcnp->cn_namelen || @@ -941,6 +949,10 @@ tmpfs_rename(void *v) error = 0; +out_locked: + if (fdnode != tdnode) + VOP_UNLOCK(fdvp, 0); + out: /* Release target nodes. */ /* XXX: I don't understand when tdvp can be the same as tvp, but