diff --git a/src/client/Client.cc b/src/client/Client.cc index 6286996cc53..a718a0cad66 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -4188,6 +4188,19 @@ int Client::chmod(const char *relpath, mode_t mode) return _setattr(in, &attr, CEPH_SETATTR_MODE); } +int Client::fchmod(int fd, mode_t mode) +{ + Mutex::Locker lock(client_lock); + tout(cct) << "fchmod" << std::endl; + tout(cct) << fd << std::endl; + tout(cct) << mode << std::endl; + assert(fd_map.count(fd)); + Fh *f = fd_map[fd]; + struct stat attr; + attr.st_mode = mode; + return _setattr(f->inode, &attr, CEPH_SETATTR_MODE); +} + int Client::chown(const char *relpath, uid_t uid, gid_t gid) { Mutex::Locker lock(client_lock); diff --git a/src/client/Client.h b/src/client/Client.h index 404096bceed..d4f61d6ed0a 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -588,6 +588,7 @@ public: int setattr(const char *relpath, struct stat *attr, int mask); int chmod(const char *path, mode_t mode); + int fchmod(int fd, mode_t mode); int chown(const char *path, uid_t uid, gid_t gid); int utime(const char *path, struct utimbuf *buf); int truncate(const char *path, loff_t size); diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 937c192b22f..e0048b9e692 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -462,6 +462,7 @@ int ceph_lstat(struct ceph_mount_info *cmount, const char *path, struct stat *st * @returns 0 on success or negative error code on failure. */ int ceph_setattr(struct ceph_mount_info *cmount, const char *relpath, struct stat *attr, int mask); + /** * Change the mode bits (permissions) of a file/directory. * @@ -472,6 +473,16 @@ int ceph_setattr(struct ceph_mount_info *cmount, const char *relpath, struct sta */ int ceph_chmod(struct ceph_mount_info *cmount, const char *path, mode_t mode); +/** + * Change the mode bits (permissions) of an open file. + * + * @param cmount the ceph mount handle to use for performing the chmod. + * @param fd the open file descriptor to change the mode bits on. + * @param mode the new permissions to set. + * @returns 0 on success or a negative error code on failure. + */ +int ceph_fchmod(struct ceph_mount_info *cmount, int fd, mode_t mode); + /** * Change the ownership of a file/directory. * diff --git a/src/libcephfs.cc b/src/libcephfs.cc index f4e4ad0b03e..8e1020e85e0 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -450,6 +450,10 @@ extern "C" int ceph_chmod(struct ceph_mount_info *cmount, const char *path, mode { return cmount->get_client()->chmod(path, mode); } +extern "C" int ceph_fchmod(struct ceph_mount_info *cmount, int fd, mode_t mode) +{ + return cmount->get_client()->fchmod(fd, mode); +} extern "C" int ceph_chown(struct ceph_mount_info *cmount, const char *path, uid_t uid, gid_t gid) {