From 03ce2c53a3905b11e54c424ca395ae5bea186cbd Mon Sep 17 00:00:00 2001 From: Matan Azrad Date: Thu, 3 May 2018 10:31:46 +0000 Subject: [PATCH] app/testpmd: fix synchronic port hotplug When the user uses the synchronic hot-plug commands, attach\detach, in order to insert\remove a port from the system, the forward ports list update is missed in the current implementation. Thus, an invalid port may be used for data-path in case of detach because the detached port was not removed from the forward port list. In addition, a new port is not used for data-path in case of attach, as the default behavior of Testpmd, because the attached port was not inserted to the forward port list. Update the forward port list in the above cases to allow the correct port usage for data-path in the next packet forwarding start. Fixes: edab33b1c01d ("app/testpmd: support port hotplug") Cc: stable@dpdk.org Signed-off-by: Matan Azrad --- app/test-pmd/testpmd.c | 29 +++++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 1 + 2 files changed, 30 insertions(+) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 40880ecec5..f72560ca36 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -1218,6 +1218,31 @@ launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore) } } +/* + * Update the forward ports list. + */ +void +update_fwd_ports(portid_t new_pid) +{ + unsigned int i; + unsigned int new_nb_fwd_ports = 0; + int move = 0; + + for (i = 0; i < nb_fwd_ports; ++i) { + if (port_id_is_invalid(fwd_ports_ids[i], DISABLED_WARN)) + move = 1; + else if (move) + fwd_ports_ids[new_nb_fwd_ports++] = fwd_ports_ids[i]; + else + new_nb_fwd_ports++; + } + if (new_pid < RTE_MAX_ETHPORTS) + fwd_ports_ids[new_nb_fwd_ports++] = new_pid; + + nb_fwd_ports = new_nb_fwd_ports; + nb_cfg_ports = new_nb_fwd_ports; +} + /* * Launch packet forwarding configuration. */ @@ -1938,6 +1963,8 @@ attach_port(char *identifier) ports[pi].port_status = RTE_PORT_STOPPED; + update_fwd_ports(pi); + printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports); printf("Done\n"); } @@ -1964,6 +1991,8 @@ detach_port(portid_t port_id) nb_ports = rte_eth_dev_count_avail(); + update_fwd_ports(RTE_MAX_ETHPORTS); + printf("Port '%s' is detached. Now total ports is %d\n", name, nb_ports); printf("Done\n"); diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index e6f9514120..f51cd9dd9b 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -596,6 +596,7 @@ void fwd_config_setup(void); void set_def_fwd_config(void); void reconfig(portid_t new_port_id, unsigned socket_id); int init_fwd_streams(void); +void update_fwd_ports(portid_t new_pid); void set_fwd_eth_peer(portid_t port_id, char *peer_addr); -- 2.20.1