Merge PR #69324 into main

* refs/pull/69324/head:
	libcephfs: increment extra version to indicate new flock functions
	libcephfs: add public api for ceph_ll_flock

Reviewed-by: Venky Shankar <vshankar@redhat.com>
Reviewed-by: Greg Farnum <gfarnum@redhat.com>
This commit is contained in:
Venky Shankar 2026-06-30 19:09:27 +05:30
commit 084d84f3f9
3 changed files with 65 additions and 1 deletions

View File

@ -42,7 +42,7 @@ extern "C" {
#define LIBCEPHFS_VER_MAJOR 11
#define LIBCEPHFS_VER_MINOR 0
#define LIBCEPHFS_VER_EXTRA 0
#define LIBCEPHFS_VER_EXTRA 1
#define LIBCEPHFS_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
#define LIBCEPHFS_VERSION_CODE LIBCEPHFS_VERSION(LIBCEPHFS_VER_MAJOR, LIBCEPHFS_VER_MINOR, LIBCEPHFS_VER_EXTRA)
@ -2237,6 +2237,8 @@ int ceph_ll_getlk(struct ceph_mount_info *cmount,
Fh *fh, struct flock *fl, uint64_t owner);
int ceph_ll_setlk(struct ceph_mount_info *cmount,
Fh *fh, struct flock *fl, uint64_t owner, int sleep);
int ceph_ll_flock(struct ceph_mount_info *cmount,
Fh *fh, int operation, uint64_t owner);
int ceph_ll_lazyio(struct ceph_mount_info *cmount, Fh *fh, int enable);

View File

@ -2407,6 +2407,12 @@ extern "C" int ceph_ll_setlk(struct ceph_mount_info *cmount,
return (cmount->get_client()->ll_setlk(fh, fl, owner, sleep));
}
extern "C" int ceph_ll_flock(struct ceph_mount_info *cmount,
Fh *fh, int operation, uint64_t owner)
{
return (cmount->get_client()->ll_flock(fh, operation, owner));
}
extern "C" int ceph_ll_lazyio(class ceph_mount_info *cmount,
Fh *fh, int enable)
{

View File

@ -130,6 +130,62 @@ TEST(LibCephFS, BasicLocking) {
CLEANUP_CEPH();
}
TEST(LibCephFS, BasicLLLocking) {
struct ceph_mount_info *cmount = NULL;
STARTUP_CEPH();
char c_file[1024];
sprintf(c_file, "ll_flock_test_%d", getpid());
Fh *fh = NULL;
Inode *root = NULL, *inode = NULL;
struct ceph_statx stx;
UserPerm *perms = ceph_mount_perms(cmount);
ASSERT_EQ(0, ceph_ll_lookup_root(cmount, &root));
ASSERT_EQ(0, ceph_ll_create(cmount, root, c_file, fileMode,
O_RDWR | O_CREAT, &inode, &fh, &stx,
0, 0, perms));
// Lock exclusively twice
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_EX, 42));
ASSERT_EQ(-EAGAIN, ceph_ll_flock(cmount, fh, LOCK_EX | LOCK_NB, 43));
ASSERT_EQ(-EAGAIN, ceph_ll_flock(cmount, fh, LOCK_EX | LOCK_NB, 44));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_UN, 42));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_EX | LOCK_NB, 43));
ASSERT_EQ(-EAGAIN, ceph_ll_flock(cmount, fh, LOCK_EX | LOCK_NB, 44));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_UN, 43));
// Lock shared three times
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_SH, 42));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_SH, 43));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_SH, 44));
// And then attempt to lock exclusively
ASSERT_EQ(-EAGAIN, ceph_ll_flock(cmount, fh, LOCK_EX | LOCK_NB, 45));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_UN, 42));
ASSERT_EQ(-EAGAIN, ceph_ll_flock(cmount, fh, LOCK_EX | LOCK_NB, 45));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_UN, 44));
ASSERT_EQ(-EAGAIN, ceph_ll_flock(cmount, fh, LOCK_EX | LOCK_NB, 45));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_UN, 43));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_EX | LOCK_NB, 45));
ASSERT_EQ(-EAGAIN, ceph_ll_flock(cmount, fh, LOCK_SH | LOCK_NB, 42));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_UN, 45));
// Lock shared with upgrade to exclusive (POSIX)
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_SH, 42));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_EX, 42));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_UN, 42));
// Lock exclusive with downgrade to shared (POSIX)
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_EX, 42));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_SH, 42));
ASSERT_EQ(0, ceph_ll_flock(cmount, fh, LOCK_UN, 42));
ASSERT_EQ(0, ceph_ll_close(cmount, fh));
ASSERT_EQ(0, ceph_ll_unlink(cmount, root, c_file, perms));
CLEANUP_CEPH();
}
/* Locking in different threads */
// Used by ConcurrentLocking test