From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by dpdk.org (Postfix) with ESMTP id 9E49B1B1B2 for ; Thu, 12 Oct 2017 10:21:52 +0200 (CEST) Received: by mail-wm0-f47.google.com with SMTP id b189so10781802wmd.4 for ; Thu, 12 Oct 2017 01:21:52 -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=O0HDpyKLtTwLaYsqKb0GUS052IrEzfb2mLu4xSqlUkE=; b=lE/Y3pbH6rGER1xXCu+hU/yeDnOM4ObU1K5Hc3a7mb5pLGJown+9wW5nD4wONrnS89 ShBy2T7r7hgeo4bAc1qKaHD0FwffEkjXP+Qa8I4ibBG++UtivPG53mzvT7ykD9jX2vsV X6QoWIbLo6LtJkl4GJY5zKu6gD11a5VbWuhGNTq4w5xRlVdYAd9G4wBEfl3we/adbm6H RkX330/GQt7Gqmm3PhL+YHKhJZe/EyKF0qqGMQbpOX9ea46ToKniT1JLfqV9KKbg8wj9 /gkeqOxeQ78MbeTJHHPwPx0aeMo98aLh06EU/ebIzpKlJwmk637a9QvSzBu51TdE3YaK 4ntQ== 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=O0HDpyKLtTwLaYsqKb0GUS052IrEzfb2mLu4xSqlUkE=; b=S4P+xaGK5Ch+tNhSmjeF2ZPx2TFVBPZI0Q4SgkXzanS78hQ4SWe6Q5BPUFWG3Mlc0B 6XksRc8y6iXJl8n8YaCEmz/TfU3njvOqesfZoZpvta3TFMEfHQ7zxhgbXIrI1f5Lx7sS rxhz2ZE38F7dES4Ewz1+HZqRQ0CBu9XCd3nizt8T4Up77Z+Jx0qoHFK6kt/NR2IgMOTX QT02yvQpfG2agD+njQEIz7N4a+kvE/Lt7Z5k714MbD3uaTty5yzZpOo0QwYO3aLtBpD5 a01gV4ytLcOrBuDrsZWiGb12GcD77CdksHlB6ra0zC0SGmy8Ie7MLNBYILJt/z2GcMDo +lhA== X-Gm-Message-State: AMCzsaUo48rV+8oTkHvvnb4xPVzIOHaIDzgEsNGlrxv0Dtd5TRzu+XSi xLgmNujKNtJpJ6RwOgbWLYSg09zS X-Google-Smtp-Source: AOwi7QB3/gwab8q3caxy2BBbObF/Uj4Iz8bdNQZv3TU8InuQIDtj7BSxbxSJVvphdf8olMhrlm5CGg== X-Received: by 10.223.171.236 with SMTP id s99mr1257684wrc.27.1507796511788; Thu, 12 Oct 2017 01:21:51 -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 200sm19424728wmu.44.2017.10.12.01.21.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Oct 2017 01:21:50 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 12 Oct 2017 10:21:16 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 09/18] 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: Thu, 12 Oct 2017 08:21:53 -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 +- 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 | 25 +++++++++++----------- 4 files changed, 30 insertions(+), 45 deletions(-) diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c index cfc83e3..08ce4ad 100644 --- a/drivers/net/failsafe/failsafe_args.c +++ b/drivers/net/failsafe/failsafe_args.c @@ -88,7 +88,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/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index e251275..b965e56 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -127,29 +127,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_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); @@ -164,17 +147,12 @@ int rte_eal_hotplug_add(const char *busname, const char *devname, 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; @@ -200,7 +178,6 @@ int rte_eal_hotplug_add(const char *busname, const char *devname, dev->name); goto err_devarg; } - free(name); return 0; err_devarg: @@ -208,8 +185,6 @@ int rte_eal_hotplug_add(const char *busname, const char *devname, 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 0f81f22..a21cc1a 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -89,15 +90,23 @@ bus_name_cmp(const struct rte_bus *bus, const void *name) } int -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; @@ -166,7 +175,7 @@ rte_eal_devargs_add(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; TAILQ_INSERT_TAIL(&devargs_list, devargs, next); return 0; diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h index 5f4ad33..1fe03d6 100644 --- a/lib/librte_eal/common/include/rte_devargs.h +++ b/lib/librte_eal/common/include/rte_devargs.h @@ -108,18 +108,20 @@ 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_eal_devargs_parse(const char *dev, - struct rte_devargs *da); +rte_eal_devargs_parse(struct rte_devargs *da, + const char *format, ...); /** * Insert an rte_devargs in the global list. @@ -137,15 +139,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 devargs_str * The arguments as given by the user. -- 2.1.4