]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs: add ceph_get_pool_name()
authorSage Weil <sage@inktank.com>
Sat, 18 May 2013 00:06:36 +0000 (17:06 -0700)
committerSage Weil <sage@inktank.com>
Sat, 18 May 2013 00:06:36 +0000 (17:06 -0700)
Convert an int pool id to a pool name.  Useful for making sense of the
output from ceph_get_*_layout()'s poolid output argument.

Signed-off-by: Sage Weil <sage@inktank.com>
src/include/cephfs/libcephfs.h
src/libcephfs.cc

index 12f62b34d5c0657fb311c94d89890763ab2934ba..93e86e7c031548ef09d9c14a6d73491deecda6ba 100644 (file)
@@ -926,6 +926,19 @@ int ceph_get_path_pool(struct ceph_mount_info *cmount, const char *path);
  */
 int ceph_get_file_pool_name(struct ceph_mount_info *cmount, int fh, char *buf, size_t buflen);
 
+/**
+ * get the name of a pool by id
+ *
+ * Given a pool's numeric identifier, get the pool's alphanumeric name.
+ *
+ * @param cmount the ceph mount handle to use
+ * @param pool the numeric pool id
+ * @param buf buffer to sore the name in
+ * @param buflen size of the buffer
+ * @returns length in bytes of the pool name, or -ERANGE if the buffer is not large enough
+ */
+int ceph_get_pool_name(struct ceph_mount_info *cmount, int pool, char *buf, size_t buflen);
+
 /**
  * Get the name of the pool a file is stored in
  *
index 6044f7689a943892ff892ff871ff8f0d669ea344..16b130a435a518f4dd4a6c108e66fd669fe33d6c 100644 (file)
@@ -838,6 +838,19 @@ extern "C" int ceph_get_file_pool_name(struct ceph_mount_info *cmount, int fh, c
   return name.length();
 }
 
+extern "C" int ceph_get_pool_name(struct ceph_mount_info *cmount, int pool, char *buf, size_t len)
+{
+  if (!cmount->is_mounted())
+    return -ENOTCONN;
+  string name = cmount->get_client()->get_pool_name(pool);
+  if (len == 0)
+    return name.length();
+  if (name.length() > len)
+    return -ERANGE;
+  strncpy(buf, name.c_str(), len);
+  return name.length();
+}
+
 extern "C" int ceph_get_path_pool_name(struct ceph_mount_info *cmount, const char *path, char *buf, size_t len)
 {
   struct ceph_file_layout l;