fusefs: move common code from forget.cc to utils.cc

MFC after:	2 weeks
This commit is contained in:
Alan Somers 2021-12-01 19:50:26 -07:00
parent 19ab361045
commit 8d99a6b91b
3 changed files with 15 additions and 8 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);
};