Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Mar 2019 19:10:23 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r344775 - projects/fuse2/tests/sys/fs/fuse
Message-ID:  <201903041910.x24JANP2003177@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Mon Mar  4 19:10:22 2019
New Revision: 344775
URL: https://svnweb.freebsd.org/changeset/base/344775

Log:
  fuse(4): add tests for negative lookups
  
  PR:		236226
  Sponsored by:	The FreeBSD Foundation

Modified:
  projects/fuse2/tests/sys/fs/fuse/lookup.cc

Modified: projects/fuse2/tests/sys/fs/fuse/lookup.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/lookup.cc	Mon Mar  4 19:06:51 2019	(r344774)
+++ projects/fuse2/tests/sys/fs/fuse/lookup.cc	Mon Mar  4 19:10:22 2019	(r344775)
@@ -198,6 +198,65 @@ TEST_F(Lookup, entry_cache)
 	ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno);
 }
 
+/* 
+ * If the daemon returns an error of 0 and an inode of 0, that's a flag for
+ * "ENOENT and cache it" with the given entry_timeout
+ */
+/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236226 */
+TEST_F(Lookup, DISABLED_entry_cache_negative)
+{
+	EXPECT_CALL(*m_mock, process(
+		ResultOf([](auto in) {
+			return (in->header.opcode == FUSE_LOOKUP);
+		}, Eq(true)),
+		_)
+	).Times(1)
+	.WillOnce(Invoke([](auto in, auto out) {
+		out->header.unique = in->header.unique;
+		out->header.error = 0;
+		out->body.entry.nodeid = 0;
+		out->body.entry.entry_valid = UINT64_MAX;
+		SET_OUT_HEADER_LEN(out, entry);
+	}));
+	EXPECT_NE(0, access("mountpoint/does_not_exist", F_OK));
+	EXPECT_EQ(ENOENT, errno);
+	EXPECT_NE(0, access("mountpoint/does_not_exist", F_OK));
+	EXPECT_EQ(ENOENT, errno);
+}
+
+/* Negative entry caches should timeout, too */
+/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236226 */
+TEST_F(Lookup, DISABLED_entry_cache_negative_timeout)
+{
+	/* 
+	 * The timeout should be longer than the longest plausible time the
+	 * daemon would take to complete a write(2) to /dev/fuse, but no longer.
+	 */
+	long timeout_ns = 250'000'000;
+
+	EXPECT_CALL(*m_mock, process(
+		ResultOf([](auto in) {
+			return (in->header.opcode == FUSE_LOOKUP);
+		}, Eq(true)),
+		_)
+	).Times(1)
+	.WillOnce(Invoke([=](auto in, auto out) {
+		out->header.unique = in->header.unique;
+		out->header.error = 0;
+		out->body.entry.nodeid = 0;
+		out->body.entry.entry_valid_nsec = timeout_ns;
+		SET_OUT_HEADER_LEN(out, entry);
+	}));
+	EXPECT_NE(0, access("mountpoint/does_not_exist", F_OK));
+	EXPECT_EQ(ENOENT, errno);
+
+	usleep(2 * timeout_ns / 1000);
+
+	/* The cache has timed out; VOP_LOOKUP should requery the daemon*/
+	EXPECT_NE(0, access("mountpoint/does_not_exist", F_OK));
+	EXPECT_EQ(ENOENT, errno);
+}
+
 /*
  * If lookup returns a finite but non-zero entry cache timeout, then we should
  * discard the cached inode and requery the daemon



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201903041910.x24JANP2003177>