From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by dpdk.org (Postfix) with ESMTP id 983864BE1 for ; Wed, 5 Jul 2017 01:57:22 +0200 (CEST) Received: by mail-wm0-f42.google.com with SMTP id w126so207224326wme.0 for ; Tue, 04 Jul 2017 16:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=2jWCVajeHHfPF5UfwzYZO8u3TU28jDtgQj7NnOSZ/hA=; b=fBMJQpNxaMb7XfYxp5Uj6O8ewGJ5ejhiT7+QJgYYpEao0SDviO9E9JhpaU/JAJeVb3 nT/g2VdVZwdBGwsnXGM10MzCkZFSc2pe5URRZRNk6VvniSD2pnCwyktw8RcxXHxczlXy aqVQehAo65DMy6gtdWZSxV1S+YnqH06jPxKHCwHgdc+sU5MoEalp0DvxvXkQx+/Q4OSV dLu74hvG/JojyimpIYUcr3nBlTMLkh/IG0ggQ732a2bPhlq+t92+ShV038l9zyTP8xqy UUiRwfVWYF61J5zOD+WXQ6z4pFOIYjjMkA2iH6k/oXKfCsnZvyxufJ9E//WB8WP4ItMB u2uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=2jWCVajeHHfPF5UfwzYZO8u3TU28jDtgQj7NnOSZ/hA=; b=LVZgyQd0z6k4kb2JL2e/wKhXfzIa0lW6xdEM4CEnDKd72Z5U6SzO0ygk8CcIIL2RD0 LR5dGcdbntZ3A4xzIyJYCeLzjBKQ9PEVRcAV5httG8JsvODZa8XoasoKiTjmIsI6vncv Qg+oqrVzeELf9sjLzP5FrehHqs5unR4YP/ciwrJuZTETg3GDHlvftZEcJfN1JArIScvc GsGDKMS6tV0zZ8rG2Soyw00TbTRpM8Yvu6do83sixV6+gqWwdaoHylcqJNdE96xiGKPE l+9OZCCCnu7s/VaFJT3XIBluVX0gF2AZm2qGTfDpPilpEMu6KOGJMjtyk5eSd5OniNR4 zu+g== X-Gm-Message-State: AIVw1109IJqo5aJThLTnIbIrojoTEgla6Th4f5Rh5tDE+4Vpfskdw2KU ApxHQUjnMMmYVtgRFig= X-Received: by 10.28.87.205 with SMTP id l196mr22385460wmb.121.1499212641939; Tue, 04 Jul 2017 16:57:21 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id w197sm27273899wme.20.2017.07.04.16.57.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Jul 2017 16:57:21 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 5 Jul 2017 01:56:46 +0200 Message-Id: <9b68baa2b7c9cb0606be2bbb2a54a498d5f17a0b.1499211959.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v6 16/19] devargs: introduce cleaner parsing helper X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Jul 2017 23:57:23 -0000 Introduce a more versatile helper to parse device strings. This helper expects a generic rte_devargs structure as storage in order not to require any API changes in the future, should this structure be updated. The old equivalent function is thus being deprecated, as its API does not allow to accompany current rte_devargs evolutions. A deprecation notice is issued. This new helper will parse bus information as well as device name and device parameters. It does not allocate an rte_devargs structure and expects one to be given as input. Signed-off-by: Gaetan Rivet --- doc/guides/rel_notes/deprecation.rst | 5 ++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_devargs.c | 78 ++++++++++++++++--------- lib/librte_eal/common/include/rte_devargs.h | 20 +++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 5 files changed, 79 insertions(+), 26 deletions(-) diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index 2e708db..56d0698 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -95,3 +95,8 @@ Deprecation Notices The non-"do-sig" versions of the hash tables will be removed (including the ``signature_offset`` parameter) and the "do-sig" versions renamed accordingly. + +* eal: the following function is deprecated starting from 17.08 and will + be removed in 17.11: + + - ``rte_eal_parse_devargs_str``, replaced by ``rte_eal_devargs_parse`` diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 0295ea9..cec3894 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -200,6 +200,7 @@ DPDK_17.08 { rte_bus_find; rte_bus_find_by_device; rte_bus_find_by_name; + rte_eal_devargs_parse; } DPDK_17.05; diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index 8fe1b39..3ea070d 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -86,49 +86,77 @@ bus_name_cmp(const struct rte_bus *bus, const void *_name) strlen(bus->name)); } -/* store a whitelist parameter for later parsing */ int -rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) +rte_eal_devargs_parse(const char *dev, struct rte_devargs *da) { - struct rte_devargs *devargs = NULL; struct rte_bus *bus = NULL; - char *dev = NULL; const char *devname; - int ret; - - /* use malloc instead of rte_malloc as it's called early at init */ - devargs = malloc(sizeof(*devargs)); - if (devargs == NULL) - goto fail; - - memset(devargs, 0, sizeof(*devargs)); - devargs->type = devtype; + const size_t maxlen = sizeof(da->name); + size_t i; - if (rte_eal_parse_devargs_str(devargs_str, &dev, &devargs->args)) - goto fail; - devname = dev; + if (dev == NULL || da == NULL) + return -EINVAL; + /* Retrieve eventual bus info */ do { + devname = dev; bus = rte_bus_find(bus, bus_name_cmp, dev); if (bus == NULL) break; devname = dev + strlen(bus->name) + 1; if (rte_bus_find_by_device_name(devname) == bus) break; - devname = dev; } while (1); + /* Store device name */ + i = 0; + while (devname[i] != '\0' && devname[i] != ',') { + da->name[i] = devname[i]; + i++; + if (i == maxlen) { + fprintf(stderr, "WARNING: Parsing \"%s\": device name should be shorter than %zu\n", + dev, maxlen); + da->name[i - 1] = '\0'; + return -EINVAL; + } + } + da->name[i] = '\0'; if (bus == NULL) { - bus = rte_bus_find_by_device_name(devname); + bus = rte_bus_find_by_device_name(da->name); if (bus == NULL) { - fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n"); - goto fail; + fprintf(stderr, "ERROR: failed to parse device \"%s\"\n", + da->name); + return -EFAULT; } } - devargs->bus = bus; + da->bus = bus; + /* Parse eventual device arguments */ + if (devname[i] == ',') + da->args = strdup(&devname[i + 1]); + else + da->args = strdup(""); + if (da->args == NULL) { + fprintf(stderr, "ERROR: not enough memory to parse arguments\n"); + return -ENOMEM; + } + return 0; +} + +/* store a whitelist parameter for later parsing */ +int +rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) +{ + struct rte_devargs *devargs = NULL; + struct rte_bus *bus = NULL; + const char *dev = devargs_str; - /* save device name. */ - ret = snprintf(devargs->name, sizeof(devargs->name), "%s", devname); - if (ret < 0 || ret >= (int)sizeof(devargs->name)) + /* use calloc instead of rte_zmalloc as it's called early at init */ + devargs = calloc(1, sizeof(*devargs)); + if (devargs == NULL) goto fail; + + if (rte_eal_devargs_parse(dev, devargs)) + goto fail; + devargs->type = devtype; + bus = devargs->bus; if (devargs->type == RTE_DEVTYPE_WHITELISTED) { if (bus->conf.scan_mode == RTE_BUS_SCAN_UNDEFINED) { bus->conf.scan_mode = RTE_BUS_SCAN_WHITELIST; @@ -145,12 +173,10 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) } } - free(dev); TAILQ_INSERT_TAIL(&devargs_list, devargs, next); return 0; fail: - free(dev); if (devargs) { free(devargs->args); free(devargs); diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h index 6e9e134..2ab8864 100644 --- a/lib/librte_eal/common/include/rte_devargs.h +++ b/lib/librte_eal/common/include/rte_devargs.h @@ -119,6 +119,26 @@ int rte_eal_parse_devargs_str(const char *devargs_str, char **drvname, char **drvargs); /** + * Parse a device string. + * + * Verify that a bus is capable of handling the device passed + * in argument. Store which bus will handle the device, its name + * and the eventual device parameters. + * + * @param dev + * The device declaration string. + * @param da + * The devargs structure holding the device information. + * + * @return + * - 0 on success. + * - Negative errno on error. + */ +int +rte_eal_devargs_parse(const char *dev, + struct rte_devargs *da); + +/** * Add a device to the user device list * * For PCI devices, the format of arguments string is "PCI_ADDR" or diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index a118fb1..09b875a 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -205,6 +205,7 @@ DPDK_17.08 { rte_bus_find; rte_bus_find_by_device; rte_bus_find_by_name; + rte_eal_devargs_parse; } DPDK_17.05; -- 2.1.4