From 22e5db4dc71409d0b1befe676d345a490a77d346 Mon Sep 17 00:00:00 2001 From: Giorgos Kappes Date: Tue, 17 Dec 2024 16:01:07 +0200 Subject: [PATCH] Client: Add Client::setlk and Client::getlk functions Also, removed CEPHFS_* errno's from setlk() and getlk() as Ceph has moved away from them. Signed-off-by: Giorgos Kappes --- src/client/Client.cc | 37 +++++++++++++++++++++++++++++++++++++ src/client/Client.h | 4 +++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 35baf658cf3a1..766e957249ff9 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -9158,6 +9158,43 @@ int Client::flock(int fd, int operation, uint64_t owner) return _flock(f, operation, owner); } +int Client::getlk(int fd, struct flock *fl, uint64_t owner) +{ + RWRef_t mref_reader(mount_state, CLIENT_MOUNTING); + if (!mref_reader.is_state_satisfied()) + return -ENOTCONN; + + tout(cct) << __func__ << std::endl; + tout(cct) << fd << std::endl; + tout(cct) << owner << std::endl; + + std::scoped_lock lock(client_lock); + Fh *fh = get_filehandle(fd); + if (!fh) + return -EBADF; + + return _getlk(fh, fl, owner); +} + +int Client::setlk(int fd, struct flock *fl, uint64_t owner, int sleep) +{ + RWRef_t mref_reader(mount_state, CLIENT_MOUNTING); + if (!mref_reader.is_state_satisfied()) + return -ENOTCONN; + + tout(cct) << __func__ << std::endl; + tout(cct) << fd << std::endl; + tout(cct) << owner << std::endl; + tout(cct) << sleep << std::endl; + + std::scoped_lock lock(client_lock); + Fh *fh = get_filehandle(fd); + if (!fh) + return -EBADF; + + return _setlk(fh, fl, owner, sleep); +} + int Client::opendir(const char *relpath, dir_result_t **dirpp, const UserPerm& perms) { RWRef_t mref_reader(mount_state, CLIENT_MOUNTING); diff --git a/src/client/Client.h b/src/client/Client.h index 52b23288ea8f9..fd406dd6ebccd 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -478,7 +478,9 @@ public: const UserPerm& perms); int flock(int fd, int operation, uint64_t owner); int truncate(const char *path, loff_t size, const UserPerm& perms); - + int getlk(int fd, struct flock *fl, uint64_t owner); + int setlk(int fd, struct flock *fl, uint64_t owner, int sleep); + // file ops int mknod(const char *path, mode_t mode, const UserPerm& perms, dev_t rdev=0); -- 2.39.5