Compare commits
3 Commits
1e3f143892
...
4b48b60ce1
Author | SHA1 | Date |
---|---|---|
|
4b48b60ce1 | |
|
5075cb27c8 | |
|
7808d07d26 |
|
@ -28,6 +28,7 @@ target_link_libraries(vitastor_client
|
|||
vitastor_cli
|
||||
${LIBURING_LIBRARIES}
|
||||
${IBVERBS_LIBRARIES}
|
||||
${RDMACM_LIBRARIES}
|
||||
)
|
||||
set_target_properties(vitastor_client PROPERTIES VERSION ${VITASTOR_VERSION} SOVERSION 0)
|
||||
configure_file(vitastor.pc.in vitastor.pc @ONLY)
|
||||
|
|
|
@ -182,7 +182,7 @@ void etcd_state_client_t::add_etcd_url(std::string addr)
|
|||
exit(1);
|
||||
}
|
||||
if (!local_ips.size())
|
||||
local_ips = getifaddr_list(std::vector<std::string>(), true);
|
||||
local_ips = getifaddr_list(std::vector<addr_mask_t>(), true);
|
||||
std::string check_addr;
|
||||
int pos = addr.find('/');
|
||||
int pos2 = addr.find(':');
|
||||
|
|
|
@ -117,29 +117,56 @@ void msgr_iothread_t::run()
|
|||
|
||||
void osd_messenger_t::init()
|
||||
{
|
||||
#ifdef WITH_RDMACM
|
||||
if (use_rdmacm)
|
||||
{
|
||||
// RDMA-CM only requires the event channel. All the remaining work is done separately
|
||||
rdmacm_evch = rdma_create_event_channel();
|
||||
if (!rdmacm_evch)
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize RDMA-CM event channel: %s (code %d)\n", strerror(errno), errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
fcntl(rdmacm_evch->fd, F_SETFL, fcntl(rdmacm_evch->fd, F_GETFL, 0) | O_NONBLOCK);
|
||||
tfd->set_fd_handler(rdmacm_evch->fd, false, [this](int rdmacm_eventfd, int epoll_events)
|
||||
{
|
||||
handle_rdmacm_events();
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#ifdef WITH_RDMA
|
||||
if (use_rdma)
|
||||
{
|
||||
rdma_context = msgr_rdma_context_t::create(
|
||||
osd_networks, rdma_device != "" ? rdma_device.c_str() : NULL,
|
||||
rdma_contexts = msgr_rdma_context_t::create_all(
|
||||
osd_num && osd_cluster_network_masks.size() ? osd_cluster_network_masks : osd_network_masks,
|
||||
rdma_device != "" ? rdma_device.c_str() : NULL,
|
||||
rdma_port_num, rdma_gid_index, rdma_mtu, rdma_odp, log_level
|
||||
);
|
||||
if (!rdma_context)
|
||||
if (!rdma_contexts.size())
|
||||
{
|
||||
if (force_rdma)
|
||||
{
|
||||
fprintf(stderr, "[OSD %ju] Couldn't initialize RDMA, force_rdma is enabled, exiting\n", osd_num);
|
||||
exit(1);
|
||||
}
|
||||
if (log_level > 0)
|
||||
fprintf(stderr, "[OSD %ju] Couldn't initialize RDMA, proceeding with TCP only\n", osd_num);
|
||||
}
|
||||
else
|
||||
{
|
||||
rdma_max_sge = rdma_max_sge < rdma_context->attrx.orig_attr.max_sge
|
||||
? rdma_max_sge : rdma_context->attrx.orig_attr.max_sge;
|
||||
fprintf(stderr, "[OSD %ju] RDMA initialized successfully\n", osd_num);
|
||||
fcntl(rdma_context->channel->fd, F_SETFL, fcntl(rdma_context->channel->fd, F_GETFL, 0) | O_NONBLOCK);
|
||||
tfd->set_fd_handler(rdma_context->channel->fd, false, [this](int notify_fd, int epoll_events)
|
||||
for (msgr_rdma_context_t* rdma_context: rdma_contexts)
|
||||
{
|
||||
handle_rdma_events();
|
||||
});
|
||||
handle_rdma_events();
|
||||
fcntl(rdma_context->channel->fd, F_SETFL, fcntl(rdma_context->channel->fd, F_GETFL, 0) | O_NONBLOCK);
|
||||
tfd->set_fd_handler(rdma_context->channel->fd, false, [this, rdma_context](int notify_fd, int epoll_events)
|
||||
{
|
||||
handle_rdma_events(rdma_context);
|
||||
});
|
||||
handle_rdma_events(rdma_context);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -247,10 +274,19 @@ osd_messenger_t::~osd_messenger_t()
|
|||
iothreads.clear();
|
||||
}
|
||||
#ifdef WITH_RDMA
|
||||
if (rdma_context)
|
||||
for (auto rdma_context: rdma_contexts)
|
||||
{
|
||||
delete rdma_context;
|
||||
}
|
||||
rdma_contexts.clear();
|
||||
#endif
|
||||
#ifdef WITH_RDMACM
|
||||
if (rdmacm_evch)
|
||||
{
|
||||
tfd->set_fd_handler(rdmacm_evch->fd, false, NULL);
|
||||
rdma_destroy_event_channel(rdmacm_evch);
|
||||
rdmacm_evch = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -262,10 +298,18 @@ void osd_messenger_t::parse_config(const json11::Json & config)
|
|||
// RDMA is on by default in RDMA-enabled builds
|
||||
this->use_rdma = config["use_rdma"].bool_value() || config["use_rdma"].uint64_value() != 0;
|
||||
}
|
||||
#ifdef WITH_RDMACM
|
||||
// Use RDMA CM? (required for iWARP and may be useful for IB)
|
||||
// FIXME: Only parse during start
|
||||
this->use_rdmacm = config["use_rdmacm"].bool_value() || config["use_rdmacm"].uint64_value() != 0;
|
||||
this->disable_tcp = this->use_rdmacm && (config["disable_tcp"].bool_value() || config["disable_tcp"].uint64_value() != 0);
|
||||
#endif
|
||||
if (!config["force_rdma"].is_null())
|
||||
{
|
||||
this->force_rdma = config["force_rdma"].bool_value() || config["force_rdma"].uint64_value() != 0;
|
||||
}
|
||||
this->rdma_device = config["rdma_device"].string_value();
|
||||
this->rdma_port_num = (uint8_t)config["rdma_port_num"].uint64_value();
|
||||
if (!this->rdma_port_num)
|
||||
this->rdma_port_num = 1;
|
||||
if (!config["rdma_gid_index"].is_null())
|
||||
this->rdma_gid_index = (uint8_t)config["rdma_gid_index"].uint64_value();
|
||||
this->rdma_mtu = (uint32_t)config["rdma_mtu"].uint64_value();
|
||||
|
@ -282,15 +326,6 @@ void osd_messenger_t::parse_config(const json11::Json & config)
|
|||
if (!this->rdma_max_msg || this->rdma_max_msg > 128*1024*1024)
|
||||
this->rdma_max_msg = 129*1024;
|
||||
this->rdma_odp = config["rdma_odp"].bool_value();
|
||||
std::vector<std::string> mask;
|
||||
if (config["bind_address"].is_string())
|
||||
mask.push_back(config["bind_address"].string_value());
|
||||
else if (config["osd_network"].is_string())
|
||||
mask.push_back(config["osd_network"].string_value());
|
||||
else
|
||||
for (auto v: config["osd_network"].array_items())
|
||||
mask.push_back(v.string_value());
|
||||
this->osd_networks = mask;
|
||||
#endif
|
||||
if (!osd_num)
|
||||
this->iothread_count = (uint32_t)config["client_iothread_count"].uint64_value();
|
||||
|
@ -314,23 +349,88 @@ void osd_messenger_t::parse_config(const json11::Json & config)
|
|||
if (!this->osd_ping_timeout)
|
||||
this->osd_ping_timeout = 5;
|
||||
this->log_level = config["log_level"].uint64_value();
|
||||
// OSD public & cluster networks
|
||||
this->osd_networks.clear();
|
||||
if (config["bind_address"].is_string())
|
||||
this->osd_networks.push_back(config["bind_address"].string_value());
|
||||
else if (config["osd_network"].is_string())
|
||||
this->osd_networks.push_back(config["osd_network"].string_value());
|
||||
else
|
||||
for (auto v: config["osd_network"].array_items())
|
||||
this->osd_networks.push_back(v.string_value());
|
||||
this->osd_cluster_networks.clear();
|
||||
if (config["osd_cluster_network"].is_string())
|
||||
this->osd_cluster_networks.push_back(config["osd_cluster_network"].string_value());
|
||||
else
|
||||
for (auto v: config["osd_cluster_network"].array_items())
|
||||
this->osd_cluster_networks.push_back(v.string_value());
|
||||
if (this->osd_cluster_networks.size())
|
||||
for (auto & net: this->osd_cluster_networks)
|
||||
for (int i = this->osd_networks.size()-1; i >= 0; i--)
|
||||
if (this->osd_networks[i] == net)
|
||||
this->osd_networks.erase(this->osd_networks.begin()+i, this->osd_networks.begin()+i+1);
|
||||
this->osd_network_masks.clear();
|
||||
for (auto & netstr: this->osd_networks)
|
||||
this->osd_network_masks.push_back(cidr_parse(netstr));
|
||||
this->osd_cluster_network_masks.clear();
|
||||
for (auto & netstr: this->osd_cluster_networks)
|
||||
this->osd_cluster_network_masks.push_back(cidr_parse(netstr));
|
||||
this->all_osd_networks.clear();
|
||||
this->all_osd_networks.insert(this->all_osd_networks.end(), this->osd_networks.begin(), this->osd_networks.end());
|
||||
this->all_osd_networks.insert(this->all_osd_networks.end(), this->osd_cluster_networks.begin(), this->osd_cluster_networks.end());
|
||||
this->all_osd_network_masks.clear();
|
||||
this->all_osd_network_masks.insert(this->all_osd_network_masks.end(), this->osd_network_masks.begin(), this->osd_network_masks.end());
|
||||
this->all_osd_network_masks.insert(this->all_osd_network_masks.end(), this->osd_cluster_network_masks.begin(), this->osd_cluster_network_masks.end());
|
||||
if (!this->osd_networks.size())
|
||||
{
|
||||
this->osd_networks = this->osd_cluster_networks;
|
||||
this->osd_network_masks = this->osd_cluster_network_masks;
|
||||
}
|
||||
}
|
||||
|
||||
void osd_messenger_t::connect_peer(uint64_t peer_osd, json11::Json peer_state)
|
||||
{
|
||||
if (wanted_peers.find(peer_osd) == wanted_peers.end())
|
||||
if (wanted_peers[peer_osd].raw_address_list != peer_state["addresses"])
|
||||
{
|
||||
wanted_peers[peer_osd] = (osd_wanted_peer_t){
|
||||
.address_list = peer_state["addresses"],
|
||||
.port = (int)peer_state["port"].int64_value(),
|
||||
};
|
||||
wanted_peers[peer_osd].raw_address_list = peer_state["addresses"];
|
||||
if (osd_cluster_networks.size())
|
||||
{
|
||||
json11::Json::array address_list, cluster_address_list;
|
||||
for (auto json_addr: peer_state["addresses"].array_items())
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
auto ok = string_to_addr(json_addr.string_value(), false, 0, &addr);
|
||||
if (ok)
|
||||
{
|
||||
bool is_cluster = false;
|
||||
for (auto & mask: osd_cluster_network_masks)
|
||||
{
|
||||
if (cidr_sockaddr_match(addr, mask))
|
||||
{
|
||||
is_cluster = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_cluster)
|
||||
cluster_address_list.push_back(json_addr);
|
||||
else
|
||||
address_list.push_back(json_addr);
|
||||
}
|
||||
}
|
||||
auto n_cluster = this->osd_num ? cluster_address_list.size() : 0;
|
||||
if (this->osd_num)
|
||||
address_list.insert(address_list.begin(), cluster_address_list.begin(), cluster_address_list.end());
|
||||
wanted_peers[peer_osd].address_list = address_list;
|
||||
wanted_peers[peer_osd].n_cluster_addr = n_cluster;
|
||||
}
|
||||
else
|
||||
wanted_peers[peer_osd].address_list = peer_state["addresses"];
|
||||
wanted_peers[peer_osd].address_changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
wanted_peers[peer_osd].address_list = peer_state["addresses"];
|
||||
wanted_peers[peer_osd].port = (int)peer_state["port"].int64_value();
|
||||
}
|
||||
wanted_peers[peer_osd].address_changed = true;
|
||||
#ifdef WITH_RDMACM
|
||||
wanted_peers[peer_osd].peer_rdmacm = peer_state["rdmacm"].bool_value();
|
||||
#endif
|
||||
wanted_peers[peer_osd].port = (int)peer_state["port"].int64_value();
|
||||
try_connect_peer(peer_osd);
|
||||
}
|
||||
|
||||
|
@ -355,12 +455,24 @@ void osd_messenger_t::try_connect_peer(uint64_t peer_osd)
|
|||
wp.cur_addr = wp.address_list[wp.address_index].string_value();
|
||||
wp.cur_port = wp.port;
|
||||
wp.connecting = true;
|
||||
try_connect_peer_addr(peer_osd, wp.cur_addr.c_str(), wp.cur_port);
|
||||
#ifdef WITH_RDMACM
|
||||
if (use_rdmacm && wp.peer_rdmacm)
|
||||
rdmacm_try_connect_peer(peer_osd, wp.cur_addr.c_str(), wp.cur_port);
|
||||
else
|
||||
#endif
|
||||
try_connect_peer_tcp(peer_osd, wp.cur_addr.c_str(), wp.cur_port);
|
||||
}
|
||||
|
||||
void osd_messenger_t::try_connect_peer_addr(osd_num_t peer_osd, const char *peer_host, int peer_port)
|
||||
void osd_messenger_t::try_connect_peer_tcp(osd_num_t peer_osd, const char *peer_host, int peer_port)
|
||||
{
|
||||
assert(peer_osd != this->osd_num);
|
||||
#ifdef WITH_RDMACM
|
||||
if (disable_tcp)
|
||||
{
|
||||
on_connect_peer(peer_osd, -EINVAL);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
struct sockaddr_storage addr;
|
||||
if (!string_to_addr(peer_host, 0, peer_port, &addr))
|
||||
{
|
||||
|
@ -524,20 +636,30 @@ void osd_messenger_t::check_peer_config(osd_client_t *cl)
|
|||
},
|
||||
};
|
||||
#ifdef WITH_RDMA
|
||||
if (rdma_context)
|
||||
if (rdma_contexts.size())
|
||||
{
|
||||
cl->rdma_conn = msgr_rdma_connection_t::create(rdma_context, rdma_max_send, rdma_max_recv, rdma_max_sge, rdma_max_msg);
|
||||
if (cl->rdma_conn)
|
||||
// Choose the right context for the selected network
|
||||
msgr_rdma_context_t *selected_ctx = choose_rdma_context(cl);
|
||||
if (!selected_ctx)
|
||||
{
|
||||
json11::Json payload = json11::Json::object {
|
||||
{ "connect_rdma", cl->rdma_conn->addr.to_string() },
|
||||
{ "rdma_max_msg", cl->rdma_conn->max_msg },
|
||||
};
|
||||
std::string payload_str = payload.dump();
|
||||
op->req.show_conf.json_len = payload_str.size();
|
||||
op->buf = malloc_or_die(payload_str.size());
|
||||
op->iov.push_back(op->buf, payload_str.size());
|
||||
memcpy(op->buf, payload_str.c_str(), payload_str.size());
|
||||
if (log_level > 0)
|
||||
fprintf(stderr, "No RDMA context for OSD %ju connection (peer %d), using only TCP\n", cl->osd_num, cl->peer_fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
cl->rdma_conn = msgr_rdma_connection_t::create(selected_ctx, rdma_max_send, rdma_max_recv, rdma_max_sge, rdma_max_msg);
|
||||
if (cl->rdma_conn)
|
||||
{
|
||||
json11::Json payload = json11::Json::object {
|
||||
{ "connect_rdma", cl->rdma_conn->addr.to_string() },
|
||||
{ "rdma_max_msg", cl->rdma_conn->max_msg },
|
||||
};
|
||||
std::string payload_str = payload.dump();
|
||||
op->req.show_conf.json_len = payload_str.size();
|
||||
op->buf = malloc_or_die(payload_str.size());
|
||||
op->iov.push_back(op->buf, payload_str.size());
|
||||
memcpy(op->buf, payload_str.c_str(), payload_str.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -667,9 +789,29 @@ void osd_messenger_t::accept_connections(int listen_fd)
|
|||
}
|
||||
|
||||
#ifdef WITH_RDMA
|
||||
msgr_rdma_context_t* osd_messenger_t::choose_rdma_context(osd_client_t *cl)
|
||||
{
|
||||
// Choose the right context for the selected network
|
||||
msgr_rdma_context_t *selected_ctx = NULL;
|
||||
for (auto rdma_ctx: rdma_contexts)
|
||||
{
|
||||
if (!rdma_ctx->net_mask.family && !selected_ctx ||
|
||||
rdma_ctx->net_mask.family && cidr_sockaddr_match(cl->peer_addr, rdma_ctx->net_mask))
|
||||
{
|
||||
selected_ctx = rdma_ctx;
|
||||
}
|
||||
}
|
||||
return selected_ctx;
|
||||
}
|
||||
|
||||
bool osd_messenger_t::is_rdma_enabled()
|
||||
{
|
||||
return rdma_context != NULL;
|
||||
return rdma_contexts.size() > 0;
|
||||
}
|
||||
|
||||
bool osd_messenger_t::is_use_rdmacm()
|
||||
{
|
||||
return use_rdmacm;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "json11/json11.hpp"
|
||||
#include "msgr_op.h"
|
||||
#include "timerfd_manager.h"
|
||||
#include "addr_util.h"
|
||||
#include <ringloop.h>
|
||||
|
||||
#define CL_READ_HDR 1
|
||||
|
@ -49,10 +50,10 @@ struct osd_client_t
|
|||
{
|
||||
int refs = 0;
|
||||
|
||||
sockaddr_storage peer_addr;
|
||||
int peer_port;
|
||||
sockaddr_storage peer_addr = {};
|
||||
int peer_port = 0;
|
||||
int peer_fd = -1;
|
||||
int peer_state;
|
||||
int peer_state = 0;
|
||||
int connect_timeout_id = -1;
|
||||
int ping_time_remaining = 0;
|
||||
int idle_time_remaining = 0;
|
||||
|
@ -93,13 +94,16 @@ struct osd_client_t
|
|||
|
||||
struct osd_wanted_peer_t
|
||||
{
|
||||
json11::Json raw_address_list;
|
||||
json11::Json address_list;
|
||||
int port;
|
||||
time_t last_connect_attempt;
|
||||
bool connecting, address_changed;
|
||||
int address_index;
|
||||
bool peer_rdmacm = false;
|
||||
int n_cluster_addr = 0;
|
||||
int port = 0;
|
||||
time_t last_connect_attempt = 0;
|
||||
bool connecting = false, address_changed = false;
|
||||
int address_index = 0;
|
||||
std::string cur_addr;
|
||||
int cur_port;
|
||||
int cur_port = 0;
|
||||
};
|
||||
|
||||
struct osd_op_stats_t
|
||||
|
@ -149,6 +153,15 @@ public:
|
|||
};
|
||||
#endif
|
||||
|
||||
#ifdef WITH_RDMA
|
||||
struct rdma_event_channel;
|
||||
struct rdma_cm_id;
|
||||
struct rdma_cm_event;
|
||||
struct ibv_context;
|
||||
struct osd_messenger_t;
|
||||
struct rdmacm_connecting_t;
|
||||
#endif
|
||||
|
||||
struct osd_messenger_t
|
||||
{
|
||||
protected:
|
||||
|
@ -165,14 +178,20 @@ protected:
|
|||
|
||||
#ifdef WITH_RDMA
|
||||
bool use_rdma = true;
|
||||
std::vector<std::string> osd_networks;
|
||||
bool use_rdmacm = false;
|
||||
bool disable_tcp = false;
|
||||
bool force_rdma = false;
|
||||
std::string rdma_device;
|
||||
uint64_t rdma_port_num = 1, rdma_mtu = 0;
|
||||
uint64_t rdma_port_num = 1;
|
||||
int rdma_mtu = 0;
|
||||
int rdma_gid_index = -1;
|
||||
msgr_rdma_context_t *rdma_context = NULL;
|
||||
std::vector<msgr_rdma_context_t *> rdma_contexts;
|
||||
uint64_t rdma_max_sge = 0, rdma_max_send = 0, rdma_max_recv = 0;
|
||||
uint64_t rdma_max_msg = 0;
|
||||
bool rdma_odp = false;
|
||||
rdma_event_channel *rdmacm_evch = NULL;
|
||||
std::map<rdma_cm_id*, osd_client_t*> rdmacm_connections;
|
||||
std::map<rdma_cm_id*, rdmacm_connecting_t*> rdmacm_connecting;
|
||||
#endif
|
||||
|
||||
std::vector<msgr_iothread_t*> iothreads;
|
||||
|
@ -190,6 +209,12 @@ public:
|
|||
std::map<int, osd_client_t*> clients;
|
||||
std::map<osd_num_t, osd_wanted_peer_t> wanted_peers;
|
||||
std::map<uint64_t, int> osd_peer_fds;
|
||||
std::vector<std::string> osd_networks;
|
||||
std::vector<addr_mask_t> osd_network_masks;
|
||||
std::vector<std::string> osd_cluster_networks;
|
||||
std::vector<addr_mask_t> osd_cluster_network_masks;
|
||||
std::vector<std::string> all_osd_networks;
|
||||
std::vector<addr_mask_t> all_osd_network_masks;
|
||||
// op statistics
|
||||
osd_op_stats_t stats, recovery_stats;
|
||||
|
||||
|
@ -216,13 +241,18 @@ public:
|
|||
bool is_rdma_enabled();
|
||||
bool connect_rdma(int peer_fd, std::string rdma_address, uint64_t client_max_msg);
|
||||
#endif
|
||||
#ifdef WITH_RDMACM
|
||||
bool is_use_rdmacm();
|
||||
rdma_cm_id *rdmacm_listen(const std::string & bind_address, int rdmacm_port, int *bound_port, int log_level);
|
||||
void rdmacm_destroy_listener(rdma_cm_id *listener);
|
||||
#endif
|
||||
|
||||
void inc_op_stats(osd_op_stats_t & stats, uint64_t opcode, timespec & tv_begin, timespec & tv_end, uint64_t len);
|
||||
void measure_exec(osd_op_t *cur_op);
|
||||
|
||||
protected:
|
||||
void try_connect_peer(uint64_t osd_num);
|
||||
void try_connect_peer_addr(osd_num_t peer_osd, const char *peer_host, int peer_port);
|
||||
void try_connect_peer_tcp(osd_num_t peer_osd, const char *peer_host, int peer_port);
|
||||
void handle_peer_epoll(int peer_fd, int epoll_events);
|
||||
void handle_connect_epoll(int peer_fd);
|
||||
void on_connect_peer(osd_num_t peer_osd, int peer_fd);
|
||||
|
@ -247,6 +277,18 @@ protected:
|
|||
void try_send_rdma_odp(osd_client_t *cl);
|
||||
void try_send_rdma_nodp(osd_client_t *cl);
|
||||
bool try_recv_rdma(osd_client_t *cl);
|
||||
void handle_rdma_events();
|
||||
void handle_rdma_events(msgr_rdma_context_t *rdma_context);
|
||||
msgr_rdma_context_t* choose_rdma_context(osd_client_t *cl);
|
||||
#endif
|
||||
#ifdef WITH_RDMACM
|
||||
void handle_rdmacm_events();
|
||||
msgr_rdma_context_t* rdmacm_get_context(ibv_context *verbs);
|
||||
msgr_rdma_context_t* rdmacm_create_qp(rdma_cm_id *cmid);
|
||||
void rdmacm_accept(rdma_cm_event *ev);
|
||||
void rdmacm_try_connect_peer(uint64_t peer_osd, const std::string & addr, int peer_port);
|
||||
void rdmacm_on_connect_peer_error(rdma_cm_id *cmid, int res);
|
||||
void rdmacm_address_resolved(rdma_cm_event *ev);
|
||||
void rdmacm_route_resolved(rdma_cm_event *ev);
|
||||
void rdmacm_established(rdma_cm_event *ev);
|
||||
#endif
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,9 +2,13 @@
|
|||
// License: VNPL-1.1 or GNU GPL-2.0+ (see README.md for details)
|
||||
|
||||
#pragma once
|
||||
#ifdef WITH_RDMACM
|
||||
#include <rdma/rdma_cma.h>
|
||||
#endif
|
||||
#include <infiniband/verbs.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "addr_util.h"
|
||||
|
||||
struct msgr_rdma_address_t
|
||||
{
|
||||
|
@ -20,7 +24,6 @@ struct msgr_rdma_address_t
|
|||
struct msgr_rdma_context_t
|
||||
{
|
||||
ibv_context *context = NULL;
|
||||
ibv_device *dev = NULL;
|
||||
ibv_device_attr_ex attrx;
|
||||
ibv_pd *pd = NULL;
|
||||
bool odp = false;
|
||||
|
@ -35,8 +38,17 @@ struct msgr_rdma_context_t
|
|||
uint32_t mtu;
|
||||
int max_cqe = 0;
|
||||
int used_max_cqe = 0;
|
||||
addr_mask_t net_mask = {};
|
||||
bool is_cm = false;
|
||||
int cm_refs = 0;
|
||||
|
||||
static std::vector<msgr_rdma_context_t*> create_all(const std::vector<addr_mask_t> & osd_network_masks,
|
||||
const char *sel_dev_name, int sel_port_num, int sel_gid_index, uint32_t sel_mtu, bool odp, int log_level);
|
||||
static msgr_rdma_context_t *create(ibv_device *dev, ibv_port_attr & portinfo,
|
||||
int ib_port, int gid_index, uint32_t mtu, bool odp, int log_level);
|
||||
static msgr_rdma_context_t* create_cm(ibv_context *ctx);
|
||||
bool reserve_cqe(int n);
|
||||
|
||||
static msgr_rdma_context_t *create(std::vector<std::string> osd_networks, const char *ib_devname, uint8_t ib_port, int gid_index, uint32_t mtu, bool odp, int log_level);
|
||||
~msgr_rdma_context_t();
|
||||
};
|
||||
|
||||
|
@ -50,11 +62,14 @@ struct msgr_rdma_connection_t
|
|||
{
|
||||
msgr_rdma_context_t *ctx = NULL;
|
||||
ibv_qp *qp = NULL;
|
||||
#ifdef WITH_RDMACM
|
||||
rdma_cm_id *cmid = NULL;
|
||||
#endif
|
||||
msgr_rdma_address_t addr;
|
||||
int max_send = 0, max_recv = 0, max_sge = 0;
|
||||
int cur_send = 0, cur_recv = 0;
|
||||
uint64_t max_msg = 0;
|
||||
|
||||
int cur_send = 0, cur_recv = 0;
|
||||
int send_pos = 0, send_buf_pos = 0;
|
||||
int next_recv_buf = 0;
|
||||
std::vector<msgr_rdma_buf_t> recv_buffers;
|
||||
|
|
|
@ -98,5 +98,3 @@ std::string format_lat(uint64_t lat);
|
|||
std::string format_q(double depth);
|
||||
|
||||
bool stupid_glob(const std::string str, const std::string glob);
|
||||
|
||||
std::string implode(const std::string & sep, json11::Json array);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "epoll_manager.h"
|
||||
#include "pg_states.h"
|
||||
#include "str_util.h"
|
||||
#include "json_util.h"
|
||||
|
||||
struct placement_osd_t
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "cluster_client.h"
|
||||
#include "pg_states.h"
|
||||
#include "str_util.h"
|
||||
#include "json_util.h"
|
||||
|
||||
struct pg_lister_t
|
||||
{
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "epoll_manager.h"
|
||||
#include "pg_states.h"
|
||||
#include "str_util.h"
|
||||
#include "json_util.h"
|
||||
|
||||
struct pool_creator_t
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "cli.h"
|
||||
#include "cluster_client.h"
|
||||
#include "str_util.h"
|
||||
#include "json_util.h"
|
||||
#include "pg_states.h"
|
||||
|
||||
// List pools with space statistics
|
||||
|
@ -665,19 +666,3 @@ std::function<bool(cli_result_t &)> cli_tool_t::start_pool_ls(json11::Json cfg)
|
|||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
std::string implode(const std::string & sep, json11::Json array)
|
||||
{
|
||||
if (array.is_number() || array.is_bool() || array.is_string())
|
||||
{
|
||||
return array.as_string();
|
||||
}
|
||||
std::string res;
|
||||
bool first = true;
|
||||
for (auto & item: array.array_items())
|
||||
{
|
||||
res += (first ? item.as_string() : sep+item.as_string());
|
||||
first = false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ target_link_libraries(vitastor-osd
|
|||
Jerasure
|
||||
${ISAL_LIBRARIES}
|
||||
${IBVERBS_LIBRARIES}
|
||||
${RDMACM_LIBRARIES}
|
||||
)
|
||||
|
||||
# osd_rmw_test
|
||||
|
|
|
@ -120,7 +120,14 @@ osd_t::~osd_t()
|
|||
delete epmgr;
|
||||
if (bs)
|
||||
delete bs;
|
||||
close(listen_fd);
|
||||
#ifdef WITH_RDMACM
|
||||
for (rdma_cm_id *listener: rdmacm_listeners)
|
||||
msgr.rdmacm_destroy_listener(listener);
|
||||
rdmacm_listeners.clear();
|
||||
#endif
|
||||
for (auto listen_fd: listen_fds)
|
||||
close(listen_fd);
|
||||
listen_fds.clear();
|
||||
free(zero_buffer);
|
||||
}
|
||||
|
||||
|
@ -162,12 +169,14 @@ void osd_t::parse_config(bool init)
|
|||
else
|
||||
immediate_commit = IMMEDIATE_NONE;
|
||||
// Bind address
|
||||
bind_address = config["bind_address"].string_value();
|
||||
if (bind_address == "")
|
||||
bind_address = "0.0.0.0";
|
||||
bind_port = config["bind_port"].uint64_value();
|
||||
if (bind_port <= 0 || bind_port > 65535)
|
||||
bind_port = 0;
|
||||
#ifdef WITH_RDMACM
|
||||
// Use RDMA CM? (required for iWARP and may be useful for IB)
|
||||
this->use_rdmacm = config["use_rdmacm"].bool_value() || config["use_rdmacm"].uint64_value() != 0;
|
||||
this->disable_tcp = this->use_rdmacm && (config["disable_tcp"].bool_value() || config["disable_tcp"].uint64_value() != 0);
|
||||
#endif
|
||||
// OSD configuration
|
||||
etcd_report_interval = config["etcd_report_interval"].uint64_value();
|
||||
if (etcd_report_interval <= 0)
|
||||
|
@ -322,41 +331,44 @@ void osd_t::parse_config(bool init)
|
|||
|
||||
void osd_t::bind_socket()
|
||||
{
|
||||
if (config["osd_network"].is_string() ||
|
||||
config["osd_network"].is_array())
|
||||
if (msgr.all_osd_network_masks.size())
|
||||
{
|
||||
std::vector<std::string> mask;
|
||||
if (config["osd_network"].is_string())
|
||||
mask.push_back(config["osd_network"].string_value());
|
||||
else
|
||||
for (auto v: config["osd_network"].array_items())
|
||||
mask.push_back(v.string_value());
|
||||
auto matched_addrs = getifaddr_list(mask);
|
||||
if (matched_addrs.size() > 1)
|
||||
bind_addresses = getifaddr_list(msgr.all_osd_network_masks);
|
||||
if (!bind_addresses.size())
|
||||
{
|
||||
fprintf(stderr, "More than 1 address matches requested network(s): %s\n", json11::Json(matched_addrs).dump().c_str());
|
||||
force_stop(1);
|
||||
}
|
||||
if (!matched_addrs.size())
|
||||
{
|
||||
std::string nets;
|
||||
for (auto v: mask)
|
||||
nets += (nets == "" ? v : ","+v);
|
||||
auto nets = implode(", ", msgr.all_osd_networks);
|
||||
fprintf(stderr, "Addresses matching osd_network(s) %s not found\n", nets.c_str());
|
||||
force_stop(1);
|
||||
}
|
||||
bind_address = matched_addrs[0];
|
||||
}
|
||||
|
||||
// FIXME Support multiple listening sockets
|
||||
|
||||
listen_fd = create_and_bind_socket(bind_address, bind_port, listen_backlog, &listening_port);
|
||||
fcntl(listen_fd, F_SETFL, fcntl(listen_fd, F_GETFL, 0) | O_NONBLOCK);
|
||||
|
||||
epmgr->set_fd_handler(listen_fd, false, [this](int fd, int events)
|
||||
else
|
||||
{
|
||||
msgr.accept_connections(listen_fd);
|
||||
});
|
||||
bind_addresses.push_back("0.0.0.0");
|
||||
}
|
||||
if (!disable_tcp)
|
||||
{
|
||||
for (auto & bind_address: bind_addresses)
|
||||
{
|
||||
int listen_fd = create_and_bind_socket(bind_address, listening_port ? listening_port : bind_port, listen_backlog, &listening_port);
|
||||
fcntl(listen_fd, F_SETFL, fcntl(listen_fd, F_GETFL, 0) | O_NONBLOCK);
|
||||
epmgr->set_fd_handler(listen_fd, false, [this](int fd, int events)
|
||||
{
|
||||
msgr.accept_connections(fd);
|
||||
});
|
||||
listen_fds.push_back(listen_fd);
|
||||
}
|
||||
}
|
||||
#ifdef WITH_RDMACM
|
||||
if (use_rdmacm)
|
||||
{
|
||||
for (auto & bind_address: bind_addresses)
|
||||
{
|
||||
auto listener = msgr.rdmacm_listen(bind_address, listening_port, &listening_port, log_level);
|
||||
if (listener)
|
||||
rdmacm_listeners.push_back(listener);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool osd_t::shutdown()
|
||||
|
|
|
@ -107,8 +107,9 @@ class osd_t
|
|||
bool no_recovery = false;
|
||||
bool no_scrub = false;
|
||||
bool allow_net_split = false;
|
||||
std::string bind_address;
|
||||
int bind_port, listen_backlog = 128;
|
||||
bool use_rdmacm = false;
|
||||
bool disable_tcp = false;
|
||||
// FIXME: Implement client queue depth limit
|
||||
int client_queue_depth = 128;
|
||||
bool allow_test_ops = false;
|
||||
|
@ -200,7 +201,11 @@ class osd_t
|
|||
epoll_manager_t *epmgr = NULL;
|
||||
|
||||
int listening_port = 0;
|
||||
int listen_fd = 0;
|
||||
std::vector<std::string> bind_addresses;
|
||||
std::vector<int> listen_fds;
|
||||
#ifdef WITH_RDMACM
|
||||
std::vector<rdma_cm_id *> rdmacm_listeners;
|
||||
#endif
|
||||
ring_consumer_t consumer;
|
||||
|
||||
// op statistics
|
||||
|
|
|
@ -165,13 +165,17 @@ json11::Json osd_t::get_osd_state()
|
|||
hostname.resize(strnlen(hostname.data(), hostname.size()));
|
||||
json11::Json::object st;
|
||||
st["state"] = "up";
|
||||
if (bind_address != "0.0.0.0")
|
||||
st["addresses"] = json11::Json::array { bind_address };
|
||||
if (bind_addresses.size() != 1 || bind_addresses[0] != "0.0.0.0")
|
||||
st["addresses"] = bind_addresses;
|
||||
else
|
||||
st["addresses"] = getifaddr_list();
|
||||
st["host"] = std::string(hostname.data(), hostname.size());
|
||||
st["version"] = VITASTOR_VERSION;
|
||||
st["port"] = listening_port;
|
||||
#ifdef WITH_RDMACM
|
||||
if (rdmacm_listeners.size())
|
||||
st["rdmacm"] = true;
|
||||
#endif
|
||||
st["primary_enabled"] = run_primary;
|
||||
st["blockstore_enabled"] = bs ? true : false;
|
||||
return st;
|
||||
|
|
|
@ -25,6 +25,7 @@ target_link_libraries(stub_uring_osd
|
|||
vitastor_common
|
||||
${LIBURING_LIBRARIES}
|
||||
${IBVERBS_LIBRARIES}
|
||||
${RDMACM_LIBRARIES}
|
||||
tcmalloc_minimal
|
||||
)
|
||||
|
||||
|
|
|
@ -93,6 +93,13 @@ bool cidr6_match(const in6_addr &address, const in6_addr &network, uint8_t bits)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool cidr_sockaddr_match(const sockaddr_storage &addr, const addr_mask_t &mask)
|
||||
{
|
||||
return mask.family == addr.ss_family && (mask.family == AF_INET
|
||||
? cidr_match(*(in_addr*)&addr, mask.ipv4, mask.bits)
|
||||
: cidr6_match(*(in6_addr*)&addr, mask.ipv6, mask.bits));
|
||||
}
|
||||
|
||||
addr_mask_t cidr_parse(std::string mask)
|
||||
{
|
||||
unsigned bits = 255;
|
||||
|
@ -126,13 +133,11 @@ addr_mask_t cidr_parse(std::string mask)
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> getifaddr_list(std::vector<std::string> mask_cfg, bool include_v6)
|
||||
std::vector<std::string> getifaddr_list(const std::vector<addr_mask_t> & masks, bool include_v6)
|
||||
{
|
||||
std::vector<addr_mask_t> masks;
|
||||
for (auto mask: mask_cfg)
|
||||
for (auto & mask: masks)
|
||||
{
|
||||
masks.push_back(cidr_parse(mask));
|
||||
if (masks[masks.size()-1].family == AF_INET6)
|
||||
if (mask.family == AF_INET6)
|
||||
{
|
||||
// Auto-enable IPv6 addresses
|
||||
include_v6 = true;
|
||||
|
|
|
@ -18,5 +18,6 @@ std::string addr_to_string(const sockaddr_storage &addr);
|
|||
addr_mask_t cidr_parse(std::string mask);
|
||||
bool cidr_match(const in_addr &address, const in_addr &network, uint8_t bits);
|
||||
bool cidr6_match(const in6_addr &address, const in6_addr &network, uint8_t bits);
|
||||
std::vector<std::string> getifaddr_list(std::vector<std::string> mask_cfg = std::vector<std::string>(), bool include_v6 = false);
|
||||
bool cidr_sockaddr_match(const sockaddr_storage &addr, const addr_mask_t &mask);
|
||||
std::vector<std::string> getifaddr_list(const std::vector<addr_mask_t> & masks = std::vector<addr_mask_t>(), bool include_v6 = false);
|
||||
int create_and_bind_socket(std::string bind_address, int bind_port, int listen_backlog, int *listening_port);
|
||||
|
|
|
@ -33,3 +33,19 @@ bool json_is_false(const json11::Json & val)
|
|||
return !val.bool_value();
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string implode(const std::string & sep, json11::Json array)
|
||||
{
|
||||
if (array.is_number() || array.is_bool() || array.is_string())
|
||||
{
|
||||
return array.as_string();
|
||||
}
|
||||
std::string res;
|
||||
bool first = true;
|
||||
for (auto & item: array.array_items())
|
||||
{
|
||||
res += (first ? item.as_string() : sep+item.as_string());
|
||||
first = false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -11,3 +11,4 @@
|
|||
std::map<std::string, std::string> json_to_string_map(const json11::Json::object & config);
|
||||
bool json_is_true(const json11::Json & val);
|
||||
bool json_is_false(const json11::Json & val);
|
||||
std::string implode(const std::string & sep, json11::Json array);
|
||||
|
|
Loading…
Reference in New Issue