From: Noah Watkins Date: Thu, 14 Mar 2013 19:15:41 +0000 (-0700) Subject: libcephfs: add ceph_get_osd_addr interface X-Git-Tag: v0.60~70^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=47378d69ed475e720bab19176b893697178a6dcf;p=ceph.git libcephfs: add ceph_get_osd_addr interface Return the network address for an OSD by ID. Signed-off-by: Noah Watkins --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 5d7fc5faa8bd..a716672a0943 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -7706,6 +7706,18 @@ int Client::get_file_stripe_address(int fd, loff_t offset, vector return 0; } +int Client::get_osd_addr(int osd, entity_addr_t& addr) +{ + Mutex::Locker lock(client_lock); + + if (!osdmap->exists(osd)) + return -ENOENT; + + addr = osdmap->get_addr(osd); + + return 0; +} + int Client::enumerate_layout(int fd, vector& result, loff_t length, loff_t offset) { diff --git a/src/client/Client.h b/src/client/Client.h index da66c486899d..03764aee240e 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -672,6 +672,7 @@ public: int describe_layout(int fd, ceph_file_layout* layout); int get_file_stripe_address(int fd, loff_t offset, vector& address); int get_file_extent_osds(int fd, loff_t off, loff_t *len, vector& osds); + int get_osd_addr(int osd, entity_addr_t& addr); // expose osdmap int get_local_osd(); diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index fc92b5d45b02..df4ae9f8bbb6 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -929,6 +929,17 @@ int ceph_get_file_extent_osds(struct ceph_mount_info *cmount, int fh, int ceph_get_osd_crush_location(struct ceph_mount_info *cmount, int osd, char *path, size_t len); +/** + * Get the network address of an OSD. + * + * @param cmount the ceph mount handle. + * @param osd the OSD id. + * @param addr the OSD network address. + * @returns zero on success, other returns a negative error code. + */ +int ceph_get_osd_addr(struct ceph_mount_info *cmount, int osd, + struct sockaddr_storage *addr); + /** * Get the file layout stripe unit granularity. * @param cmount the ceph mount handle. diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 35f1fd6ad363..7a47bcb064a8 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -854,6 +854,25 @@ extern "C" int ceph_get_osd_crush_location(struct ceph_mount_info *cmount, return needed; } +extern "C" int ceph_get_osd_addr(struct ceph_mount_info *cmount, int osd, + struct sockaddr_storage *addr) +{ + if (!cmount->is_mounted()) + return -ENOTCONN; + + if (!addr) + return -EINVAL; + + entity_addr_t address; + int ret = cmount->get_client()->get_osd_addr(osd, address); + if (ret < 0) + return ret; + + memcpy(addr, &address.ss_addr(), sizeof(*addr)); + + return 0; +} + extern "C" int ceph_get_file_stripe_address(struct ceph_mount_info *cmount, int fh, loff_t offset, struct sockaddr_storage *addr, int naddr) { diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index c23eedbe78cf..74d4db362754 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -1029,3 +1029,23 @@ TEST(LibCephFS, GetOsdCrushLocation) { ceph_shutdown(cmount); } + +TEST(LibCephFS, GetOsdAddr) { + struct ceph_mount_info *cmount; + ASSERT_EQ(ceph_create(&cmount, NULL), 0); + + EXPECT_EQ(-ENOTCONN, ceph_get_osd_addr(cmount, 0, NULL)); + + ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0); + ASSERT_EQ(ceph_mount(cmount, NULL), 0); + + ASSERT_EQ(-EINVAL, ceph_get_osd_addr(cmount, 0, NULL)); + + struct sockaddr_storage addr; + ASSERT_EQ(-ENOENT, ceph_get_osd_addr(cmount, -1, &addr)); + ASSERT_EQ(-ENOENT, ceph_get_osd_addr(cmount, 9999999, &addr)); + + ASSERT_EQ(0, ceph_get_osd_addr(cmount, 0, &addr)); + + ceph_shutdown(cmount); +}