From nobody Sat Aug 20 00:31:36 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4M8fgs1B3wz4ZcW8; Sat, 20 Aug 2022 00:31:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4M8fgs0ZN8z41XV; Sat, 20 Aug 2022 00:31:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660955497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=srQTnyCX0kup9Uolwe/rMwnWLtCYyfR8YCjiYcJlSP4=; b=SPa5Uiq1AZ37IAQBJeQoa6H+UhOetn+Fl7fMY7NlErmDXCAlxCI7+ITyws1AdGI7BDql7F Af24vWeONkpggpOu1cekMspMnv2HIH+/q/raYNCQ7sSfgs+o4GG1bv0fx6OuNbOwWvMTwV g7uGa+bf/sksqdoaR9fUsFTJFztLJvWxwiOVgpsWdKkE0qOVv6jUobaR1Tws6oHSwy4Y8T mgyiF2l1hPNdMqAbQ3T/WoE/QwbWSmcBX7T23B4vay3cu2z2uPE1Brj+4fIaa+mXghuZCW p0jKb0zfQ/e5mPkQkUoqPkmQIzNvCPQ0A7bDDPvUML8V1Spk9qW4c1c095ge7A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4M8fgr6lq3z1C3g; Sat, 20 Aug 2022 00:31:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 27K0Vatg050535; Sat, 20 Aug 2022 00:31:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27K0VaRs050534; Sat, 20 Aug 2022 00:31:36 GMT (envelope-from git) Date: Sat, 20 Aug 2022 00:31:36 GMT Message-Id: <202208200031.27K0VaRs050534@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: a9d0655fa413 - stable/12 - fusefs: fix a cached attributes bug during directory rename List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: a9d0655fa413ef10592815c9e123e6dc7b412b65 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660955497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=srQTnyCX0kup9Uolwe/rMwnWLtCYyfR8YCjiYcJlSP4=; b=JP12UQpAc9QtLOf6OUhOp9CVXrkQl81yVP6mUxJwOqMPdaFr/rmYde7cclNsr4Aklkk0Iv ljdqrWmcg5+9UfhGC8xULJgV3bazDQaJJvA6T01vsZ9lf2J+MVgqs1/++lMWbVnzw1TmQQ EHwhXgJVCGw/R7Sfz+YcIOIKQqm9+6lg+ybDtX231yInYOKOICyaMe7Ee7aaTswYUEYWb9 PdCdZC6+quxjjbb6ZbfAwr9qn8MKOS1whowK1QhcJIlbUHgYMivct/TILLkrv2ra4iG+eS CsckuiAeXQen/PUNAi0te3+ducHgxoCd3vFAV57wShExeVvRHmj52rDVj0fiSw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660955497; a=rsa-sha256; cv=none; b=eZEhkRIKe85LIsJVdVAqcFDLVQpw015QzLTsDWIG3apDKU2wVfVFxRidz1TijV7MEyYBmO T2e4Ah9YqOFrTtLW1D9Tsev1CcmlELGj8xH8hozF2WZ5GRGuXnt/XsKnvIwjGtI0NFWUFX LKP4m1MLIStnI+HnFRwBKn3Bpu9c/of+a+l8iwVetFoF6DedxmuKl/Md4Zp5tivRGh44ZW Z1NDKb1qHmytTn3oQyawORGTR0SCTgEK03NauUlQac3G9rfyL41YqRjo2iXfn7n9ee/aVq 4S39Zt1C6qqkOfCou3v6e1xE55aReN/CFLh2KIWCXJ0oLxS9CTs2mKyr3WiYkw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=a9d0655fa413ef10592815c9e123e6dc7b412b65 commit a9d0655fa413ef10592815c9e123e6dc7b412b65 Author: Alan Somers AuthorDate: 2022-02-22 05:00:42 +0000 Commit: Alan Somers CommitDate: 2022-08-19 22:44:11 +0000 fusefs: fix a cached attributes bug during directory rename When renaming a directory into a different parent directory, invalidate the cached attributes of the new parent. Otherwise, stat will show the wrong st_nlink value. Reviewed by: ngie Differential Revision: https://reviews.freebsd.org/D34336 (cherry picked from commit e8553be9bcfc2c0d78e9f379bd166dc0a9cae719) --- sys/fs/fuse/fuse_vnops.c | 2 +- tests/sys/fs/fusefs/rename.cc | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/sys/fs/fuse/fuse_vnops.c b/sys/fs/fuse/fuse_vnops.c index bd55a21358ba..9e7cd474e29a 100644 --- a/sys/fs/fuse/fuse_vnops.c +++ b/sys/fs/fuse/fuse_vnops.c @@ -1647,7 +1647,7 @@ fuse_vnop_rename(struct vop_rename_args *ap) cache_purge(tvp); } if (vnode_isdir(fvp)) { - if ((tvp != NULL) && vnode_isdir(tvp)) { + if (((tvp != NULL) && vnode_isdir(tvp)) || vnode_isdir(fvp)) { cache_purge(tdvp); } cache_purge(fdvp); diff --git a/tests/sys/fs/fusefs/rename.cc b/tests/sys/fs/fusefs/rename.cc index ba1d5ec1ec6d..23d25c9965bf 100644 --- a/tests/sys/fs/fusefs/rename.cc +++ b/tests/sys/fs/fusefs/rename.cc @@ -221,7 +221,8 @@ TEST_F(Rename, parent) const char RELDST[] = "dst"; const char FULLSRC[] = "mountpoint/src"; const char RELSRC[] = "src"; - const char FULLDSTPARENT[] = "mountpoint/dstdir/dst/.."; + const char FULLDSTPARENT[] = "mountpoint/dstdir"; + const char FULLDSTDOTDOT[] = "mountpoint/dstdir/dst/.."; Sequence seq; uint64_t dst_dir_ino = 43; uint64_t ino = 42; @@ -229,13 +230,14 @@ TEST_F(Rename, parent) expect_lookup(RELSRC, ino, S_IFDIR | 0755, 0, 1); EXPECT_LOOKUP(FUSE_ROOT_ID, RELDSTDIR) - .WillRepeatedly(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { + .WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { SET_OUT_HEADER_LEN(out, entry); out.body.entry.nodeid = dst_dir_ino; out.body.entry.entry_valid = UINT64_MAX; out.body.entry.attr_valid = UINT64_MAX; out.body.entry.attr.mode = S_IFDIR | 0755; out.body.entry.attr.ino = dst_dir_ino; + out.body.entry.attr.nlink = 2; }))); EXPECT_LOOKUP(dst_dir_ino, RELDST) .InSequence(seq) @@ -252,6 +254,31 @@ TEST_F(Rename, parent) }, Eq(true)), _) ).WillOnce(Invoke(ReturnErrno(0))); + EXPECT_CALL(*m_mock, process( + ResultOf([](auto in) { + return (in.header.opcode == FUSE_GETATTR && + in.header.nodeid == 1); + }, Eq(true)), + _) + ).InSequence(seq) + .WillOnce(Invoke(ReturnImmediate([=](auto i __unused, auto& out) { + SET_OUT_HEADER_LEN(out, attr); + out.body.attr.attr_valid = UINT64_MAX; + out.body.attr.attr.ino = 1; + out.body.attr.attr.mode = S_IFDIR | 0755; + out.body.attr.attr.nlink = 2; + }))); + EXPECT_LOOKUP(FUSE_ROOT_ID, RELDSTDIR) + .InSequence(seq) + .WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { + SET_OUT_HEADER_LEN(out, entry); + out.body.entry.nodeid = dst_dir_ino; + out.body.entry.entry_valid = UINT64_MAX; + out.body.entry.attr_valid = UINT64_MAX; + out.body.entry.attr.mode = S_IFDIR | 0755; + out.body.entry.attr.ino = dst_dir_ino; + out.body.entry.attr.nlink = 3; + }))); EXPECT_LOOKUP(dst_dir_ino, RELDST) .InSequence(seq) .WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { @@ -263,7 +290,14 @@ TEST_F(Rename, parent) }))); ASSERT_EQ(0, rename(FULLSRC, FULLDST)) << strerror(errno); + + ASSERT_EQ(0, stat("mountpoint", &sb)) << strerror(errno); + EXPECT_EQ(2ul, sb.st_nlink); + ASSERT_EQ(0, stat(FULLDSTPARENT, &sb)) << strerror(errno); + EXPECT_EQ(3ul, sb.st_nlink); + + ASSERT_EQ(0, stat(FULLDSTDOTDOT, &sb)) << strerror(errno); ASSERT_EQ(dst_dir_ino, sb.st_ino); }