From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id 4F0D710BD for ; Tue, 24 Apr 2018 00:41:45 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id u18-v6so18184260wrg.3 for ; Mon, 23 Apr 2018 15:41:45 -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=bKrzyLJrsxKEFLArk4isJ9PQ7EssxhbeIz8P1m8qevo=; b=uKYdHXpVXIoQIyKmgPmt80RRpIN1YfnGz/Hyvjbzdru+vp+l8Ae3jNRIwQgU0wPwV+ 5iajSiqAdNuMbEOvFBgIeR+M8/QBkjV29xiFrSxSUzS7p++tCLoEOkg1QpsvCWd1wEPM AqyyjA6pxyk11bKCMp4lY5YgbXNbRgrZY85LUmsCzeeOnqtcrEX+UGcmJJhHKsfVCh1l IVBGaJlCT2MkGX313Ym3j7nEpqWEzmwHrhMsk2udue5i6w41bMTfgbpAiIeoHK0NEuIH 6AfzSKy1DjvScoohcqCxjQU7XWGXVtup8REEZ9MIiwajjCuU2vhLTVFrtkWVmwNb1SqN U9tQ== 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=bKrzyLJrsxKEFLArk4isJ9PQ7EssxhbeIz8P1m8qevo=; b=eW+lu8o7e1xc3rNr+7PBkgR+sT7ixT1eONa6EpMPb1x8GugcNzsUOrAjXqHYIkOjHH BMbpAlNQvUUmZ90OJ0nlxZhwrgJKsBrBLJAQRAtDyFyILudejYq9vWOUzIiXIUNJGVkD KNZKjVlim9qsXGTaLKnbwcgDMItI+3lVmwZMpLq7opDbI+JfA7NRjdEpCysjBltT84fw 5RM1Yx8YBy+0XuI/8Y/K470II/qogwMUHhtd9isM67KaFap67TkHkzBiSbAZ2a29GEw8 v8ZCZKeHiScyE7RnehjuEHE7V6uO0fuSeodaoVINBHokitfOevODsFtzVU6mAQeDx222 7Rwg== X-Gm-Message-State: ALQs6tDcmR5X8VzIm9y6SZJwXcJ6DXypa5iM1UD02zDMsdZQ6Lm8r2fn EVJY/Ds0qYvWF4HAnXLrr4Al2exs X-Google-Smtp-Source: AIpwx49YR4pVaAojo6KGyEP3oZ4ilTI30cH1EpJRwAyuSJcFqT+J9DoLTDBAAGoyOqxvKQ9tC2va2g== X-Received: by 10.28.235.3 with SMTP id j3mr11065124wmh.146.1524523304591; Mon, 23 Apr 2018 15:41:44 -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 x189sm1590705wmg.0.2018.04.23.15.41.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 15:41:43 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 24 Apr 2018 00:41:08 +0200 Message-Id: <4530c6e0150415ef5c72ca8a21bdf4bb0e08033c.1524522515.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v4 08/10] devargs: make parsing variadic 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: Mon, 23 Apr 2018 22:41:45 -0000 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 --- drivers/net/failsafe/failsafe_args.c | 2 +- drivers/net/failsafe/failsafe_eal.c | 2 +- lib/librte_eal/common/eal_common_dev.c | 33 ++++------------------------- lib/librte_eal/common/eal_common_devargs.c | 15 ++++++++++--- lib/librte_eal/common/include/rte_devargs.h | 26 ++++++++++++----------- 5 files changed, 32 insertions(+), 46 deletions(-) diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c index 20d2f520a..5edc061e8 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 4078fdbb0..c11621e93 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 149e9ad72..809d6649d 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) + da = calloc(1, sizeof(*da)); + if (da == NULL) return -ENOMEM; - da = calloc(1, sizeof(*da)); - if (da == NULL) { - ret = -ENOMEM; - goto err_name; - } - - 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 @@ int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devn 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 a7f374cfa..b251bb0a6 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -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 e48cc3cf2..e261f7c69 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. @@ -123,15 +126,14 @@ rte_eal_devargs_insert(struct rte_devargs *da); /** * Add a device to the user device list * - * For PCI devices, the format of arguments string is "PCI_ADDR" or - * "PCI_ADDR,key=val,key2=val2,...". Examples: "08:00.1", "0000:5:00.0", - * "04:00.0,arg=val". + * The format is * - * For virtual devices, the format of arguments string is "DRIVER_NAME*" - * or "DRIVER_NAME*,key=val,key2=val2,...". Examples: "net_ring", - * "net_ring0", "net_pmdAnything,arg=0:arg2=1". The validity of the - * driver name is not checked by this function, it is done when probing - * the drivers. + * bus:device_identifier,arg1=val1,arg2=val2 + * + * Examples: + * + * pci:0000:05.00.0,arg=val + * vdev:net_ring0 * * @param devtype * The type of the device. -- 2.11.0