]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs: add pool id/size lookup interface
authorNoah Watkins <noahwatkins@gmail.com>
Wed, 16 Jan 2013 19:21:39 +0000 (11:21 -0800)
committerNoah Watkins <noahwatkins@gmail.com>
Fri, 18 Jan 2013 18:33:50 +0000 (10:33 -0800)
Adds new interfaces ceph_get_pool_id() and ceph_get_pool_replication()
to libcephfs.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
src/client/Client.cc
src/client/Client.h
src/include/cephfs/libcephfs.h
src/libcephfs.cc
src/test/libcephfs/test.cc

index b76ed8776614cdf49e7d3b417631afc64c855d91..ed068bf92a35c459d52ef4d4c3461dcef45f2b49 100644 (file)
@@ -7302,6 +7302,12 @@ int Client::describe_layout(int fd, ceph_file_layout *lp)
 
 // expose osdmap
 
+int64_t Client::get_pool_id(const char *pool_name)
+{
+  Mutex::Locker lock(client_lock);
+  return osdmap->lookup_pg_pool_name(pool_name);
+}
+
 string Client::get_pool_name(int64_t pool)
 {
   Mutex::Locker lock(client_lock);
index 4f33d3c342ace991b3a97fa9f5dbf86a1b33756c..266c00b7e668ba3a5a4091c88ee0b82537883cc3 100644 (file)
@@ -654,6 +654,7 @@ public:
   // expose osdmap 
   int get_local_osd();
   int get_pool_replication(int64_t pool);
+  int64_t get_pool_id(const char *pool_name);
   string get_pool_name(int64_t pool);
 
   int enumerate_layout(int fd, vector<ObjectExtent>& result,
index 21eee2b5aeaa6d76ac2310c742bc17fd76ed820b..63e9233d9da2293034ee0951136e1560f18c31c2 100644 (file)
@@ -863,6 +863,24 @@ int ceph_get_file_pool_name(struct ceph_mount_info *cmount, int fh, char *buf, s
  */
 int ceph_get_file_replication(struct ceph_mount_info *cmount, int fh);
 
+/**
+ * Get the id of the named pool.
+ *
+ * @param cmount the ceph mount handle to use.
+ * @param pool_name the name of the pool.
+ * @returns the pool id, or a negative error code on failure.
+ */
+int ceph_get_pool_id(struct ceph_mount_info *cmount, const char *pool_name);
+
+/**
+ * Get the pool replication factor.
+ *
+ * @param cmount the ceph mount handle to use.
+ * @param pool_id the pool id to look up
+ * @returns the replication factor, or a negative error code on failure.
+ */
+int ceph_get_pool_replication(struct ceph_mount_info *cmount, int pool_id);
+
 /**
  * Get the OSD address where the primary copy of a file stripe is located.
  *
index 8b51ab93fcc43bc90febe2d65d8f5d4645313c75..6f3c04a6d0aa274fadfe951a5d8e2a371173fc4f 100644 (file)
@@ -848,3 +848,27 @@ extern "C" int ceph_get_stripe_unit_granularity(struct ceph_mount_info *cmount)
     return -ENOTCONN;
   return CEPH_MIN_STRIPE_UNIT;
 }
+
+extern "C" int ceph_get_pool_id(struct ceph_mount_info *cmount, const char *pool_name)
+{
+  if (!cmount->is_mounted())
+    return -ENOTCONN;
+
+  if (!pool_name || !pool_name[0])
+    return -EINVAL;
+
+  /* negative range reserved for errors */
+  int64_t pool_id = cmount->get_client()->get_pool_id(pool_name);
+  if (pool_id > 0x7fffffff)
+    return -ERANGE;
+
+  /* get_pool_id error codes fit in int */
+  return (int)pool_id;
+}
+
+extern "C" int ceph_get_pool_replication(struct ceph_mount_info *cmount, int pool_id)
+{
+  if (!cmount->is_mounted())
+    return -ENOTCONN;
+  return cmount->get_client()->get_pool_replication(pool_id);
+}
index 04199b4fbbb2ead51d5a6602a7705f83a0978d70..62482a08d786c5572da2249768bd7b428a86453a 100644 (file)
@@ -887,6 +887,38 @@ TEST(LibCephFS, UseUnmounted) {
   EXPECT_EQ(-ENOTCONN, ceph_debug_get_fd_caps(cmount, 0));
   EXPECT_EQ(-ENOTCONN, ceph_debug_get_file_caps(cmount, "/path"));
   EXPECT_EQ(-ENOTCONN, ceph_get_stripe_unit_granularity(cmount));
+  EXPECT_EQ(-ENOTCONN, ceph_get_pool_id(cmount, "data"));
+  EXPECT_EQ(-ENOTCONN, ceph_get_pool_replication(cmount, 1));
 
   ceph_release(cmount);
 }
+
+TEST(LibCephFS, GetPoolId) {
+  struct ceph_mount_info *cmount;
+  ASSERT_EQ(ceph_create(&cmount, NULL), 0);
+  ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0);
+  ASSERT_EQ(ceph_mount(cmount, NULL), 0);
+
+  ASSERT_GE(ceph_get_pool_id(cmount, "data"), 0);
+  ASSERT_GE(ceph_get_pool_id(cmount, "metadata"), 0);
+  ASSERT_EQ(ceph_get_pool_id(cmount, "weflkjwelfjwlkejf"), -ENOENT);
+
+  ceph_shutdown(cmount);
+}
+
+TEST(LibCephFS, GetPoolReplication) {
+  struct ceph_mount_info *cmount;
+  ASSERT_EQ(ceph_create(&cmount, NULL), 0);
+  ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0);
+  ASSERT_EQ(ceph_mount(cmount, NULL), 0);
+
+  /* negative pools */
+  ASSERT_EQ(ceph_get_pool_replication(cmount, -10), -ENOENT);
+
+  /* valid pool */
+  int pool_id = ceph_get_pool_id(cmount, "data");
+  ASSERT_GE(pool_id, 0);
+  ASSERT_GT(ceph_get_pool_replication(cmount, pool_id), 0);
+
+  ceph_shutdown(cmount);
+}