Skip to content

Commit

Permalink
issue: 1284069 Use if_index only to create any ring
Browse files Browse the repository at this point in the history
- Reduce ring_resource_creation_info_t from ring CTOR
- Ring simple has just single related net_device_val
with unique if_index and no parent
- Bond ring has primary single net_device_val with
if_index. All slaves can request primary if_index from
parent and at the same time they have own related if_index.

So to refer right ring a pair of if_index can be used in
common way.

Signed-off-by: Igor Ivanov <[email protected]>
  • Loading branch information
igor-ivanov authored and liranoz12 committed May 22, 2018
1 parent f4cdaa6 commit 07c15e3
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 147 deletions.
12 changes: 6 additions & 6 deletions src/vma/dev/ib_ctx_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ class ib_ctx_handler : public event_handler_ibverbs
* on init or constructor:
* register to event manager with m_channel and this.
* */
ibv_pd* get_ibv_pd() { return m_p_ibv_pd;}
ibv_pd* get_ibv_pd() { return m_p_ibv_pd; }
bool post_umr_wr(struct ibv_exp_send_wr &wr);
ibv_device* get_ibv_device() { return m_p_ibv_device;}
inline char* get_ibname() { return m_p_ibv_device->name; }
struct ibv_context* get_ibv_context() { return m_p_ibv_context;}
vma_ibv_device_attr* get_ibv_device_attr() { return m_p_ibv_device_attr;}
ibv_device* get_ibv_device() { return m_p_ibv_device; }
inline char* get_ibname() { return (m_p_ibv_device ? m_p_ibv_device->name : (char *)""); }
struct ibv_context* get_ibv_context() { return m_p_ibv_context; }
vma_ibv_device_attr* get_ibv_device_attr() { return m_p_ibv_device_attr; }
uint32_t mem_reg(void *addr, size_t length, uint64_t access);
void mem_dereg(uint32_t lkey);
struct ibv_mr* get_mem_reg(uint32_t lkey);
bool is_removed() { return m_removed;}
ts_conversion_mode_t get_ctx_time_converter_status();
void set_flow_tag_capability(bool flow_tag_capability);
bool get_flow_tag_capability() { return m_flow_tag_enabled;} // m_flow_tag_capability
bool get_flow_tag_capability() { return m_flow_tag_enabled; } // m_flow_tag_capability
size_t get_on_device_memory_size() { return m_on_device_memory; }
bool is_active(int port_num);
virtual void handle_event_ibverbs_cb(void *ev_data, void *ctx);
Expand Down
70 changes: 31 additions & 39 deletions src/vma/dev/net_device_val.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,23 @@ void net_device_val::set_slave_array()
m_slaves[i]->port_num, if_name, base_ifname);
}
}

if (m_slaves.size() == 0) {
m_state = INVALID;
nd_logpanic("No slave found.");
}
}

slave_data_t* net_device_val::get_slave(int if_index)
{
slave_data_vector_t::iterator iter;
for (iter = m_slaves.begin(); iter != m_slaves.end(); iter++) {
slave_data_t *cur_slave = *iter;
if (cur_slave->if_index == if_index) {
return cur_slave;
}
}
return NULL;
}

void net_device_val::verify_bonding_mode()
Expand Down Expand Up @@ -695,9 +712,9 @@ bool net_device_val::update_active_backup_slaves()

