All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Cc: Gaetan Rivet <gaetan.rivet@6wind.com>
Subject: [PATCH v5 07/10] devargs: make parsing variadic
Date: Tue, 24 Apr 2018 01:54:49 +0200	[thread overview]
Message-ID: <0192a12d5f027e2e3fe7f3f955b4499ee10d10fd.1524527213.git.gaetan.rivet@6wind.com> (raw)
In-Reply-To: <cover.1524527213.git.gaetan.rivet@6wind.com>
In-Reply-To: <cover.1524527213.git.gaetan.rivet@6wind.com>

rte_eal_devargs_parse can be used by EAL subsystems, drivers,
applications alike.

Device parameters may be presented with different structure each time;
as a single declaration string or several strings each describing
different parts of the declaration.

To simplify the use of this parsing facility, its parameters are made
variadic.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
---
 drivers/net/failsafe/failsafe_args.c        |  2 +-
 drivers/net/failsafe/failsafe_eal.c         |  2 +-
 lib/librte_eal/common/eal_common_dev.c      | 33 ++++-------------------------
 lib/librte_eal/common/eal_common_devargs.c  | 15 ++++++++++---
 lib/librte_eal/common/include/rte_devargs.h | 11 ++++++----
 5 files changed, 25 insertions(+), 38 deletions(-)

diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c
index 20d2f520a..5edc061e8 100644
--- a/drivers/net/failsafe/failsafe_args.c
+++ b/drivers/net/failsafe/failsafe_args.c
@@ -63,7 +63,7 @@ fs_parse_device(struct sub_device *sdev, char *args)
 
 	d = &sdev->devargs;
 	DEBUG("%s", args);
-	ret = rte_eal_devargs_parse(args, d);
+	ret = rte_eal_devargs_parse(d, "%s", args);
 	if (ret) {
 		DEBUG("devargs parsing failed with code %d", ret);
 		return ret;
diff --git a/drivers/net/failsafe/failsafe_eal.c b/drivers/net/failsafe/failsafe_eal.c
index 4078fdbb0..c11621e93 100644
--- a/drivers/net/failsafe/failsafe_eal.c
+++ b/drivers/net/failsafe/failsafe_eal.c
@@ -69,7 +69,7 @@ fs_bus_init(struct rte_eth_dev *dev)
 			else
 				snprintf(devstr, sizeof(devstr), "%s",
 					 rte_eth_devices[pid].device->name);
-			ret = rte_eal_devargs_parse(devstr, da);
+			ret = rte_eal_devargs_parse(da, "%s", devstr);
 			if (ret) {
 				ERROR("Probed devargs parsing failed with code"
 				      " %d", ret);
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 149e9ad72..809d6649d 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -114,29 +114,12 @@ int rte_eal_dev_detach(struct rte_device *dev)
 	return ret;
 }
 
-static char *
-full_dev_name(const char *bus, const char *dev, const char *args)
-{
-	char *name;
-	size_t len;
-
-	len = snprintf(NULL, 0, "%s:%s,%s", bus, dev, args) + 1;
-	name = calloc(1, len);
-	if (name == NULL) {
-		RTE_LOG(ERR, EAL, "Could not allocate full device name\n");
-		return NULL;
-	}
-	snprintf(name, len, "%s:%s,%s", bus, dev, args);
-	return name;
-}
-
 int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devname,
 			const char *devargs)
 {
 	struct rte_bus *bus;
 	struct rte_device *dev;
 	struct rte_devargs *da;
-	char *name;
 	int ret;
 
 	bus = rte_bus_find_by_name(busname);
@@ -151,17 +134,12 @@ int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devn
 		return -ENOTSUP;
 	}
 
-	name = full_dev_name(busname, devname, devargs);
-	if (name == NULL)
+	da = calloc(1, sizeof(*da));
+	if (da == NULL)
 		return -ENOMEM;
 
-	da = calloc(1, sizeof(*da));
-	if (da == NULL) {
-		ret = -ENOMEM;
-		goto err_name;
-	}
-
-	ret = rte_eal_devargs_parse(name, da);
+	ret = rte_eal_devargs_parse(da, "%s:%s,%s",
+				    busname, devname, devargs);
 	if (ret)
 		goto err_devarg;
 
@@ -187,7 +165,6 @@ int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devn
 			dev->name);
 		goto err_devarg;
 	}
-	free(name);
 	return 0;
 
 err_devarg:
@@ -195,8 +172,6 @@ int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devn
 		free(da->args);
 		free(da);
 	}
-err_name:
-	free(name);
 	return ret;
 }
 
diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index a7f374cfa..b251bb0a6 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -11,6 +11,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <stdarg.h>
 
 #include <rte_compat.h>
 #include <rte_dev.h>
@@ -62,15 +63,23 @@ bus_name_cmp(const struct rte_bus *bus, const void *name)
 }
 
 int __rte_experimental
