Skip to contentSkip to conversation

app/testpmd: add port check before manual detach

PATCH Applied Thomas Monjalon 2 participants 3 messages Feb 13, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 app/testpmd: add port check before manual detach

User may try to run "port detach <port_id>"
for an already detached device.
It has been decided to protect from such usage in testpmd, so a check was added to detach_port_device() in DPDK 19.11. This check might be removed to allow hotplug path detaching the device of a closed port.
Whatever will be decided in future, this check is also added before the call to detach_port_device().

---
 app/test-pmd/cmdline.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
app/test-pmd/cmdline.c +4 -2
index de7a695d74..99e4168103 100644
@@ -1497,10 +1497,12 @@ static void cmd_operate_detach_port_parsed(void *parsed_result,
 {
 	struct cmd_operate_detach_port_result *res = parsed_result;
 
-	if (!strcmp(res->keyword, "detach"))
+	if (!strcmp(res->keyword, "detach")) {
+		RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
 		detach_port_device(res->port_id);
-	else
+	} else {
 		printf("Unknown parameter\n");
+	}
 }
 
 cmdline_parse_token_string_t cmd_operate_detach_port_port =
Signature · 1 line
2.25.0
#1 lore raw
Quoted 19 lines · Thomas Monjalon

User may try to run "port detach <port_id>"
for an already detached device.
It has been decided to protect from such usage in testpmd, so a check was added to detach_port_device() in DPDK 19.11. This check might be removed to allow hotplug path detaching the device of a closed port.
Whatever will be decided in future, this check is also added before the call to detach_port_device().

---
 app/test-pmd/cmdline.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
app/test-pmd/cmdline.c +0 -0
index de7a695d74..99e4168103 100644

app/test-pmd/cmdline.c static void cmd_operate_detach_port_parsed(void *parsed_result, · line 1501

Quoted 6 lines
app/test-pmd/cmdline.c +2 -1
@@ -1497,10 +1497,12 @@ static void cmd_operate_detach_port_parsed(void *parsed_result,
 {
 	struct cmd_operate_detach_port_result *res = parsed_result;
 
-	if (!strcmp(res->keyword, "detach"))
+	if (!strcmp(res->keyword, "detach")) {
+		RTE_ETH_VALID_PORTID_OR_RET(res->port_id);

What do you think adding a comment to say this is a workaround for:
a) closed() ports can be re-used
b) fix problem in double detach when pointers are not cleared properly in the first pass
and this workaround should be removed when above fixed?

To give some hint to the future us why we are preventing closed ports to be detached.

Quoted 9 lines
app/test-pmd/cmdline.c +2 -1
 		detach_port_device(res->port_id);
-	else
+	} else {
 		printf("Unknown parameter\n");
+	}
 }
 
 cmdline_parse_token_string_t cmd_operate_detach_port_port =
Reviewed-by on v1 1/1 Applied
#2 lore raw
In reply to Thomas Monjalon
Quoted 10 lines · Thomas Monjalon

User may try to run "port detach <port_id>"
for an already detached device.
It has been decided to protect from such usage in testpmd, so a check was added to detach_port_device() in DPDK 19.11. This check might be removed to allow hotplug path detaching the device of a closed port.
Whatever will be decided in future, this check is also added before the call to detach_port_device().

Applied to dpdk-next-net/master, thanks.