Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue: 3928407 Remove VLAs #142

Open
wants to merge 2 commits into
base: vNext
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/dev/net_device_table_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ void net_device_table_mgr::global_ring_wait_for_notification_and_process_element
uint64_t *p_poll_sn, void *pv_fd_ready_array /*=NULL*/)
{
ndtm_logfunc("");
int max_fd = 16;
constexpr int max_fd = 16;
struct epoll_event events[max_fd];

int res = SYSCALL(epoll_wait, global_ring_epfd_get(), events, max_fd, 0);
Expand Down
114 changes: 35 additions & 79 deletions src/core/dev/net_device_val.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,8 @@ void net_device_val::set_slave_array()
}
}

bool up_and_active_slaves[m_slaves.size()];

memset(up_and_active_slaves, 0, sizeof(up_and_active_slaves));

if (m_bond == LAG_8023ad) {
get_up_and_active_slaves(up_and_active_slaves, m_slaves.size());
get_up_and_active_slaves();
}

for (uint16_t i = 0; i < m_slaves.size(); i++) {
Expand All @@ -646,12 +642,7 @@ void net_device_val::set_slave_array()
m_slaves[i]->active = true;
}

if (m_bond == LAG_8023ad) {
if (up_and_active_slaves[i]) {
m_slaves[i]->active = true;
}
}

/* For LAG_8023ad bonding the slaves status is set above */
if (m_bond == NETVSC) {
m_slaves[i]->active = true;
}
Expand Down Expand Up @@ -829,102 +820,67 @@ bool net_device_val::update_active_backup_slaves()
return 1;
}

