From: Xueming Li <xuemingl@nvidia.com>
To: <dev@dpdk.org>
Cc: <xuemingl@nvidia.com>, Thomas Monjalon <thomas@monjalon.net>,
"David Marchand" <david.marchand@redhat.com>
Subject: [dpdk-dev] [PATCH v1 1/3] devargs: support path value for global device arguments
Date: Tue, 5 Oct 2021 23:54:33 +0800 [thread overview]
Message-ID: <20211005155435.279043-2-xuemingl@nvidia.com> (raw)
In-Reply-To: <20211005155435.279043-1-xuemingl@nvidia.com>
Slash is used to split global device arguments.
To support path value which contains slash, this patch parses devargs by
locating both slash and layer name key:
bus=a,name=/some/path/class=b,k1=v1/driver=c,k2=v2
"/class=" and "/driver" are valid start of a layer.
Signed-off-by: Xueming Li <xuemingl@nvidia.com>
---
lib/eal/common/eal_common_devargs.c | 117 ++++++++++------------------
1 file changed, 43 insertions(+), 74 deletions(-)
diff --git a/lib/eal/common/eal_common_devargs.c b/lib/eal/common/eal_common_devargs.c
index 7ab9e71b2a3..e3786c6c02a 100644
--- a/lib/eal/common/eal_common_devargs.c
+++ b/lib/eal/common/eal_common_devargs.c
@@ -29,18 +29,6 @@ TAILQ_HEAD(rte_devargs_list, rte_devargs);
static struct rte_devargs_list devargs_list =
TAILQ_HEAD_INITIALIZER(devargs_list);
-static size_t
-devargs_layer_count(const char *s)
-{
- size_t i = s ? 1 : 0;
-
- while (s != NULL && s[0] != '\0') {
- i += s[0] == '/';
- s++;
- }
- return i;
-}
-
/* Resolve devargs name from bus arguments. */
static int
devargs_bus_parse_default(struct rte_devargs *devargs,
@@ -77,23 +65,13 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,
{ RTE_DEVARGS_KEY_DRIVER "=", NULL, NULL, },
};
struct rte_kvargs_pair *kv = NULL;
- struct rte_class *cls = NULL;
- struct rte_bus *bus = NULL;
- const char *s = devstr;
- size_t nblayer;
- size_t i = 0;
+ struct rte_kvargs *bus_kvlist = NULL;
+ char *s;
+ size_t nblayer = 0;
+ size_t i;
int ret = 0;
bool allocated_data = false;
- /* Split each sub-lists. */
- nblayer = devargs_layer_count(devstr);
- if (nblayer > RTE_DIM(layers)) {
- RTE_LOG(ERR, EAL, "Invalid format: too many layers (%zu)\n",
- nblayer);
- ret = -E2BIG;
- goto get_out;
- }
-
/* If the devargs points the devstr
* as source data, then it should not allocate
* anything and keep referring only to it.
@@ -106,33 +84,41 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,
goto get_out;
}
allocated_data = true;
- s = devargs->data;
}
+ s = devargs->data;
while (s != NULL) {
- if (i >= RTE_DIM(layers)) {
- RTE_LOG(ERR, EAL, "Unrecognized layer %s\n", s);
- ret = -EINVAL;
+ if (nblayer > RTE_DIM(layers)) {
+ ret = -E2BIG;
goto get_out;
}
- /*
- * The last layer is free-form.
- * The "driver" key is not required (but accepted).
- */
- if (strncmp(layers[i].key, s, strlen(layers[i].key)) &&
- i != RTE_DIM(layers) - 1)
- goto next_layer;
- layers[i].str = s;
- layers[i].kvlist = rte_kvargs_parse_delim(s, NULL, "/");
- if (layers[i].kvlist == NULL) {
+ layers[nblayer].str = s;
+
+ /* Locate next layer starts with valid layer key. */
+ while (s != NULL) {
+ s = strchr(s, '/');
+ if (s == NULL)
+ break;
+ for (i = 0; i < RTE_DIM(layers); i++) {
+ if (strncmp(s + 1, layers[i].key,
+ strlen(layers[i].key)) == 0) {
+ *s = '\0';
+ break;
+ }
+ }
+ s++;
+ if (i < RTE_DIM(layers))
+ break;
+ }
+
+ layers[nblayer].kvlist = rte_kvargs_parse
+ (layers[nblayer].str, NULL);
+ if (layers[nblayer].kvlist == NULL) {
ret = -EINVAL;
goto get_out;
}
- s = strchr(s, '/');
- if (s != NULL)
- s++;
-next_layer:
- i++;
+
+ nblayer++;
}
/* Parse each sub-list. */
@@ -143,52 +129,35 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,
if (kv->key == NULL)
continue;
if (strcmp(kv->key, RTE_DEVARGS_KEY_BUS) == 0) {
- bus = rte_bus_find_by_name(kv->value);
- if (bus == NULL) {
+ bus_kvlist = layers[i].kvlist;
+ devargs->bus_str = layers[i].str;
+ devargs->bus = rte_bus_find_by_name(kv->value);
+ if (devargs->bus == NULL) {
RTE_LOG(ERR, EAL, "Could not find bus \"%s\"\n",
kv->value);
ret = -EFAULT;
goto get_out;
}
} else if (strcmp(kv->key, RTE_DEVARGS_KEY_CLASS) == 0) {
- cls = rte_class_find_by_name(kv->value);
- if (cls == NULL) {
+ devargs->cls_str = layers[i].str;
+ devargs->cls = rte_class_find_by_name(kv->value);
+ if (devargs->cls == NULL) {
RTE_LOG(ERR, EAL, "Could not find class \"%s\"\n",
kv->value);
ret = -EFAULT;
goto get_out;
}
} else if (strcmp(kv->key, RTE_DEVARGS_KEY_DRIVER) == 0) {
- /* Ignore */
+ devargs->drv_str = layers[i].str;
continue;
}
}
- /* Fill devargs fields. */
- devargs->bus_str = layers[0].str;
- devargs->cls_str = layers[1].str;
- devargs->drv_str = layers[2].str;
- devargs->bus = bus;
- devargs->cls = cls;
-
- /* If we own the data, clean up a bit
- * the several layers string, to ease
- * their parsing afterward.
- */
- if (devargs->data != devstr) {
- char *s = devargs->data;
-
- while ((s = strchr(s, '/'))) {
- *s = '\0';
- s++;
- }
- }
-
/* Resolve devargs name. */
- if (bus != NULL && bus->devargs_parse != NULL)
- ret = bus->devargs_parse(devargs);
- else if (layers[0].kvlist != NULL)
- ret = devargs_bus_parse_default(devargs, layers[0].kvlist);
+ if (devargs->bus != NULL && devargs->bus->devargs_parse != NULL)
+ ret = devargs->bus->devargs_parse(devargs);
+ else if (bus_kvlist != NULL)
+ ret = devargs_bus_parse_default(devargs, bus_kvlist);
get_out:
for (i = 0; i < RTE_DIM(layers); i++) {
--
2.33.0
next prev parent reply other threads:[~2021-10-05 15:55 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-05 12:30 [dpdk-dev] [PATCH " Xueming Li
2021-10-05 12:30 ` [dpdk-dev] [PATCH 2/3] devargs: make bus key parsing optional Xueming Li
2021-10-05 12:30 ` [dpdk-dev] [PATCH 3/3] test/devargs: add devargs test cases Xueming Li
2021-10-05 14:01 ` David Marchand
2021-10-05 15:56 ` Xueming(Steven) Li
2021-10-05 15:54 ` [dpdk-dev] [PATCH v1 0/3] devargs: support path in global syntax Xueming Li
2021-10-05 15:54 ` Xueming Li [this message]
2021-10-19 14:57 ` [dpdk-dev] [PATCH v1 1/3] devargs: support path value for global device arguments Gaëtan Rivet
2021-10-05 15:54 ` [dpdk-dev] [PATCH v1 2/3] devargs: make bus key parsing optional Xueming Li
2021-10-19 15:19 ` Gaëtan Rivet
2021-10-05 15:54 ` [dpdk-dev] [PATCH v1 3/3] test/devargs: add devargs test cases Xueming Li
2021-10-19 15:07 ` Gaëtan Rivet
2021-10-20 7:20 ` Xueming(Steven) Li
2021-10-20 7:31 ` [dpdk-dev] [PATCH v2 0/3] devargs: support path in global syntax Xueming Li
2021-10-20 7:31 ` [dpdk-dev] [PATCH v2 1/3] devargs: support path value for global device arguments Xueming Li
2021-10-20 7:31 ` [dpdk-dev] [PATCH v2 2/3] devargs: make bus key parsing optional Xueming Li
2021-10-20 7:31 ` [dpdk-dev] [PATCH v2 3/3] test/devargs: add devargs test cases Xueming Li
2021-10-20 7:38 ` David Marchand
2021-10-20 8:23 ` Xueming(Steven) Li
2021-10-20 8:21 ` [dpdk-dev] [PATCH v3 0/3] devargs: support path in global syntax Xueming Li
2021-10-20 8:21 ` [dpdk-dev] [PATCH v3 1/3] devargs: support path value for global device arguments Xueming Li
2021-10-20 8:21 ` [dpdk-dev] [PATCH v3 2/3] devargs: make bus key parsing optional Xueming Li
2021-10-20 8:22 ` [dpdk-dev] [PATCH v3 3/3] test/devargs: add devargs test cases Xueming Li
2021-10-20 9:08 ` David Marchand
2021-10-20 9:40 ` Xueming(Steven) Li
2021-10-20 10:41 ` Bruce Richardson
2021-10-20 11:12 ` [dpdk-dev] [PATCH v4 0/3] devargs: support path in global syntax Xueming Li
2021-10-20 11:12 ` [dpdk-dev] [PATCH v4 1/3] devargs: support path value for global device arguments Xueming Li
2021-10-20 11:12 ` [dpdk-dev] [PATCH v4 2/3] devargs: make bus key parsing optional Xueming Li
2021-10-20 11:12 ` [dpdk-dev] [PATCH v4 3/3] test/devargs: add devargs test cases Xueming Li
2021-10-20 11:55 ` Gaëtan Rivet
2021-10-20 13:53 ` Xueming(Steven) Li
2021-10-20 14:22 ` Gaëtan Rivet
2021-10-20 14:34 ` Bruce Richardson
2021-10-20 15:47 ` [dpdk-dev] [PATCH v5 0/3] devargs: support path in global syntax Xueming Li
2021-10-20 15:47 ` [dpdk-dev] [PATCH v5 1/3] devargs: support path value for global device arguments Xueming Li
2021-10-20 15:47 ` [dpdk-dev] [PATCH v5 2/3] devargs: make bus key parsing optional Xueming Li
2021-10-20 15:47 ` [dpdk-dev] [PATCH v5 3/3] test/devargs: add devargs test cases Xueming Li
2021-10-21 9:03 ` Gaëtan Rivet
2021-10-23 6:17 ` David Marchand
2021-10-23 12:20 ` Xueming(Steven) Li
2021-10-21 9:22 ` [dpdk-dev] [PATCH v5 0/3] devargs: support path in global syntax David Marchand
2021-10-21 10:43 ` Xueming(Steven) Li
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=20211005155435.279043-2-xuemingl@nvidia.com \
--to=xuemingl@nvidia.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=thomas@monjalon.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).