From 253d9bc480c460d6ddec4a3833f61a4036c1eaa0 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 2 Dec 2017 01:02:59 -0800 Subject: [PATCH] hammer2 - Fix rename race * Fix a rename race in hammer2 which can result in unwanted namecache overloading. When this occurs, a rename operation can wind up deleting the same inode more than once. * This fixes a "hammer2_chain_getparent: no parent" panic in H2. Reported-by: kerma --- sys/vfs/hammer2/hammer2_vnops.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sys/vfs/hammer2/hammer2_vnops.c b/sys/vfs/hammer2/hammer2_vnops.c index 5bed6a7d90..79a3458fc4 100644 --- a/sys/vfs/hammer2/hammer2_vnops.c +++ b/sys/vfs/hammer2/hammer2_vnops.c @@ -2197,9 +2197,16 @@ done2: /* * Issue the namecache update after unlocking all the internal * hammer2 structures, otherwise we might deadlock. + * + * The target namespace must be atomic, so we depend on + * cache_rename() to atomically rename a_fnch to a_tnch + * and then unlink the old a_tnch. If we do it before-hand + * we leave a small window of opportunity where the target + * namespace does not exist that another thread can squeeze + * in and set. */ if (error == 0 && tip) { - cache_unlink(ap->a_tnch); + /*cache_unlink(ap->a_tnch); see above */ cache_setunresolved(ap->a_tnch); } if (error == 0) { -- 2.11.4.GIT