*/
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.
*
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);
+}
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);
+}