Return the network address for an OSD by ID.
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
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)
{
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();
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.
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)
{
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);
+}