Skip to content

Commit 70ac8a8

Browse files
committed
test/libcephfs: Add a new test with ceph_ll_get() API
Signed-off-by: Anoop C S <[email protected]>
1 parent 04c81a4 commit 70ac8a8

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/test/libcephfs/test.cc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4100,3 +4100,51 @@ TEST(LibCephFS, SubdirLookupAfterReaddir_ll) {
41004100
ASSERT_EQ(0, ceph_unmount(cmount));
41014101
ceph_shutdown(cmount);
41024102
}
4103+
4104+
TEST(LibCephFS, InodeGetPut) {
4105+
struct ceph_mount_info *cmount;
4106+
ASSERT_EQ(ceph_create(&cmount, NULL), 0);
4107+
ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0);
4108+
ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
4109+
ASSERT_EQ(ceph_mount(cmount, NULL), 0);
4110+
4111+
Inode *root = NULL;
4112+
4113+
ASSERT_EQ(ceph_ll_lookup_root(cmount, &root), 0);
4114+
// Update reference on root
4115+
ceph_ll_get(cmount, root);
4116+
4117+
bool last_ref = ceph_ll_put(cmount, root);
4118+
// ceph_ll_put() always ignore forget on root
4119+
ASSERT_TRUE(last_ref);
4120+
4121+
char dir_name[128];
4122+
pid_t mypid = getpid();
4123+
sprintf(dir_name, "dir_%d", mypid);
4124+
4125+
ASSERT_EQ(ceph_mkdir(cmount, dir_name, 0777), 0);
4126+
4127+
Inode *dir_inode = NULL;
4128+
UserPerm *perms = ceph_mount_perms(cmount);
4129+
struct ceph_statx stx;
4130+
4131+
ASSERT_EQ(0, ceph_ll_lookup(cmount, root, dir_name, &dir_inode, &stx, 0, 0, perms));
4132+
// Update reference on directory
4133+
ceph_ll_get(cmount, dir_inode);
4134+
4135+
last_ref = ceph_ll_put(cmount, dir_inode);
4136+
ASSERT_FALSE(last_ref);
4137+
4138+
last_ref = ceph_ll_put(cmount, dir_inode);
4139+
ASSERT_TRUE(last_ref);
4140+
4141+
// Take another reference on directory
4142+
ceph_ll_get(cmount, dir_inode);
4143+
4144+
last_ref = ceph_ll_put(cmount, dir_inode);
4145+
ASSERT_TRUE(last_ref);
4146+
4147+
ASSERT_EQ(0, ceph_rmdir(cmount, dir_name));
4148+
ASSERT_EQ(0, ceph_unmount(cmount));
4149+
ceph_shutdown(cmount);
4150+
}

0 commit comments

Comments
 (0)