From: Sam Lang Date: Sat, 1 Dec 2012 22:54:44 +0000 (-0600) Subject: client: Add routine to get caps of file/fd X-Git-Tag: v0.56~86^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=10bf1509900eb91a4498b05d925c2226c9e39ea7;p=ceph.git client: Add routine to get caps of file/fd In order to properly validate the client capabilities, we need to be able to access them from libcephfs. Signed-off-by: Sam Lang --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 84438e79acc8..406723aa5f52 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -6084,7 +6084,27 @@ int Client::rmsnap(const char *relpath, const char *name) return _rmdir(snapdir, name); } +// ============================= +// expose caps + +int Client::get_caps_issued(int fd) { + + Mutex::Locker lock(client_lock); + Fh *f = get_filehandle(fd); + return f->inode->caps_issued(); +} + +int Client::get_caps_issued(const char *path) { + + Mutex::Locker lock(client_lock); + filepath p(path); + Inode *in; + int r = path_walk(p, &in, true); + if (r < 0) + return r; + return in->caps_issued(); +} // ========================================= // low level @@ -7395,3 +7415,4 @@ void Client::clear_filer_flags(int flags) assert(flags == CEPH_OSD_FLAG_LOCALIZE_READS); objecter->clear_global_op_flag(flags); } + diff --git a/src/client/Client.h b/src/client/Client.h index ae75d2df9fe1..9512a2d8861d 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -670,6 +670,10 @@ public: int mksnap(const char *path, const char *name); int rmsnap(const char *path, const char *name); + // expose caps + int get_caps_issued(int fd); + int get_caps_issued(const char *path); + // low-level interface int ll_lookup(vinodeno_t parent, const char *name, struct stat *attr, int uid = -1, int gid = -1); bool ll_forget(vinodeno_t vino, int count); diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 71bf25f6aed9..9cf66049d4d6 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -937,6 +937,26 @@ int ceph_get_local_osd(struct ceph_mount_info *cmount); /** @} default_filelayout */ +/** + * Get the capabilities currently issued to the client. + * + * @param cmount the ceph mount handle to use. + * @param fd the file descriptor to get issued + * @returns the current capabilities issued to this client + * for the open file + */ +int ceph_debug_get_fd_caps(struct ceph_mount_info *cmount, int fd); + +/** + * Get the capabilities currently issued to the client. + * + * @param cmount the ceph mount handle to use. + * @param the path to the file + * @returns the current capabilities issued to this client + * for the file + */ +int ceph_debug_get_file_caps(struct ceph_mount_info *cmount, const char *path); + #ifdef __cplusplus } #endif diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 02cf0864972c..c33f6284afcd 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -802,3 +802,17 @@ extern "C" CephContext *ceph_get_mount_context(struct ceph_mount_info *cmount) { return cmount->get_ceph_context(); } + +extern "C" int ceph_debug_get_fd_caps(struct ceph_mount_info *cmount, int fd) +{ + if (!cmount->is_mounted()) + return -ENOTCONN; + return cmount->get_client()->get_caps_issued(fd); +} + +extern "C" int ceph_debug_get_file_caps(struct ceph_mount_info *cmount, const char *path) +{ + if (!cmount->is_mounted()) + return -ENOTCONN; + return cmount->get_client()->get_caps_issued(path); +}