summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaetan Rivet <gaetan.rivet@6wind.com>2018-04-24 01:54:49 +0200
committerThomas Monjalon <thomas@monjalon.net>2018-04-25 03:58:45 +0200
commit9e6b5ea9925a204965b859f1cc11641df03232af (patch)
tree9758703e76814fe56fe4c6d88ce68813bcfe653f
parentc7b424c03d8ed4b050fc3455ac0a0c03c22f773e (diff)
downloaddpdk-9e6b5ea9925a204965b859f1cc11641df03232af.zip
dpdk-9e6b5ea9925a204965b859f1cc11641df03232af.tar.gz
dpdk-9e6b5ea9925a204965b859f1cc11641df03232af.tar.xz
devargs: make parsing variadic
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>
-rw-r--r--drivers/net/failsafe/failsafe_args.c2
-rw-r--r--drivers/net/failsafe/failsafe_eal.c2
-rw-r--r--lib/librte_eal/common/eal_common_dev.c33
-rw-r--r--lib/librte_eal/common/eal_common_devargs.c15
-rw-r--r--lib/librte_eal/common/include/rte_devargs.h11
5 files changed, 25 insertions, 38 deletions
diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c
index 20d2f52..5edc061 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 4078fdb..c11621e 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 149e9ad..809d664 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)
- return -ENOMEM;
-
da = calloc(1, sizeof(*da));
- if (da == NULL) {
- ret = -ENOMEM;
- goto err_name;
- }
+ if (da == NULL)
+ return -ENOMEM;
- 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 @@ err_devarg:
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 a7f374c..b251bb0 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 e48cc3c..eff7a3f 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.