diff mbox series

lib/telemetry: fix passing full params string to command

Message ID 20200825120133.44316-1-ciara.power@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series lib/telemetry: fix passing full params string to command | expand

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS

Commit Message

Power, Ciara Aug. 25, 2020, 12:01 p.m. UTC
Telemetry only passed the first param to the command handler if multiple
were entered by the user, separated by commas. Telemetry is required to
pass the full params string to the command, by splitting by a comma
delimiter only once to remove the command part of the string. This will
enable future commands to take multiple param values.

Fixes: b1ad0e124536 ("rawdev: add telemetry callbacks")
Fixes: c190daedb9b1 ("ethdev: add telemetry callbacks")
Fixes: 6dd571fd07c3 ("telemetry: introduce new functionality")
Cc: bruce.richardson@intel.com
Cc: stable@dpdk.org

Signed-off-by: Ciara Power <ciara.power@intel.com>
---
 lib/librte_ethdev/rte_ethdev.c   | 10 ++++++++--
 lib/librte_rawdev/rte_rawdev.c   |  5 ++++-
 lib/librte_telemetry/telemetry.c |  2 +-
 3 files changed, 13 insertions(+), 4 deletions(-)

Comments

Bruce Richardson Aug. 25, 2020, 1:14 p.m. UTC | #1
On Tue, Aug 25, 2020 at 01:01:33PM +0100, Ciara Power wrote:
> Telemetry only passed the first param to the command handler if multiple
> were entered by the user, separated by commas. Telemetry is required to
> pass the full params string to the command, by splitting by a comma
> delimiter only once to remove the command part of the string. This will
> enable future commands to take multiple param values.
> 
> Fixes: b1ad0e124536 ("rawdev: add telemetry callbacks")
> Fixes: c190daedb9b1 ("ethdev: add telemetry callbacks")
> Fixes: 6dd571fd07c3 ("telemetry: introduce new functionality")
> Cc: bruce.richardson@intel.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ciara Power <ciara.power@intel.com>
> ---
>  lib/librte_ethdev/rte_ethdev.c   | 10 ++++++++--
>  lib/librte_rawdev/rte_rawdev.c   |  5 ++++-
>  lib/librte_telemetry/telemetry.c |  2 +-
>  3 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
> index 7858ad5f11..6ba09362db 100644
> --- a/lib/librte_ethdev/rte_ethdev.c
> +++ b/lib/librte_ethdev/rte_ethdev.c
> @@ -5284,11 +5284,14 @@ handle_port_xstats(const char *cmd __rte_unused,
>  	struct rte_eth_xstat_name *xstat_names;
>  	int port_id, num_xstats;
>  	int i, ret;
> +	char *end_param;
>  
>  	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
>  		return -1;
>  
> -	port_id = atoi(params);
> +	port_id = strtoul(params, &end_param, 0);
> +	if (*end_param != '\0')
> +		RTE_ETHDEV_LOG(NOTICE, "Extra params passed to telemetry command for ethdev xstats, first param in use");

The text is a bit long, so maybe you can put the string on it's own line.
Also, I'd change "params" to the full word "parameters", and remove "first
param in use". Maybe the word "ignoring" would substitute for the last
part, e.g.

"Extra parameters passed to ethdev telemetry command, ignoring."
diff mbox series

Patch

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 7858ad5f11..6ba09362db 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -5284,11 +5284,14 @@  handle_port_xstats(const char *cmd __rte_unused,
 	struct rte_eth_xstat_name *xstat_names;
 	int port_id, num_xstats;
 	int i, ret;
+	char *end_param;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
 		return -1;
 
-	port_id = atoi(params);
+	port_id = strtoul(params, &end_param, 0);
+	if (*end_param != '\0')
+		RTE_ETHDEV_LOG(NOTICE, "Extra params passed to telemetry command for ethdev xstats, first param in use");
 	if (!rte_eth_dev_is_valid_port(port_id))
 		return -1;
 
@@ -5330,11 +5333,14 @@  handle_port_link_status(const char *cmd __rte_unused,
 	static const char *status_str = "status";
 	int ret, port_id;
 	struct rte_eth_link link;
+	char *end_param;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
 		return -1;
 
-	port_id = atoi(params);
+	port_id = strtoul(params, &end_param, 0);
+	if (*end_param != '\0')
+		RTE_ETHDEV_LOG(NOTICE, "Extra params passed to telemetry command for ethdev link status, first param in use");
 	if (!rte_eth_dev_is_valid_port(port_id))
 		return -1;
 
diff --git a/lib/librte_rawdev/rte_rawdev.c b/lib/librte_rawdev/rte_rawdev.c
index 8f84d0b228..51c4470b0c 100644
--- a/lib/librte_rawdev/rte_rawdev.c
+++ b/lib/librte_rawdev/rte_rawdev.c
@@ -565,11 +565,14 @@  handle_dev_xstats(const char *cmd __rte_unused,
 	struct rte_rawdev_xstats_name *xstat_names;
 	int dev_id, num_xstats, i, ret;
 	unsigned int *ids;
+	char *end_param;
 
 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
 		return -1;
 
-	dev_id = atoi(params);
+	dev_id = strtoul(params, &end_param, 0);
+	if (*end_param != '\0')
+		RTE_RDEV_LOG(NOTICE, "Extra params passed to telemetry command for rawdev xstats, first param in use");
 	if (!rte_rawdev_pmd_is_valid_dev(dev_id))
 		return -1;
 
diff --git a/lib/librte_telemetry/telemetry.c b/lib/librte_telemetry/telemetry.c
index 0252282735..c6c2948709 100644
--- a/lib/librte_telemetry/telemetry.c
+++ b/lib/librte_telemetry/telemetry.c
@@ -248,7 +248,7 @@  client_handler(void *sock_id)
 	while (bytes > 0) {
 		buffer[bytes] = 0;
 		const char *cmd = strtok(buffer, ",");
-		const char *param = strtok(NULL, ",");
+		const char *param = strtok(NULL, "\0");
 		telemetry_cb fn = unknown_command;
 		int i;