-rte_eal_devargs_parse(const char *dev, struct rte_devargs *da)
+rte_eal_devargs_parse(struct rte_devargs *da, const char *format, ...)
 {
 	struct rte_bus *bus = NULL;
+	va_list ap;
+	va_start(ap, format);
+	char dev[vsnprintf(NULL, 0, format, ap) + 1];
 	const char *devname;
 	const size_t maxlen = sizeof(da->name);
 	size_t i;
 
-	if (dev == NULL || da == NULL)
+	va_end(ap);
+	if (da == NULL)
 		return -EINVAL;
+
+	va_start(ap, format);
+	vsnprintf(dev, sizeof(dev), format, ap);
+	va_end(ap);
 	/* Retrieve eventual bus info */
 	do {
 		devname = dev;
@@ -140,7 +149,7 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	if (devargs == NULL)
 		goto fail;
 
-	if (rte_eal_devargs_parse(dev, devargs))
+	if (rte_eal_devargs_parse(devargs, "%s", dev))
 		goto fail;
 	devargs->type = devtype;
 	bus = devargs->bus;
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index e48cc3cf2..eff7a3f8c 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -94,18 +94,21 @@ int rte_eal_parse_devargs_str(const char *devargs_str,
  * in argument. Store which bus will handle the device, its name
  * and the eventual device parameters.
  *
- * @param dev
- *   The device declaration string.
+ * The device string is built with a printf-like syntax.
+ *
  * @param da
  *   The devargs structure holding the device information.
+ * @param format
+ *   Format string describing a device.
  *
  * @return
  *   - 0 on success.
  *   - Negative errno on error.
  */
 int __rte_experimental
-rte_eal_devargs_parse(const char *dev,
-		      struct rte_devargs *da);
+rte_eal_devargs_parse(struct rte_devargs *da,
+		      const char *format, ...)
+__attribute__((format(printf, 2, 0)));
 
 /**
  * Insert an rte_devargs in the global list.
-- 
2.11.0

  parent reply	other threads:[~2018-04-23 23:55 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-25 16:07 [PATCH 0/6] devargs cleanup Gaetan Rivet
2017-08-25 16:07 ` [PATCH 1/6] devargs: introduce iterator Gaetan Rivet
2017-08-25 16:07 ` [PATCH 2/6] devargs: introduce foreach macro Gaetan Rivet
2017-08-25 16:07 ` [PATCH 3/6] vdev: do not reference devargs_list Gaetan Rivet
2017-08-25 16:07 ` [PATCH 4/6] bus/pci: " Gaetan Rivet
2017-08-25 16:07 ` [PATCH 5/6] test: remove rte_devargs unit tests Gaetan Rivet
2017-08-25 16:07 ` [PATCH 6/6] devargs: make devargs_list private Gaetan Rivet
2017-10-12  8:21 ` [PATCH v2 00/18] devargs cleanup Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 01/18] eal: prepend busname on legacy device declaration Gaetan Rivet
2017-12-11 13:57     ` Shreyansh Jain
2017-10-12  8:21   ` [PATCH v2 02/18] eal: remove generic devtype Gaetan Rivet
2017-10-17 18:16     ` Aaron Conole
2017-10-18  8:20       ` Gaëtan Rivet
2017-10-12  8:21   ` [PATCH v2 03/18] devargs: introduce iterator Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 04/18] devargs: introduce foreach macro Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 05/18] vdev: do not reference devargs list Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 06/18] bus/pci: " Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 07/18] test: remove devargs unit tests Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 08/18] devargs: make devargs list private Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 09/18] devargs: make parsing variadic Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 10/18] devargs: require bus name prefix Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 11/18] devargs: simplify implementation Gaetan Rivet
2017-10-16 11:39     ` Shreyansh Jain
2017-10-16 11:42       ` Shreyansh Jain
2017-10-16 13:42         ` Gaëtan Rivet
2017-10-17  5:58           ` Shreyansh Jain
2017-10-12  8:21   ` [PATCH v2 12/18] eal: add generic device declaration parameter Gaetan Rivet
2017-12-13 14:26     ` Shreyansh Jain
2017-12-13 14:47       ` Gaëtan Rivet
2017-12-13 15:24         ` Shreyansh Jain
2017-10-12  8:21   ` [PATCH v2 13/18] bus: make device recognition function public Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 14/18] net/failsafe: keep legacy sub-device declaration Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 15/18] ether: use new devargs parsing function Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 16/18] devargs: remove old " Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 17/18] devargs: use proper prefix Gaetan Rivet
2017-10-12  8:21   ` [PATCH v2 18/18] doc: remove devargs deprecation notices Gaetan Rivet
2017-10-12 11:28     ` Mcnamara, John
2017-12-13 10:17     ` Shreyansh Jain
2017-12-13 10:25       ` Gaëtan Rivet
2017-12-13 10:54         ` Shreyansh Jain
2017-12-22  4:59           ` Shreyansh Jain
2017-12-22  8:33             ` Gaëtan Rivet
2017-10-17 18:18   ` [PATCH v2 00/18] devargs cleanup Aaron Conole
2017-10-18  8:36     ` Gaëtan Rivet
2018-03-20 23:20   ` [PATCH v3 00/10] " Gaetan Rivet
2018-03-20 23:20     ` [PATCH v3 01/10] devargs: introduce iterator Gaetan Rivet
2018-03-21  5:43       ` Tan, Jianfeng
2018-03-21  8:50         ` Gaëtan Rivet
2018-03-20 23:20     ` [PATCH v3 02/10] devargs: introduce foreach macro Gaetan Rivet
2018-04-22 21:42       ` Thomas Monjalon
2018-03-20 23:20     ` [PATCH v3 03/10] bus/vdev: do not reference devargs list Gaetan Rivet
2018-03-21  5:41       ` Tan, Jianfeng
2018-03-20 23:20     ` [PATCH v3 04/10] bus/pci: " Gaetan Rivet
2018-03-20 23:20     ` [PATCH v3 05/10] net/vdev_netvsc: " Gaetan Rivet
2018-03-20 23:20     ` [PATCH v3 06/10] test: remove devargs unit tests Gaetan Rivet
2018-03-20 23:20     ` [PATCH v3 07/10] devargs: make devargs list private Gaetan Rivet
2018-04-22 21:46       ` Thomas Monjalon
2018-03-20 23:20     ` [PATCH v3 08/10] devargs: make parsing variadic Gaetan Rivet
2018-04-22 21:52       ` Thomas Monjalon
2018-03-20 23:20     ` [PATCH v3 09/10] devargs: use proper namespace prefix Gaetan Rivet
2018-03-20 23:20     ` [PATCH v3 10/10] devargs: rename legacy API Gaetan Rivet
2018-04-22 22:00     ` [PATCH v3 00/10] devargs cleanup Thomas Monjalon
2018-04-23 22:41 ` [PATCH v4 " Gaetan Rivet
2018-04-23 22:41   ` [PATCH v4 01/10] devargs: introduce iterator Gaetan Rivet
2018-04-23 23:54     ` Stephen Hemminger
2018-04-24 10:22       ` Gaëtan Rivet
2018-04-23 22:41   ` [PATCH v4 02/10] devargs: introduce foreach macro Gaetan Rivet
2018-04-23 23:56     ` Stephen Hemminger
2018-04-24 10:26       ` Gaëtan Rivet
2018-04-23 22:41   ` [PATCH v4 03/10] bus/vdev: do not reference devargs list Gaetan Rivet
2018-04-23 22:41   ` [PATCH v4 04/10] bus/pci: " Gaetan Rivet
2018-04-23 22:41   ` [PATCH v4 05/10] net/vdev_netvsc: " Gaetan Rivet
2018-04-23 22:41   ` [PATCH v4 06/10] test: remove devargs unit tests Gaetan Rivet
2018-04-23 22:41   ` [PATCH v4 07/10] devargs: make devargs list private Gaetan Rivet
2018-04-23 22:41   ` [PATCH v4 08/10] devargs: make parsing variadic Gaetan Rivet
2018-04-23 22:41   ` [PATCH v4 09/10] devargs: use proper namespace prefix Gaetan Rivet
2018-04-23 22:41   ` [PATCH v4 10/10] devargs: rename legacy API Gaetan Rivet
2018-04-23 23:54 ` [PATCH v5 00/10] devargs cleanup Gaetan Rivet
2018-04-23 23:54   ` [PATCH v5 01/10] devargs: introduce iterator Gaetan Rivet
2018-04-23 23:54   ` [PATCH v5 02/10] bus/vdev: do not reference devargs list Gaetan Rivet
2018-04-23 23:54   ` [PATCH v5 03/10] bus/pci: " Gaetan Rivet
2018-04-23 23:54   ` [PATCH v5 04/10] net/vdev_netvsc: " Gaetan Rivet
2018-04-23 23:54   ` [PATCH v5 05/10] test: remove devargs unit tests Gaetan Rivet
2018-04-25  0:45     ` Thomas Monjalon
2018-04-23 23:54   ` [PATCH v5 06/10] devargs: make devargs list private Gaetan Rivet
2018-04-23 23:54   ` Gaetan Rivet [this message]
2018-04-23 23:54   ` [PATCH v5 08/10] devargs: update devargs add documentation Gaetan Rivet
2018-04-23 23:54   ` [PATCH v5 09/10] devargs: use proper namespace prefix Gaetan Rivet
2018-04-23 23:54   ` [PATCH v5 10/10] devargs: rename legacy API Gaetan Rivet
2018-04-25  1:51     ` Thomas Monjalon
2018-04-25  1:57   ` [PATCH v5 00/10] devargs cleanup Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0192a12d5f027e2e3fe7f3f955b4499ee10d10fd.1524527213.git.gaetan.rivet@6wind.com \
    --to=gaetan.rivet@6wind.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.