/*
* this function assume m_slaves[i]->if_name and m_slaves.size() are already set.
*/
bool net_device_val::get_up_and_active_slaves(bool *up_and_active_slaves, size_t size)
bool net_device_val::get_up_and_active_slaves()
{
bool up_slaves[m_slaves.size()];
int num_up = 0;
bool active_slaves[m_slaves.size()];
int num_up_and_active = 0;
size_t i = 0;

if (size != m_slaves.size()) {
nd_logwarn("programmer error! array size is not correct");
return false;
}
slave_data_t *first_up_slave = nullptr;
bool first_up_slave_status = false;
bool is_changed = false;
bool is_functional = false;

/* get slaves operstate and active state */
for (i = 0; i < m_slaves.size(); i++) {
// Get slaves operstate and active state.
for (auto &slave : m_slaves) {
char oper_state[5] = {0};
char slave_state[10] = {0};
char if_name[IFNAMSIZ] = {0};
bool is_up = false;
bool is_active = false;

up_slaves[i] = false;
if (!if_indextoname(m_slaves[i]->if_index, if_name)) {
nd_logerr("Can not find interface name by index=%d", m_slaves[i]->if_index);
if (!if_indextoname(slave->if_index, if_name)) {
nd_logerr("Can not find interface name by index=%d", slave->if_index);
slave->active = false;
continue;
}

// get interface operstate
get_interface_oper_state(if_name, oper_state, sizeof(oper_state));
if (strstr(oper_state, "up")) {
num_up++;
up_slaves[i] = true;
is_up = true;
first_up_slave = first_up_slave ?: slave;
first_up_slave_status = slave->active;
}

active_slaves[i] = true;
// get slave state
is_active = true;
if (get_bond_slave_state(if_name, slave_state, sizeof(slave_state))) {
if (!strstr(slave_state, "active")) {
active_slaves[i] = false;
is_active = false;
}
}

if (active_slaves[i] && up_slaves[i]) {
up_and_active_slaves[i] = true;
num_up_and_active++;
} else {
up_and_active_slaves[i] = false;
}
bool new_status = is_up && is_active;
is_changed = is_changed || (new_status != slave->active);
is_functional = is_functional || new_status;
slave->active = new_status;
}

/* make sure at least one up interface is active */
if (!num_up_and_active && num_up) {
for (i = 0; i < m_slaves.size(); i++) {
if (up_slaves[i]) {
up_and_active_slaves[i] = true;
break;
}
}
// Make sure at least one up interface is active.
if (!is_functional && first_up_slave) {
first_up_slave->active = true;
is_changed = is_changed || !first_up_slave_status;
}

return true;
return is_changed;
}

bool net_device_val::update_active_slaves()
{
bool changed = false;
bool up_and_active_slaves[m_slaves.size()];
size_t i = 0;

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

/* compare to current status and prepare for restart */
for (i = 0; i < m_slaves.size(); i++) {
if (up_and_active_slaves[i]) {
// slave came up
if (!m_slaves[i]->active) {
nd_logdbg("slave %d is up ", m_slaves[i]->if_index);
m_slaves[i]->active = true;
changed = true;
}
} else {
// slave went down
if (m_slaves[i]->active) {
nd_logdbg("slave %d is down ", m_slaves[i]->if_index);
m_slaves[i]->active = false;
changed = true;
}
}
bool is_changed = get_up_and_active_slaves();

for (auto &slave : m_slaves) {
nd_logdbg("slave %d is %s", slave->if_index, slave->active ? "up" : "down");
NOT_IN_USE(slave); // Suppress --enable-opt-log=high warning
}

/* restart if status changed */
if (changed) {
// Restart if status changed.
if (is_changed) {
m_p_L2_addr = create_L2_address(get_ifname());
// restart rings
rings_hash_map_t::iterator ring_iter;
for (ring_iter = m_h_ring_map.begin(); ring_iter != m_h_ring_map.end(); ring_iter++) {
THE_RING->restart();
Expand Down
2 changes: 1 addition & 1 deletion src/core/dev/net_device_val.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class net_device_val {
resource_allocation_key *get_ring_key_redirection(resource_allocation_key *key);
void ring_key_redirection_release(resource_allocation_key *key);
void print_ips();
bool get_up_and_active_slaves(bool *up_and_active_slaves, size_t size);
bool get_up_and_active_slaves(); /* Returns true if a slave status is changed */

/* See: RFC 3549 2.3.3.1. */
int m_if_idx; /* Uniquely identifies interface (not unique: eth4 and eth4:5 has the same idx) */
Expand Down
11 changes: 8 additions & 3 deletions src/core/dev/ring_tap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,20 +599,25 @@ int ring_tap::mem_buf_tx_release(mem_buf_desc_t *buff_list, bool b_accounting, b

int ring_tap::send_buffer(xlio_ibv_send_wr *wr, xlio_wr_tx_packet_attr attr)
{
int ret = 0;
iovec iovec[wr->num_sge];
NOT_IN_USE(attr);

struct iovec *iovec = new struct iovec[wr->num_sge];
if (!iovec) {
errno = ENOMEM;
return -1;
}

for (int i = 0; i < wr->num_sge; i++) {
iovec[i].iov_base = (void *)wr->sg_list[i].addr;
iovec[i].iov_len = wr->sg_list[i].length;
}

ret = SYSCALL(writev, m_tap_fd, iovec, wr->num_sge);
int ret = SYSCALL(writev, m_tap_fd, iovec, wr->num_sge);
if (ret < 0) {
ring_logdbg("writev: tap_fd %d, errno: %d\n", m_tap_fd, errno);
}

delete[] iovec;
return ret;
}

Expand Down
21 changes: 13 additions & 8 deletions src/core/sock/sockinfo_tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2209,15 +2209,20 @@ err_t sockinfo_tcp::rx_lwip_cb_recv_callback(void *arg, struct tcp_pcb *pcb, str
}

// fill io vector array with data buffer pointers
iovec iov[p_first_desc->rx.n_frags];
nr_frags = 0;
for (tmp = p_first_desc; tmp; tmp = tmp->p_next_desc) {
iov[nr_frags++] = tmp->rx.frag;
}
struct iovec *iov = new struct iovec[p_first_desc->rx.n_frags];
if (likely(iov)) {
nr_frags = 0;
for (tmp = p_first_desc; tmp; tmp = tmp->p_next_desc) {
iov[nr_frags++] = tmp->rx.frag;
}

// call user callback
callback_retval =
conn->m_rx_callback(conn->m_fd, nr_frags, iov, &pkt_info, conn->m_rx_callback_context);
// call user callback
callback_retval = conn->m_rx_callback(conn->m_fd, nr_frags, iov, &pkt_info,
conn->m_rx_callback_context);
delete[] iov;
} else {
callback_retval = XLIO_PACKET_DROP;
}
}

if (callback_retval == XLIO_PACKET_DROP) {
Expand Down
11 changes: 9 additions & 2 deletions src/core/sock/sockinfo_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2307,15 +2307,22 @@ inline xlio_recv_callback_retval_t sockinfo_udp::inspect_by_user_cb(mem_buf_desc
}

// fill io vector array with data buffer pointers
iovec iov[p_desc->rx.n_frags];
int nr_frags = 0;
struct iovec *iov = new struct iovec[p_desc->rx.n_frags];
if (!iov) {
return XLIO_PACKET_DROP;
}

for (mem_buf_desc_t *tmp = p_desc; tmp; tmp = tmp->p_next_desc) {
iov[nr_frags++] = tmp->rx.frag;
}

// call user callback
return m_rx_callback(m_fd, nr_frags, iov, &pkt_info, m_rx_callback_context);
xlio_recv_callback_retval_t ret =
m_rx_callback(m_fd, nr_frags, iov, &pkt_info, m_rx_callback_context);

delete[] iov;
return ret;
}

/* Update completion with
Expand Down
2 changes: 1 addition & 1 deletion src/core/util/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int get_base_interface_name(const char *if_name, char *base_ifname, size_t sz_ba
}
}

unsigned char tmp_mac[ADDR_LEN];
unsigned char tmp_mac[MAX_L2_ADDR_LEN];
if (ADDR_LEN == get_local_ll_addr(ifa->ifa_name, tmp_mac, ADDR_LEN, false)) {
int size_to_compare = 0;
if (ADDR_LEN == ETH_ALEN) {
Expand Down
8 changes: 6 additions & 2 deletions src/stats/stats_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2303,9 +2303,12 @@ void get_all_processes_pids(std::vector<int> &pids)
int print_processes_stats(const std::vector<int> &pids)
{
const int SIZE = pids.size();

int num_instances = 0;
sh_mem_info_t sh_mem_info[SIZE];

sh_mem_info_t *sh_mem_info = new sh_mem_info_t[SIZE];
if (!sh_mem_info) {
return 1;
}

// 1. N * prepare shmem and indicate XLIO to update shmem
for (int i = 0; i < SIZE; ++i) {
Expand All @@ -2325,6 +2328,7 @@ int print_processes_stats(const std::vector<int> &pids)
complete_print_process_stats(sh_mem_info[i]);
}

delete[] sh_mem_info;
return 0;
}

Expand Down