From nobody Thu Feb 24 21:07:43 2022 X-Original-To: dev-commits-src-all@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 8345F19CE71A; Thu, 24 Feb 2022 21:07:43 +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 4K4QTq1z6qz4kNw; Thu, 24 Feb 2022 21:07:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645736863; 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=kiPtT1cIHF52jVgOfzTGRMmxMnFPOijo5qoanTnuOt4=; b=nQgOH3HuLWck+z/r+il6oiJSTE3U6saqEA0JOi0H1C4HoTDtxG7q04HKWOatF+f9/dhreH vtcb0l6i13R11O0yJAeje1IveTAcAtybcJilXX+pqfOZ2PsVNcFL4283KI5V7j5RvuYOYj IFk6h9RWd69bDS7ixiIOB1yFafC83oX52edpOtcOYwwhjE5I94WWM+DjLEedoGPx4hMV8y 3irYTeG6VqEnJ6AWiYrEbugdan8xC/eGcQsad0t7nZ9pBLsFeSQ8lGC8KF61+7aeplzhWB PUeqEcM4X9mf22riWmHA8rG1+r6ONTVRzkRWYoU/nv+fLVHnvHpNXIVeBHJpAQ== 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 234B7132A3; Thu, 24 Feb 2022 21:07:43 +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 21OL7hZg090229; Thu, 24 Feb 2022 21:07:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21OL7h1L090228; Thu, 24 Feb 2022 21:07:43 GMT (envelope-from git) Date: Thu, 24 Feb 2022 21:07:43 GMT Message-Id: <202202242107.21OL7h1L090228@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: e8553be9bcfc - main - fusefs: fix a cached attributes bug during directory rename List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: e8553be9bcfc2c0d78e9f379bd166dc0a9cae719 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645736863; 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=kiPtT1cIHF52jVgOfzTGRMmxMnFPOijo5qoanTnuOt4=; b=CPwu77Lg55+0cpKd7oN43gikRL4g8WZsAkNdbMFnI+0vxCMwfQEVMmuQ1ps7qqbnUJwdM6 41EYn/nQ9y0hR1suv9i7BWTJhZsXoTE4sZRDzXnvpwT9g2+foNu6lPU7ThRu1f0XhXurXx o0eTBe6UVNcSa310sTJx/Wvyy/GG5LW2EyXLHxSJqfVlSl3STBiZbA6knla0i9L2R7eV/c BCShgGroV94NbpmzaKzS7Q9303h8bngedFddVDe5MHAUt3Z3c8sDjx/AToxy1JIKA3JB/E HPf3zozUm2P3hpZV7odqWaC9BWB6my1KaRUC/YIDieXnYPHKAsZscTgf4yvSJA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645736863; a=rsa-sha256; cv=none; b=YyBoZoZX2uwImVOzgSmtB/F2mxYwBfgtCDXNlmrPiYf+lZFBTLr5HuiW9rW02/ruXQvNUG 7FsTN/SnhYH+ga/sGas2MmtQRrpqpm/Ax3SJbj9IANp2L2IwOrqgo4MhZKcde0fPn+PnF4 u6bxHQXIKl5zHvG07e+NqvYnF7mkovZ742AaidY2zT1EmTXTQwPJ2QojlUWB6OXd7wc0B7 OZBaHVZ2/1OWOyHkUxr+CknT3eOS//1i+R38d9gny5+OACjyFd7tkjNj+2BWrQ9R2of7jO 1ZNGOZQeXbdhyVt9vT6epLhn2C9mx1Ou/IDnuB3+8nTasUXxp76vfJ/iiNl+vw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=e8553be9bcfc2c0d78e9f379bd166dc0a9cae719 commit e8553be9bcfc2c0d78e9f379bd166dc0a9cae719 Author: Alan Somers AuthorDate: 2022-02-22 05:00:42 +0000 Commit: Alan Somers CommitDate: 2022-02-24 21:07:25 +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. MFC after: 1 week Reviewed by: ngie Differential Revision: https://reviews.freebsd.org/D34336 --- 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 3de44bf6a023..c7730cf7c606 100644 --- a/sys/fs/fuse/fuse_vnops.c +++ b/sys/fs/fuse/fuse_vnops.c @@ -2084,7 +2084,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); }