git: 8d99a6b91b78 - main - fusefs: move common code from forget.cc to utils.cc

From: Alan Somers <asomers_at_FreeBSD.org>
Date: Sat, 01 Jan 2022 03:39:04 UTC
The branch main has been updated by asomers:

URL: https://cgit.FreeBSD.org/src/commit/?id=8d99a6b91b788b7ddf88f975f288f7c6479f4be3

commit 8d99a6b91b788b7ddf88f975f288f7c6479f4be3
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2021-12-02 02:50:26 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2022-01-01 03:38:20 +0000

    fusefs: move common code from forget.cc to utils.cc
    
    MFC after:      2 weeks
---
 tests/sys/fs/fusefs/forget.cc | 10 ++--------
 tests/sys/fs/fusefs/utils.cc  |  9 +++++++++
 tests/sys/fs/fusefs/utils.hh  |  4 ++++
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/tests/sys/fs/fusefs/forget.cc b/tests/sys/fs/fusefs/forget.cc
index 2041d20efae4..84fc271df57c 100644
--- a/tests/sys/fs/fusefs/forget.cc
+++ b/tests/sys/fs/fusefs/forget.cc
@@ -44,8 +44,6 @@ extern "C" {
 
 using namespace testing;
 
-const char reclaim_mib[] = "debug.try_reclaim_vnode";
-
 class Forget: public FuseTest {
 public:
 void SetUp() {
@@ -67,7 +65,6 @@ TEST_F(Forget, ok)
 	uint64_t ino = 42;
 	mode_t mode = S_IFREG | 0755;
 	sem_t sem;
-	int err;
 
 	ASSERT_EQ(0, sem_init(&sem, 0, 0)) << strerror(errno);
 
@@ -90,8 +87,7 @@ TEST_F(Forget, ok)
 	ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno);
 	ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno);
 
-	err = sysctlbyname(reclaim_mib, NULL, 0, FULLPATH, sizeof(FULLPATH));
-	ASSERT_EQ(0, err) << strerror(errno);
+	reclaim_vnode(FULLPATH);
 
 	sem_wait(&sem);
 	sem_destroy(&sem);
@@ -109,7 +105,6 @@ TEST_F(Forget, invalidate_names)
 	const char FNAME[] = "some_file.txt";
 	uint64_t dir_ino = 42;
 	uint64_t file_ino = 43;
-	int err;
 
 	EXPECT_LOOKUP(FUSE_ROOT_ID, DNAME)
 	.Times(2)
@@ -145,8 +140,7 @@ TEST_F(Forget, invalidate_names)
 	ASSERT_EQ(0, access(FULLFPATH, F_OK)) << strerror(errno);
 	
 	/* Reclaim the directory, invalidating its children from namecache */
-	err = sysctlbyname(reclaim_mib, NULL, 0, FULLDPATH, sizeof(FULLDPATH));
-	ASSERT_EQ(0, err) << strerror(errno);
+	reclaim_vnode(FULLDPATH);
 
 	/* Access the file again, causing another lookup */
 	ASSERT_EQ(0, access(FULLFPATH, F_OK)) << strerror(errno);
diff --git a/tests/sys/fs/fusefs/utils.cc b/tests/sys/fs/fusefs/utils.cc
index f733fef7ebe0..fb2109e1e9c4 100644
--- a/tests/sys/fs/fusefs/utils.cc
+++ b/tests/sys/fs/fusefs/utils.cc
@@ -623,6 +623,15 @@ out:
 	return;
 }
 
+void
+FuseTest::reclaim_vnode(const char *path)
+{
+	int err;
+
+	err = sysctlbyname(reclaim_mib, NULL, 0, path, strlen(path) + 1);
+	ASSERT_EQ(0, err) << strerror(errno);
+}
+
 static void usage(char* progname) {
 	fprintf(stderr, "Usage: %s [-v]\n\t-v increase verbosity\n", progname);
 	exit(2);
diff --git a/tests/sys/fs/fusefs/utils.hh b/tests/sys/fs/fusefs/utils.hh
index 6f1f91b02c97..610d2126fa52 100644
--- a/tests/sys/fs/fusefs/utils.hh
+++ b/tests/sys/fs/fusefs/utils.hh
@@ -73,6 +73,7 @@ class FuseTest : public ::testing::Test {
 	unsigned m_time_gran;
 	MockFS *m_mock = NULL;
 	const static uint64_t FH = 0xdeadbeef1a7ebabe;
+	const char *reclaim_mib = "debug.try_reclaim_vnode";
 
 	public:
 	int m_maxbcachebuf;
@@ -256,4 +257,7 @@ class FuseTest : public ::testing::Test {
 	 * See comments for FuseTest::leak
 	 */
 	static void leakdir(DIR* dirp __unused) {}
+
+	/* Manually reclaim a vnode.  Requires root privileges. */
+	void reclaim_vnode(const char *fullpath);
 };