m_p_L2_addr = create_L2_address(get_ifname());
bool found_active_slave = false;
size_t slave_count = m_slaves.size();
ring_resource_creation_info_t p_ring_info[slave_count];
for (size_t i = 0; i<slave_count; i++) {
ring_resource_creation_info_t p_ring_info[m_slaves.size()];
memset(p_ring_info, 0, sizeof(p_ring_info[0]) * m_slaves.size());
for (size_t i = 0; i < m_slaves.size(); i++) {
if (if_active_slave == m_slaves[i]->if_index) {
m_slaves[i]->active = true;
found_active_slave = true;
Expand Down Expand Up @@ -796,6 +813,7 @@ bool net_device_val::update_active_slaves() {
bool up_and_active_slaves[m_slaves.size()];
size_t i = 0;

memset(p_ring_info, 0, sizeof(p_ring_info[0]) * m_slaves.size());
memset(&up_and_active_slaves, 0, m_slaves.size() * sizeof(bool));
get_up_and_active_slaves(up_and_active_slaves, m_slaves.size());

Expand Down Expand Up @@ -1130,18 +1148,6 @@ ring* net_device_val_eth::create_ring(resource_allocation_key *key)
{
ring* ring = NULL;
ring_bond* p_ring = NULL;
size_t slave_count = m_slaves.size();
if(slave_count == 0) {
nd_logpanic("Bonding configuration problem. No slave found.");
}
ring_resource_creation_info_t p_ring_info[slave_count];
for (size_t i = 0; i < slave_count; i++) {
p_ring_info[i].if_index = m_slaves[i]->if_index;
p_ring_info[i].p_ib_ctx = m_slaves[i]->p_ib_ctx;
p_ring_info[i].port_num = m_slaves[i]->port_num;
p_ring_info[i].p_l2_addr = m_slaves[i]->p_L2_addr;
p_ring_info[i].active = m_slaves[i]->active;
}

// if this is a ring profile key get the profile from the global map
if (key->get_ring_profile_key()) {
Expand All @@ -1160,12 +1166,12 @@ ring* net_device_val_eth::create_ring(resource_allocation_key *key)
switch (prof->get_ring_type()) {
#ifdef HAVE_MP_RQ
case VMA_RING_CYCLIC_BUFFER:
ring = new ring_eth_cb(get_if_idx(), p_ring_info,
ring = new ring_eth_cb(get_if_idx(),
&prof->get_desc()->ring_cyclicb);
break;
#endif
case VMA_RING_EXTERNAL_MEM:
ring = new ring_eth_direct(get_if_idx(), p_ring_info,
ring = new ring_eth_direct(get_if_idx(),
&prof->get_desc()->ring_ext);
break;
default:
Expand All @@ -1176,27 +1182,26 @@ ring* net_device_val_eth::create_ring(resource_allocation_key *key)
nd_logdbg("failed creating ring %s", error.message);
}
} else {
//TODO check if need to create bond ring even if slave count is 1
try {
switch (m_bond) {
case NO_BOND:
ring = new ring_eth(get_if_idx(), p_ring_info);
ring = new ring_eth(get_if_idx());
break;
case ACTIVE_BACKUP:
case LAG_8023ad:
ring = new ring_bond_eth(get_if_idx());
p_ring = dynamic_cast<ring_bond*>(ring);
for (size_t i = 0; i < slave_count; i++) {
p_ring->slave_create(p_ring_info[i].if_index, &p_ring_info[i]);
for (size_t i = 0; p_ring && (i < m_slaves.size()); i++) {
p_ring->slave_create(m_slaves[i]->if_index);
}
break;
case NETVSC:
{
ring_bond_eth_netvsc* p_ring_netvsc = NULL;
ring = new ring_bond_eth_netvsc(get_if_idx());
p_ring = dynamic_cast<ring_bond*>(ring);
for (size_t i = 0; i < slave_count; i++) {
p_ring->slave_create(p_ring_info[i].if_index, &p_ring_info[i]);
for (size_t i = 0; p_ring && (i < m_slaves.size()); i++) {
p_ring->slave_create(m_slaves[i]->if_index);
}
p_ring_netvsc = dynamic_cast<ring_bond_eth_netvsc*>(ring);
if (p_ring_netvsc) {
Expand Down Expand Up @@ -1292,30 +1297,17 @@ ring* net_device_val_ib::create_ring(resource_allocation_key *key)
{
ring* ring = NULL;
ring_bond* p_ring = NULL;
size_t slave_count = m_slaves.size();

NOT_IN_USE(key);

if(slave_count == 0) {
nd_logpanic("Bonding configuration problem. No slave found.");
}
ring_resource_creation_info_t p_ring_info[slave_count];
for (size_t i = 0; i<slave_count; i++) {
p_ring_info[i].if_index = m_slaves[i]->if_index;
p_ring_info[i].p_ib_ctx = m_slaves[i]->p_ib_ctx;
p_ring_info[i].port_num = m_slaves[i]->port_num;
p_ring_info[i].p_l2_addr = m_slaves[i]->p_L2_addr;
p_ring_info[i].active = m_slaves[i]->active;
}

try {
if (m_bond == NO_BOND) {
ring = new ring_ib(get_if_idx(), p_ring_info);
ring = new ring_ib(get_if_idx());
} else {
ring = new ring_bond_ib(get_if_idx());
p_ring = dynamic_cast<ring_bond*>(ring);
for (size_t i = 0; i < slave_count; i++) {
p_ring->slave_create(p_ring_info[i].if_index, &p_ring_info[i]);
for (size_t i = 0; p_ring && (i < m_slaves.size()); i++) {
p_ring->slave_create(m_slaves[i]->if_index);
}
}
} catch (vma_error &error) {
Expand Down
1 change: 1 addition & 0 deletions src/vma/dev/net_device_val.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class net_device_val
inline uint8_t* get_l2_if_addr() { return m_l2_if_addr; }
inline uint8_t* get_l2_bc_addr() { return m_l2_bc_addr; }
ip_data_vector_t* get_ip_array() { return &m_ip;}
slave_data_t* get_slave(int if_index);

void set_str();
void print_val();
Expand Down
2 changes: 2 additions & 0 deletions src/vma/dev/ring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
ring::ring() :
m_p_n_rx_channel_fds(NULL), m_parent(NULL), m_is_mp_ring(false)
{
m_if_index = 0;

#ifdef DEFINED_SOCKETXTREME
m_vma_active = true; /* TODO: This VMA version supports socketxtreme_poll() usage mode only */
INIT_LIST_HEAD(&m_ec_list);
Expand Down
9 changes: 8 additions & 1 deletion src/vma/dev/ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ring : public mem_buf_desc_owner
virtual bool attach_flow(flow_tuple& flow_spec_5t, pkt_rcvr_sink* sink) = 0;
virtual bool detach_flow(flow_tuple& flow_spec_5t, pkt_rcvr_sink* sink) = 0;

virtual void restart(ring_resource_creation_info_t* p_ring_info) = 0; //todo move to bond ?
virtual void restart(ring_resource_creation_info_t* p_ring_info) = 0;

// Funcs taken from qp_mgr.h
// Get/Release memory buffer descriptor with a linked data memory buffer
Expand Down Expand Up @@ -168,7 +168,12 @@ class ring : public mem_buf_desc_owner
}
#endif // DEFINED_SOCKETXTREME

inline int get_if_index() { return m_if_index; }

protected:
inline void set_parent(ring* parent) { m_parent = ( parent ? parent : this); }
inline void set_if_index(int if_index) { m_if_index = if_index; }

int* m_p_n_rx_channel_fds;
ring* m_parent;
bool m_is_mp_ring;
Expand All @@ -191,6 +196,8 @@ class ring : public mem_buf_desc_owner
/* This flag is enabled in case socketxtreme_poll() call is done */
bool m_vma_active;
#endif // DEFINED_SOCKETXTREME

int m_if_index; /* Interface index */
};

#endif /* RING_H */
43 changes: 19 additions & 24 deletions src/vma/dev/ring_bond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@ ring_bond::ring_bond(int if_index) :
ring(),
m_lock("ring_bond"), m_lock_ring_rx("ring_bond:lock_rx"), m_lock_ring_tx("ring_bond:lock_tx")
{
net_device_val* p_ndev = g_p_net_device_table_mgr->get_net_device_val(if_index);
if (!p_ndev) {
net_device_val* p_ndev = NULL;

/* Configure ring() fields */
set_parent(this);
set_if_index(if_index);

/* Sanity check */
p_ndev = g_p_net_device_table_mgr->get_net_device_val(m_parent->get_if_index());
if (NULL == p_ndev) {
ring_logpanic("Invalid if_index = %d", if_index);
}

m_if_index = if_index;
/* Configure ring_bond() fields */
m_bond_rings.clear();
m_parent = this;
m_type = p_ndev->get_is_bond();
m_xmit_hash_policy = p_ndev->get_bond_xmit_hash_policy();
m_min_devices_tx_inline = -1;
Expand Down Expand Up @@ -614,24 +620,17 @@ int ring_bond::socketxtreme_poll(struct vma_completion_t *vma_completions, unsig
}
#endif // DEFINED_SOCKETXTREME

void ring_bond_eth::slave_create(int if_index, ring_resource_creation_info_t* p_ring_info)
void ring_bond_eth::slave_create(int if_index)
{
ring_slave *cur_slave = NULL;

if (NULL == p_ring_info || if_index != p_ring_info->if_index) {
ring_logerr("Invalid ring slave information");
return;
}

auto_unlocker lock(m_lock);
cur_slave = new ring_eth(get_if_index(), p_ring_info, this);
cur_slave = new ring_eth(if_index, this);
if (m_min_devices_tx_inline < 0) {
m_min_devices_tx_inline = cur_slave->get_max_tx_inline();
} else {
m_min_devices_tx_inline = min(m_min_devices_tx_inline, cur_slave->get_max_tx_inline());
}
cur_slave->m_if_index = p_ring_info->if_index;
cur_slave->m_active = p_ring_info->active;
m_bond_rings.push_back(cur_slave);

if (m_bond_rings.size() > MAX_NUM_RING_RESOURCES) {
Expand All @@ -650,7 +649,7 @@ void ring_bond_eth::slave_destroy(int if_index)
auto_unlocker lock(m_lock);
for (iter = m_bond_rings.begin(); iter != m_bond_rings.end(); iter++) {
cur_slave = *iter;
if (cur_slave->m_if_index == if_index) {
if (cur_slave->get_if_index() == if_index) {
delete cur_slave;
m_bond_rings.erase(iter);
update_rx_channel_fds();
Expand All @@ -659,24 +658,17 @@ void ring_bond_eth::slave_destroy(int if_index)
}
}

void ring_bond_ib::slave_create(int if_index, ring_resource_creation_info_t* p_ring_info)
void ring_bond_ib::slave_create(int if_index)
{
ring_slave *cur_slave = NULL;

if (NULL == p_ring_info || if_index != p_ring_info->if_index) {
ring_logerr("Invalid ring slave information");
return;
}

auto_unlocker lock(m_lock);
cur_slave = new ring_ib(get_if_index(), p_ring_info, this);
cur_slave = new ring_ib(if_index, this);
if (m_min_devices_tx_inline < 0) {
m_min_devices_tx_inline = cur_slave->get_max_tx_inline();
} else {
m_min_devices_tx_inline = min(m_min_devices_tx_inline, cur_slave->get_max_tx_inline());
}
cur_slave->m_if_index = p_ring_info->if_index;
cur_slave->m_active = p_ring_info->active;
m_bond_rings.push_back(cur_slave);

if (m_bond_rings.size() > MAX_NUM_RING_RESOURCES) {
Expand All @@ -695,7 +687,7 @@ void ring_bond_ib::slave_destroy(int if_index)
auto_unlocker lock(m_lock);
for (iter = m_bond_rings.begin(); iter != m_bond_rings.end(); iter++) {
cur_slave = *iter;
if (cur_slave->m_if_index == if_index) {
if (cur_slave->get_if_index() == if_index) {
delete cur_slave;
m_bond_rings.erase(iter);
update_rx_channel_fds();
Expand All @@ -715,6 +707,9 @@ ring_bond_eth_netvsc::ring_bond_eth_netvsc(int if_index):
int err, ioctl_sock = -1;
char command_str[TAP_STR_LENGTH], return_str[TAP_STR_LENGTH], tap_name[IFNAMSIZ];

m_netvsc_idx = if_index;
memset(&m_ring_stat , 0, sizeof(m_ring_stat));

net_device_val* p_ndev = g_p_net_device_table_mgr->get_net_device_val(if_index);
if (!p_ndev) {
ring_logerr("Invalid if_index = %d", if_index);
Expand Down
9 changes: 3 additions & 6 deletions src/vma/dev/ring_bond.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class ring_bond : public ring {
ring_bond(int if_index);
virtual ~ring_bond();

inline int get_if_index() { return m_if_index; }

void free_ring_bond_resources();
virtual int request_notification(cq_type_t cq_type, uint64_t poll_sn);
virtual int poll_and_process_element_rx(uint64_t* p_cq_poll_sn, void* pv_fd_ready_array = NULL);
Expand Down Expand Up @@ -80,7 +78,7 @@ class ring_bond : public ring {
#ifdef DEFINED_SOCKETXTREME
int socketxtreme_poll(struct vma_completion_t *vma_completions, unsigned int ncompletions, int flags);
#endif // DEFINED_SOCKETXTREME
virtual void slave_create(int if_index, ring_resource_creation_info_t* p_ring_info) = 0;
virtual void slave_create(int if_index) = 0;
virtual void slave_destroy(int if_index) = 0;
protected:
void update_rx_channel_fds();
Expand All @@ -94,7 +92,6 @@ class ring_bond : public ring {
void devide_buffers_helper(descq_t *rx_reuse, descq_t *buffer_per_ring);
void devide_buffers_helper(mem_buf_desc_t *p_mem_buf_desc_list, mem_buf_desc_t** buffer_per_ring);

int m_if_index; /* Interface index (Link to related net_device_val) */
net_device_val::bond_type m_type;
net_device_val::bond_xmit_hash_policy m_xmit_hash_policy;
lock_mutex_recursive m_lock_ring_tx;
Expand All @@ -106,7 +103,7 @@ class ring_bond_eth : public ring_bond
ring_bond_eth(int if_index):
ring_bond(if_index) {}
protected:
virtual void slave_create(int if_index, ring_resource_creation_info_t* p_ring_info);
virtual void slave_create(int if_index);
virtual void slave_destroy(int if_index);
};

Expand Down Expand Up @@ -147,7 +144,7 @@ class ring_bond_ib : public ring_bond
ring_bond_ib(int if_index):
ring_bond(if_index) {}
protected:
virtual void slave_create(int if_index, ring_resource_creation_info_t* p_ring_info);
virtual void slave_create(int if_index);
virtual void slave_destroy(int if_index);
};

Expand Down
Loading

0 comments on commit 07c15e3

Please sign in to comment.