From nobody Fri Apr 29 20:00:31 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 8E4C71AAFC0D; Fri, 29 Apr 2022 20:00:31 +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 4Kqjyl3XCDz54Yf; Fri, 29 Apr 2022 20:00:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651262431; 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=Edd0Lhs38GOUo4RVKGo8mVveferCPRS3vJgRg+H8Nlo=; b=x7HnayFaUqxz6CiY+PDqAFLHMxXrAn0V+VF6PHEwfUY+xh4OtkNsP6ni49al3Xiletdp03 YTEVw/6CuSS16x4jx6Pdu8GdLX+GCkmFc66WrcylpdflJYcI86LHhY8Cc3M9efc3h+ezPl OEGLPQS25IQtP3hlV9zgtDHTlB9TBu0/GtOAxogY8Vp9kQbJlY+N0PwgysayyEZtT/lN11 shQPhoPOeSrLpg+BYD5sBDxHJ837wygUSaVlIXWS9DImhisPDC9l2Oi64gO7oQSBxrscKe fyBRXMHBqbQaIqGmmuCvGCgHxfsO5fjzZXKnEGCVxQYTgN+vLH9Jibm8TWYbxw== 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 58BBB1347E; Fri, 29 Apr 2022 20:00:31 +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 23TK0VWg083065; Fri, 29 Apr 2022 20:00:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23TK0Vcl083064; Fri, 29 Apr 2022 20:00:31 GMT (envelope-from git) Date: Fri, 29 Apr 2022 20:00:31 GMT Message-Id: <202204292000.23TK0Vcl083064@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: 507b75ced9fd - stable/13 - fusefs: fix two bugs regarding VOP_RECLAIM of the root inode 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 507b75ced9fd9f0477e3f5ce1a80b14b2ba26c31 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651262431; 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=Edd0Lhs38GOUo4RVKGo8mVveferCPRS3vJgRg+H8Nlo=; b=y0r61NoGzYFwj5PbTsqbDF3Z+nJMXhjrFPPySdqVJExUow70LZUmUvGGF2pl9LBhIf2U0u Z44MgL8xqCPlQFVuzPgbNeZ/NcTyJP/fRcbREnX8xoaxEaTms8sAya/7gFuMJ9rmG2yZ+b JOSGs0PjNXiXKf4HRE1+kKZF90KXM26fWB5aCpZnI6N4q/ZZxAufK6k6bfMDG4yGXBjukQ m1qWQ1M63gWn6IWar+y7KiThJdutO4JnfQLsqkCiQt+JmAmFqehC624duNdcxeyJIFNij7 AokaGFSVE61rbjENSMcgTjCIh3IR/gT+Zd3cEVtl5m1jKPEpJdkki3q1taqL8Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651262431; a=rsa-sha256; cv=none; b=g9rGt2Uq9qnZFUl7K5DLJ+F+IkEEraRj8hRBY4VPGkpYXTySdOvYJ8U40FTsAY48pPOgAH 1UeOktS9SGd33Gl7tSx473XXT/YDgkfOM5k/Y1sVfKrg2q2a3RmVKBUHJvYMRhS18Kw3Bk Y35AMlzJsF4i03iWWzSDaXn8EGijZ7P4BKoMcugDHQWyECI/XrfbKXvLhzR9P0ZNOd+z/v A1esXwMJ3g7DZFYmM+nUAq6i6z2i16+HgM/01tPNVdr1wosixZyDwhc6snLGmxnBdK0ciD ImoD+L0j/f5xx8vMgarLbMPh5jTvoksKybK/NCF2DfLYdoKXckcx89iTEVUwJQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=507b75ced9fd9f0477e3f5ce1a80b14b2ba26c31 commit 507b75ced9fd9f0477e3f5ce1a80b14b2ba26c31 Author: Alan Somers AuthorDate: 2022-04-02 19:31:24 +0000 Commit: Alan Somers CommitDate: 2022-04-29 17:16:00 +0000 fusefs: fix two bugs regarding VOP_RECLAIM of the root inode * We never send FUSE_LOOKUP for the root inode, since its inode number is hard-coded to 1. Therefore, we should not send FUSE_FORGET for it, lest the server see its lookup count fall below 0. * During VOP_RECLAIM, if we are reclaiming the root inode, we must clear the file system's vroot pointer. Otherwise it will be left pointing at a reclaimed vnode, which will cause future VOP_LOOKUP operations to fail. Previously we only cleared that pointer during VFS_UMOUNT. I don't know of any real-world way to trigger this bug. Reviewed by: pfg Differential Revision: https://reviews.freebsd.org/D34753 (cherry picked from commit 32273253667b941c376cf08383006b3a0cbc5ca2) --- sys/fs/fuse/fuse_vnops.c | 19 ++++++++++++++++++- tests/sys/fs/fusefs/destroy.cc | 1 - tests/sys/fs/fusefs/dev_fuse_poll.cc | 1 - tests/sys/fs/fusefs/forget.cc | 33 +++++++++++++++++++++++++++++++++ tests/sys/fs/fusefs/lookup.cc | 2 -- 5 files changed, 51 insertions(+), 5 deletions(-) diff --git a/sys/fs/fuse/fuse_vnops.c b/sys/fs/fuse/fuse_vnops.c index ba9f19e5798b..e34cebe15772 100644 --- a/sys/fs/fuse/fuse_vnops.c +++ b/sys/fs/fuse/fuse_vnops.c @@ -1981,7 +1981,24 @@ fuse_vnop_reclaim(struct vop_reclaim_args *ap) fuse_filehandle_close(vp, fufh, td, NULL); } - if (!fuse_isdeadfs(vp) && fvdat->nlookup > 0) { + if (VTOI(vp) == 1) { + /* + * Don't send FUSE_FORGET for the root inode, because + * we never send FUSE_LOOKUP for it (see + * fuse_vfsop_root) and we don't want the server to see + * mismatched lookup counts. + */ + struct fuse_data *data; + struct vnode *vroot; + + data = fuse_get_mpdata(vnode_mount(vp)); + FUSE_LOCK(); + vroot = data->vroot; + data->vroot = NULL; + FUSE_UNLOCK(); + if (vroot) + vrele(vroot); + } else if (!fuse_isdeadfs(vp) && fvdat->nlookup > 0) { fuse_internal_forget_send(vnode_mount(vp), td, NULL, VTOI(vp), fvdat->nlookup); } diff --git a/tests/sys/fs/fusefs/destroy.cc b/tests/sys/fs/fusefs/destroy.cc index e72464382d4e..91c22ba6975e 100644 --- a/tests/sys/fs/fusefs/destroy.cc +++ b/tests/sys/fs/fusefs/destroy.cc @@ -141,7 +141,6 @@ TEST_F(Destroy, ok) uint64_t ino = 42; expect_lookup(RELPATH, ino, S_IFREG | 0644, 0, 2); - expect_forget(FUSE_ROOT_ID, 1); expect_forget(ino, 2); expect_destroy(0); diff --git a/tests/sys/fs/fusefs/dev_fuse_poll.cc b/tests/sys/fs/fusefs/dev_fuse_poll.cc index 951777701e1e..5ac66a915ea5 100644 --- a/tests/sys/fs/fusefs/dev_fuse_poll.cc +++ b/tests/sys/fs/fusefs/dev_fuse_poll.cc @@ -93,7 +93,6 @@ TEST_P(DevFusePoll, access) /* Ensure that we wake up pollers during unmount */ TEST_P(DevFusePoll, destroy) { - expect_forget(FUSE_ROOT_ID, 1); expect_destroy(0); m_mock->unmount(); diff --git a/tests/sys/fs/fusefs/forget.cc b/tests/sys/fs/fusefs/forget.cc index 84fc271df57c..d520ba84dbdd 100644 --- a/tests/sys/fs/fusefs/forget.cc +++ b/tests/sys/fs/fusefs/forget.cc @@ -32,6 +32,7 @@ extern "C" { #include +#include #include #include @@ -145,3 +146,35 @@ TEST_F(Forget, invalidate_names) /* Access the file again, causing another lookup */ ASSERT_EQ(0, access(FULLFPATH, F_OK)) << strerror(errno); } + +/* + * Reclaiming the root inode should not send a FUSE_FORGET request, nor should + * it interfere with further lookup operations. + */ +TEST_F(Forget, root) +{ + const char FULLPATH[] = "mountpoint/some_file.txt"; + const char RELPATH[] = "some_file.txt"; + uint64_t ino = 42; + mode_t mode = S_IFREG | 0755; + + EXPECT_LOOKUP(FUSE_ROOT_ID, RELPATH) + .WillRepeatedly(Invoke( + ReturnImmediate([=](auto in __unused, auto& out) { + SET_OUT_HEADER_LEN(out, entry); + out.body.entry.attr.mode = mode; + out.body.entry.nodeid = ino; + out.body.entry.attr.nlink = 1; + out.body.entry.attr_valid = UINT64_MAX; + out.body.entry.entry_valid = UINT64_MAX; + }))); + + /* access(2) the file to force a lookup. */ + ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno); + + reclaim_vnode("mountpoint"); + nap(); + + /* Access it again, to make sure it's still possible. */ + ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno); +} diff --git a/tests/sys/fs/fusefs/lookup.cc b/tests/sys/fs/fusefs/lookup.cc index 2dfa10730ec8..32e2a08eb949 100644 --- a/tests/sys/fs/fusefs/lookup.cc +++ b/tests/sys/fs/fusefs/lookup.cc @@ -263,7 +263,6 @@ TEST_F(Lookup, dotdot_no_parent_nid) ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { SET_OUT_HEADER_LEN(out, open); }))); - expect_forget(FUSE_ROOT_ID, 1, NULL); expect_forget(foo_ino, 1, NULL); fd = open("mountpoint/foo/bar", O_EXEC| O_DIRECTORY); @@ -574,7 +573,6 @@ TEST_F(LookupExportable, dotdot_no_parent_nid) ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { SET_OUT_HEADER_LEN(out, open); }))); - expect_forget(FUSE_ROOT_ID, 1, NULL); expect_forget(foo_ino, 1, NULL); EXPECT_LOOKUP(bar_ino, "..") .WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) {