From: Giorgos Kappes Date: Tue, 22 Jul 2025 14:12:58 +0000 (+0300) Subject: libcephfs: Add ceph_setlk and ceph_getlk wrapper functions X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6b443ee5a4e5542def2e4fb3a3afa7d6862dd8eb;p=ceph.git libcephfs: Add ceph_setlk and ceph_getlk wrapper functions Signed-off-by: Giorgos Kappes --- diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 18e44b656eef..485b51a2ac15 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -1276,6 +1276,32 @@ int ceph_utimensat(struct ceph_mount_info *cmount, int dirfd, const char *relpat int ceph_flock(struct ceph_mount_info *cmount, int fd, int operation, uint64_t owner); +/** + * Test the existence of a record lock. + * + * @param cmount the ceph mount handle to use for performing the lock. + * @param fd the open file descriptor to test the existence of a record lock. + * @param pointer to an flock structure. + * @param owner the user-supplied owner identifier (an arbitrary integer) + * @returns 0 on success or negative error code on failure. + */ + int ceph_getlk(struct ceph_mount_info *cmount, int fd, struct flock *flock, + uint64_t owner); + +/** + * Set a record lock. + * + * @param cmount the ceph mount handle to use for performing the lock. + * @param fd the open file descriptor to set a record lock + * @param pointer to an flock structure. + * @param owner the user-supplied owner identifier (an arbitrary integer) + * @param sleep the user-supplied sleep flag + * @returns 0 on success or negative error code on failure. + */ + + int ceph_setlk(struct ceph_mount_info *cmount, int fd, struct flock *flock, + uint64_t owner, int sleep); + /** * Truncate the file to the given size. If this operation causes the * file to expand, the empty bytes will be filled in with zeros. diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 5102be67e769..049a47c4f53b 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -1405,6 +1405,22 @@ extern "C" int ceph_flock(struct ceph_mount_info *cmount, int fd, int operation, return cmount->get_client()->flock(fd, operation, owner); } +extern "C" int ceph_getlk(struct ceph_mount_info *cmount, int fd, struct flock *fl, + uint64_t owner) +{ + if (!cmount->is_mounted()) + return -ENOTCONN; + return cmount->get_client()->getlk(fd, fl, owner); +} + +extern "C" int ceph_setlk(struct ceph_mount_info *cmount, int fd, struct flock *fl, + uint64_t owner, int sleep) +{ + if (!cmount->is_mounted()) + return -ENOTCONN; + return cmount->get_client()->setlk(fd, fl, owner, sleep); +} + extern "C" int ceph_truncate(struct ceph_mount_info *cmount, const char *path, int64_t size) {