From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by dpdk.org (Postfix) with ESMTP id 19D5C1BEB9 for ; Thu, 5 Jul 2018 13:48:59 +0200 (CEST) Received: by mail-wr1-f68.google.com with SMTP id s11-v6so1012407wra.13 for ; Thu, 05 Jul 2018 04:48:59 -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; bh=BtXr4NfMI+ivRdthjStaMQ5UqenQ5lHF1Bj/skYUi6w=; b=l4nCO8Ih3hUVs2+WOuw0IzzakDXCrszC5BQvEVB/4MousRwkbQmxmL5uqBUWRPNfnA qziv+9803YD5rAaT0nwjOQzL4puy5jDrL21rrD3BxISMXxCDLMRnkH8H4BmxynBe3nXW 7LM/1K/te6cRjdAN9o4slCdiGhlQ9RK0Q753BDHMESxyg7QK3vnzStzt3cZhJ3lZsvTE BMclj39AdMCUFF1SB8ldj+4PoMmTlsC1GExb3zlQVNOsPA0HlsZChYYXaWih+wcxWZ/D ANWBEq/P3CpqFxMmG1dFPWm8hVntxrQ0nbS7ZThyIxtbUzz2UipWMZcbnOQwzrml3fV4 Abqg== 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; bh=BtXr4NfMI+ivRdthjStaMQ5UqenQ5lHF1Bj/skYUi6w=; b=JkeSGm4YEAlYnFKPrn6zP8oGygrJELk3JKRafIBjxL+b1mFOThhXU3V1SGOBBvrwRP 4Q9BwE8qL6qv3apdvc+acErfYucIUet6Co44M5X37h7gXGs7ftGf/8Qi1LK6pbavn+6L JMrBBuBrPv99s5Ue5CiTda4HU1Cbd0QQDq2r23A9zRPIcpbEyiyUx8jUXJNM0RyRIjC4 UUNbVShEnt206vfvwbRk1cyNbGer4qavOZZCVxR37R446fgg7yq32QPz8CiHDn/wCprY AkLZKIefs67k/saj6hf1HOkaeuMqpffkruy/zsA+9FdoHeLg3m6PzjaYSECNOPMpnmOD 0zBw== X-Gm-Message-State: APt69E3v3pt80akQHU7OoBlnu+vdNjbH83aLR/BPzyWVBQ7tQjLFYcus fIdN0NsPpIuHyh+ZLoZ5j/CVLBgh X-Google-Smtp-Source: AAOMgpdET1NPJVqA2r78UVnQFmvvS5f/iP8TlNk9hR6JR2biHMadzliklEBnSJ0r8W2iQkRo43U4FA== X-Received: by 2002:adf:8796:: with SMTP id b22-v6mr4541511wrb.92.1530791338244; Thu, 05 Jul 2018 04:48:58 -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 o42-v6sm15809183wrc.50.2018.07.05.04.48.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jul 2018 04:48:57 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 5 Jul 2018 13:48:08 +0200 Message-Id: <4dd95d07b484a671a2be5d65ad12a4212093ada8.1530791217.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v10 01/27] devargs: add non-variadic parsing function 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, 05 Jul 2018 11:48:59 -0000 rte_devargs_parse becomes non-variadic, rte_devargs_parsef becomes the variadic version, to be used to compose device strings. 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 | 4 +- lib/librte_eal/common/eal_common_devargs.c | 42 ++++++++++++++++----- lib/librte_eal/common/include/rte_devargs.h | 40 +++++++++++++++++++- lib/librte_eal/rte_eal_version.map | 1 + lib/librte_ethdev/rte_ethdev.c | 2 +- 7 files changed, 76 insertions(+), 17 deletions(-) diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c index 2c002b164..626883ce2 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_devargs_parse(d, "%s", args); + ret = rte_devargs_parse(d, 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 5672f3961..ce1633f13 100644 --- a/drivers/net/failsafe/failsafe_eal.c +++ b/drivers/net/failsafe/failsafe_eal.c @@ -86,7 +86,7 @@ fs_bus_init(struct rte_eth_dev *dev) else snprintf(devstr, sizeof(devstr), "%s", rte_eth_devices[pid].device->name); - ret = rte_devargs_parse(da, "%s", devstr); + ret = rte_devargs_parse(da, 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 61cb3b162..ce4b51469 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -138,8 +138,8 @@ int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devn if (da == NULL) return -ENOMEM; - ret = rte_devargs_parse(da, "%s:%s,%s", - busname, devname, devargs); + ret = rte_devargs_parsef(da, "%s:%s,%s", + busname, devname, devargs); if (ret) goto err_devarg; diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index b0434158b..0a83beb94 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -62,24 +62,18 @@ bus_name_cmp(const struct rte_bus *bus, const void *name) return strncmp(bus->name, name, strlen(bus->name)); } -int __rte_experimental -rte_devargs_parse(struct rte_devargs *da, const char *format, ...) +__rte_experimental +int +rte_devargs_parse(struct rte_devargs *da, const char *dev) { 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; - 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; @@ -124,6 +118,34 @@ rte_devargs_parse(struct rte_devargs *da, const char *format, ...) return 0; } +__rte_experimental +int +rte_devargs_parsef(struct rte_devargs *da, const char *format, ...) +{ + va_list ap; + size_t len; + char *dev; + + if (da == NULL) + return -EINVAL; + + va_start(ap, format); + len = vsnprintf(NULL, 0, format, ap); + va_end(ap); + + dev = calloc(1, len + 1); + if (dev == NULL) { + fprintf(stderr, "ERROR: not enough memory to parse device\n"); + return -ENOMEM; + } + + va_start(ap, format); + vsnprintf(dev, len, format, ap); + va_end(ap); + + return rte_devargs_parse(da, dev); +} + int __rte_experimental rte_devargs_insert(struct rte_devargs *da) { @@ -150,7 +172,7 @@ rte_devargs_add(enum rte_devtype devtype, const char *devargs_str) if (devargs == NULL) goto fail; - if (rte_devargs_parse(devargs, "%s", dev)) + if (rte_devargs_parse(devargs, 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 58fbd90a2..6c3b6326b 100644 --- a/lib/librte_eal/common/include/rte_devargs.h +++ b/lib/librte_eal/common/include/rte_devargs.h @@ -89,6 +89,42 @@ __rte_deprecated 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. + * + * The syntax is: + * + * bus:device_identifier,arg1=val1,arg2=val2 + * + * where "bus:" is the bus name followed by any character separator. + * The bus name is optional. If no bus name is specified, each bus + * will attempt to recognize the device identifier. The first one + * to succeed will be used. + * + * Examples: + * + * pci:0000:05.00.0,arg=val + * 05.00.0,arg=val + * vdev:net_ring0 + * + * @param da + * The devargs structure holding the device information. + * + * @param dev + * String describing a device. + * + * @return + * - 0 on success. + * - Negative errno on error. + */ +__rte_experimental +int +rte_devargs_parse(struct rte_devargs *da, const char *dev); + /** * Parse a device string. * @@ -124,8 +160,8 @@ int rte_eal_parse_devargs_str(const char *devargs_str, */ __rte_experimental int -rte_devargs_parse(struct rte_devargs *da, - const char *format, ...) +rte_devargs_parsef(struct rte_devargs *da, + const char *format, ...) __attribute__((format(printf, 2, 0))); /** diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index f7dd0e7bc..1c4db72fa 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -254,6 +254,7 @@ EXPERIMENTAL { rte_devargs_insert; rte_devargs_next; rte_devargs_parse; + rte_devargs_parsef; rte_devargs_remove; rte_devargs_type_count; rte_eal_cleanup; diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index a9977df97..cce20d9ae 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -654,7 +654,7 @@ rte_eth_dev_attach(const char *devargs, uint16_t *port_id) } /* parse devargs */ - if (rte_devargs_parse(&da, "%s", devargs)) + if (rte_devargs_parse(&da, devargs)) goto err; ret = rte_eal_hotplug_add(da.bus->name, da.name, da.args); -- 2.18.0