From 3562c8c5b26305f8fca064b52a88cc708371f989 Mon Sep 17 00:00:00 2001 From: Andras Elso Date: Tue, 7 May 2013 01:28:12 +0200 Subject: [PATCH] libcephfs: get replication factor of a file handle/path Signed-off-by: Andras Elso --- src/include/cephfs/libcephfs.h | 12 +++++++++++- src/libcephfs.cc | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 5ceaced2222a1..bd4f9fca816df 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -953,13 +953,23 @@ int ceph_get_file_layout(struct ceph_mount_info *cmount, int fh, int *stripe_uni int ceph_get_path_layout(struct ceph_mount_info *cmount, const char *path, int *stripe_unit, int *stripe_count, int *object_size, int *pg_pool); /** - * Get the file replication information. + * Get the file replication information from an open file descriptor. + * * @param cmount the ceph mount handle to use. * @param fh the open file descriptor referring to the file to get the replication information of. * @returns the replication factor of the file. */ int ceph_get_file_replication(struct ceph_mount_info *cmount, int fh); +/** + * Get the file replication information. + * + * @param cmount the ceph mount handle to use. + * @param path the path of the file/directory get the replication information of. + * @returns the replication factor of the file. + */ +int ceph_get_path_replication(struct ceph_mount_info *cmount, const char *path); + /** * Get the id of the named pool. * diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 9487b6c227fd2..e1b4c287a3739 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -894,6 +894,20 @@ extern "C" int ceph_get_file_replication(struct ceph_mount_info *cmount, int fh) return rep; } +extern "C" int ceph_get_path_replication(struct ceph_mount_info *cmount, const char *path) +{ + struct ceph_file_layout l; + int r; + + if (!cmount->is_mounted()) + return -ENOTCONN; + r = cmount->get_client()->describe_layout(path, &l); + if (r < 0) + return r; + int rep = cmount->get_client()->get_pool_replication(l.fl_pg_pool); + return rep; +} + extern "C" int ceph_set_default_file_stripe_unit(struct ceph_mount_info *cmount, int stripe) { -- 2.39.5