From: Noah Watkins Date: Wed, 16 Jan 2013 19:21:39 +0000 (-0800) Subject: libcephfs: add pool id/size lookup interface X-Git-Tag: v0.57~161^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=40415d1c2fe7cb650ed91ff81d7d827a744527d5;p=ceph.git libcephfs: add pool id/size lookup interface Adds new interfaces ceph_get_pool_id() and ceph_get_pool_replication() to libcephfs. Signed-off-by: Noah Watkins --- diff --git a/src/client/Client.cc b/src/client/Client.cc index b76ed8776614..ed068bf92a35 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -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); diff --git a/src/client/Client.h b/src/client/Client.h index 4f33d3c342ac..266c00b7e668 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -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& result, diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 21eee2b5aeaa..63e9233d9da2 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -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. * diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 8b51ab93fcc4..6f3c04a6d0aa 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -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); +} diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index 04199b4fbbb2..62482a08d786 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -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); +}