Skip to content

Commit 5da9c56

Browse files
committed
Merge PR ceph#62549 into main
* refs/pull/62549/head: test/libcephfs: Add a new test with ceph_ll_get() API libcephfs: Implement ceph_ll_get() API Reviewed-by: Dhairya Parmar <[email protected]> Reviewed-by: Venky Shankar <[email protected]>
2 parents 911b02d + 70ac8a8 commit 5da9c56

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

src/client/Client.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13564,6 +13564,12 @@ bool Client::_ll_forget(Inode *in, uint64_t count)
1356413564
return last;
1356513565
}
1356613566

13567+
void Client::ll_get(Inode *in)
13568+
{
13569+
std::scoped_lock lock(client_lock);
13570+
_ll_get(in);
13571+
}
13572+
1356713573
bool Client::ll_forget(Inode *in, uint64_t count)
1356813574
{
1356913575
std::scoped_lock lock(client_lock);

src/client/Client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ class Client : public Dispatcher, public md_config_obs_t {
601601
int ll_lookupx(Inode *parent, const char *name, Inode **out,
602602
struct ceph_statx *stx, unsigned want, unsigned flags,
603603
const UserPerm& perms);
604+
void ll_get(Inode *in);
604605
bool ll_forget(Inode *in, uint64_t count);
605606
bool ll_put(Inode *in);
606607
int ll_get_snap_ref(snapid_t snap);

src/include/cephfs/libcephfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,7 @@ int ceph_ll_lookup_root(struct ceph_mount_info *cmount,
19941994
int ceph_ll_lookup(struct ceph_mount_info *cmount, Inode *parent,
19951995
const char *name, Inode **out, struct ceph_statx *stx,
19961996
unsigned want, unsigned flags, const UserPerm *perms);
1997+
void ceph_ll_get(struct ceph_mount_info *cmount, struct Inode *in);
19971998
int ceph_ll_put(struct ceph_mount_info *cmount, struct Inode *in);
19981999
int ceph_ll_forget(struct ceph_mount_info *cmount, struct Inode *in,
19992000
int count);

src/libcephfs.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,11 @@ extern "C" int ceph_ll_lookup(struct ceph_mount_info *cmount,
20422042
flags, *perms);
20432043
}
20442044

2045+
extern "C" void ceph_ll_get(class ceph_mount_info *cmount, Inode *in)
2046+
{
2047+
cmount->get_client()->ll_get(in);
2048+
}
2049+
20452050
extern "C" int ceph_ll_put(class ceph_mount_info *cmount, Inode *in)
20462051
{
20472052
return (cmount->get_client()->ll_put(in));

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)