From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f176.google.com (mail-wr0-f176.google.com [209.85.128.176]) by dpdk.org (Postfix) with ESMTP id D44477CC4 for ; Fri, 7 Jul 2017 02:05:04 +0200 (CEST) Received: by mail-wr0-f176.google.com with SMTP id c11so24184517wrc.3 for ; Thu, 06 Jul 2017 17:05:04 -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=/w53aqj0sYXbIVE0ThaLcSz7N0WdhLcNGGBVv1Q1Azo=; b=z/9q/mjIxDux1cLIJfi/Kt13FF72DKhKzc7QlUhZyc8j6PxGvgUol8Eie4sIdjjmiG kx0ysSqwTqsArbJYES28sxaWWYUSdgLxeJT1u3AOEYgKroNKEhUO84fqCPMJ/RM7WTdA 7azhcdvSuHzvMXVP9xuaSUL/GfQz9hNyrizKIO5vW9Hn/Cglzv/2LQrH6I+gQmoFthDs 0MmDeJuuEXFGR42UorPybD/5MV+CL+Je64E4BOcr7eXLlt4493hy19dNR8TXjoiHRZ+N gcsDLLCebkQy2caack4KBrmGhF8gdtrv6ORRRsvyf/InAqZ6U71nQbgFZ5YgA60/PnFn RlRQ== 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=/w53aqj0sYXbIVE0ThaLcSz7N0WdhLcNGGBVv1Q1Azo=; b=kEiVeu+pS6aOEercrbhWgLItR8WCyJwfpa9cQZlJSEMTyWQVpV+GTQjkg6RkSsaDd9 Hh7Bx1ShYpeaWOKTrDNd4+U+cvWFRkTOTW+xFdgBxj6KWIe9hebdy6BUg9Gob1gGNORy Z38T6diDnm6O8lEczMf3MTjaafMKwnVIJsxCts2MoQjY6+sYojxAj/WZ1t7yq48/mNrA T1JWz5o+jCv9M5M8oaMV/LYqd6QzpgoeMBmRPashO9gMljk4A+N6KsQayJqE59d+YXDm hu/Nj3bBbJMhwelA1iRe7FFXknhuH6yrrIOE2H4ZzX37S/Xig6SH787eDFOam3lhonSj YU3A== X-Gm-Message-State: AIVw1120UaYg6L/IFzBKZFGBBtJg3oA7ixZcdCa+MHgUCbzDogjit062 G1PeFyDPCe/NDtXaT5g= X-Received: by 10.28.148.18 with SMTP id w18mr235950wmd.56.1499385904211; Thu, 06 Jul 2017 17:05:04 -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 b197sm1111520wmb.4.2017.07.06.17.05.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Jul 2017 17:05:03 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Fri, 7 Jul 2017 02:04:33 +0200 Message-Id: <16808437b2d5725bb846ac11524061e82807d746.1499384591.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 v7 16/17] 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: Fri, 07 Jul 2017 00:05:05 -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 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 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..381f895 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -206,6 +206,7 @@ DPDK_17.08 { EXPERIMENTAL { global: + rte_eal_devargs_parse; rte_eal_hotplug_add; rte_eal_hotplug_remove; 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 a5c4a4a..a0427cd 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..0f9e009 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -211,6 +211,7 @@ DPDK_17.08 { EXPERIMENTAL { global: + rte_eal_devargs_parse; rte_eal_hotplug_add; rte_eal_hotplug_remove; -- 2.1.4