]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs: add ceph_get_osd_addr interface
authorNoah Watkins <noahwatkins@gmail.com>
Thu, 14 Mar 2013 19:15:41 +0000 (12:15 -0700)
committerNoah Watkins <noahwatkins@gmail.com>
Thu, 14 Mar 2013 19:25:17 +0000 (12:25 -0700)
Return the network address for an OSD by ID.

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 5d7fc5faa8bd7a7d83ea0928983ae08b4793c371..a716672a09438b162580e5fd4031175afd4b9476 100644 (file)
@@ -7706,6 +7706,18 @@ int Client::get_file_stripe_address(int fd, loff_t offset, vector<entity_addr_t>
   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<ObjectExtent>& result,
                             loff_t length, loff_t offset)
 {
index da66c486899d724d324b8f6af9803efad36145bb..03764aee240e4748c6e46c8a26260c0817d1f140 100644 (file)
@@ -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<entity_addr_t>& address);
   int get_file_extent_osds(int fd, loff_t off, loff_t *len, vector<int>& osds);
+  int get_osd_addr(int osd, entity_addr_t& addr);
 
   // expose osdmap 
   int get_local_osd();
index fc92b5d45b02cb7e4743b6d57787572a9d5470c0..df4ae9f8bbb6167319489ecf89e3f8cf66d6cb2a 100644 (file)
@@ -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.
index 35f1fd6ad363be7af26e9b4621e2f018395d8982..7a47bcb064a87f94e8d56154e49868b358806665 100644 (file)
@@ -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)
 {
index c23eedbe78cf06f73734b075d69cc73f75c11432..74d4db36275443b982d0255672a5afe9d78298ac 100644 (file)
@@ -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);
+}