From f63b58d19d13c6b3d4e16962af8c2bf66e1760ae Mon Sep 17 00:00:00 2001 From: jmmv Date: Fri, 23 Sep 2005 14:27:55 +0000 Subject: [PATCH] Lock the source directory during the rename operation so that we are safe to modify it (I hope this is the correct way to go). Avoids triggering an assertion in the tmpfs_dir_detach function, shown by the t_rename regression test. --- sys/fs/tmpfs/tmpfs_vnops.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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