From patchwork Thu Jun 1 10:10:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 24968 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id AD2FD7D30; Thu, 1 Jun 2017 12:11:35 +0200 (CEST) Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by dpdk.org (Postfix) with ESMTP id 0920A7D21 for ; Thu, 1 Jun 2017 12:10:56 +0200 (CEST) Received: by mail-wm0-f43.google.com with SMTP id b84so152028255wmh.0 for ; Thu, 01 Jun 2017 03:10:56 -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=SCezPnAHRY3PUDDcmOtRiSG+AZcN8/l8GGmvvKBRENE=; b=Z0hShGrSJbWOKt/ks+sufF0w9U17Gi8YS+Wzn1in92p97DMbVCXMPuOPqUA3O4/umC RiTVot7ivm0yGgy8GSIjNhCRYYj6MjJ1WDRiRiRxzHdjdie3SqoFHPmavFGdxDR9Hwi/ HMqf8BNd9ZrAw8wIVUQKsD5H55Y7oESA8L6VKW22gcGvIbXnQr3hWEK+z8vy8DsPz4zz iPaDZiitNsHD6lUccgCwDqpW/Nul4dQEEVugxU5ldf0EGeE9E1FNS5RA1RMsk/uOyHzy DUBOl7WnrUr92lSbqY5ShJnvB5yGtbBc4fdOT5H4kAnLiSj+LDW8sY2E6nugitHLlBj5 dYPA== 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=SCezPnAHRY3PUDDcmOtRiSG+AZcN8/l8GGmvvKBRENE=; b=JUyqemsX1ma1r/U7jm6ihiY49HhLL0EirEHH/PFYKEXfxSUZF/QMx0PM6fVAbDzDve ucbcZ38qORLa/okBZxRd5N5Dv0A9JLjIZza6yhN/FMaZZNuTwdJCghiaGw65v7mtNVnz QkPabsJ28zXMrLA92X4K4n5F795ZuvHlAi7R1Ckgwfr0Mu+6/Qaki1gJ+N1LpskEyCz1 8WwJn6hg+0k5PS360S2DNif9Jng1YAALGWpqEFbWAre4OSHlBlW7gIa314rYfNenF15T y6XukR2fdXvpWIWDf7sdrgw7H456+oy3sdLhF2iJrz0Ho9TCDH6a+UsbTSubLHTTdfXu BDNg== X-Gm-Message-State: AODbwcBEZ6eJ8oJ6tmh9OFlU6NZ9IHm/RrWcNbHkVjzai06NmQ8LIUl0 IyovY7jexu3q/9AXcyM= X-Received: by 10.223.169.113 with SMTP id u104mr625133wrc.193.1496311855329; Thu, 01 Jun 2017 03:10:55 -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 y19sm1022569wmh.21.2017.06.01.03.10.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Jun 2017 03:10:54 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 1 Jun 2017 12:10:29 +0200 Message-Id: <8d6c252df2760736d18085a4e4b80b21a8a29541.1496309846.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 v3 14/14] 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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/common/eal_common_devargs.c | 86 ++++++++++++++++++++--------- lib/librte_eal/common/include/rte_devargs.h | 20 +++++++ 3 files changed, 85 insertions(+), 26 deletions(-) diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index ba9b5a2..f90cd87 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -128,3 +128,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/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index d423125..7bca015 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -77,44 +77,80 @@ rte_eal_parse_devargs_str(const char *devargs_str, return 0; } -/* 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; - const char *dev = devargs_str; struct rte_bus *bus; - char *buf = NULL; + const char *c; + const size_t maxlen = sizeof(da->name); size_t i; - 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; + if ((dev) == NULL || (da) == NULL) + return -EINVAL; + c = dev; + /* Retrieve eventual bus info */ bus = rte_bus_from_name(dev); if (bus) { i = rte_bus_name_valid(dev); - dev += i + 1; - } else { - bus = rte_bus_from_dev(dev); + if (dev[i] == '\0') { + fprintf(stderr, "WARNING: device name matches a bus name.\n"); + bus = NULL; + } else { + c = &dev[i+1]; + } + } + /* Store device name */ + i = 0; + while (c[i] != '\0' && c[i] != ',') { + da->name[i] = c[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) { + bus = rte_bus_from_dev(da->name); if (!bus) { - fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n"); - goto fail; + fprintf(stderr, "ERROR: failed to parse bus info from device \"%s\"\n", + da->name); + return -EFAULT; } } - devargs->bus = bus; - if (rte_eal_parse_devargs_str(dev, &buf, &devargs->args)) + da->bus = bus; + /* Parse eventual device arguments */ + if (c[i] == ',') + da->args = strdup(&c[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; + const char *dev = devargs_str; + struct rte_bus *bus; + + /* use calloc instead of rte_zmalloc as it's called early at init */ + devargs = calloc(1, sizeof(*devargs)); + if (devargs == NULL) goto fail; - /* save device name. */ - ret = snprintf(devargs->name, sizeof(devargs->name), "%s", buf); - if (ret < 0 || ret >= (int)sizeof(devargs->name)) + 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; @@ -131,12 +167,10 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) } } - free(buf); TAILQ_INSERT_TAIL(&devargs_list, devargs, next); return 0; fail: - free(buf); 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