From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by dpdk.org (Postfix) with ESMTP id 05337728E for ; Fri, 23 Mar 2018 19:45:25 +0100 (CET) Received: by mail-wr0-f194.google.com with SMTP id z8so13086623wrh.7 for ; Fri, 23 Mar 2018 11:45:25 -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=vVO6lW+spdeSzRsluNHffGLcwCqgqMqJrKGm1bE2VEo=; b=SLEl7J0FBxHXjd0+RRNu5s3prsnDGVqmZog4DL/m8ai0nQdy6pUwAljz7tUid0sNpq H9/G+nnGE+ko7GXoHN/lUSt4Aczr0QCe7kI2HP5BkjMwIJ1loz5X6LgAK7K8dJXCq130 f9swEpLuXh9NIef8N3yw3Jkn9YNgmcq5R9HotucTNubxo+7cIrznDtkz19Sr6DZNLtmM W4U/QMfC6ooSj4WLi4EAGY/xBLh3VbdTPudNyTU7sF3CwvoULYwoyE42fYVaZ6LG65cP 0nen4YJkEABBsZBJVgak7jm6lsKR2m2IILlDroQGXAFo3P+jG8IZOTSa4a1VE79eBbCR F/EA== 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=vVO6lW+spdeSzRsluNHffGLcwCqgqMqJrKGm1bE2VEo=; b=h1dtn7QEhW1UtT3qpJKye6DsUdIOqO0mdKydi3XsEK/xuioNk9fV6XPTWHAUTIt6sa pH47CSEmYpZOya3lKkMKaLq29RiYSlNF2msRbj2sQQNovV81+6yiSr8cl1aHZaglCvQl Gfjl+nZfCUYvXWOY3B4sKhhJ88r15u3fP86H/zPWFbqUS0x5jHc0y6oVQ6S0It/URBcl iJPYvZqmUtIq/JfS2yjtjcZy73ZSRfTR/o44PjQxVbfZqtNQA93VZZOnCxF7HuL68he6 zfOqzkaESg0upmauwNW87kaxmpbYtyMUdSvhAmYDihKRwmBf7FF/ur4RKBdw+QtvFYkw wQtw== X-Gm-Message-State: AElRT7FVtpjzPQGcgirJ5pQKWf5h+gojZ9evNGCO7bDrv4AqP8JrSqtD cdHx61W1fsbq6+ouVazdL0m9grUp X-Google-Smtp-Source: AG47ELvk4JXoaWBbpso+SB3/7Y+hBEJ7v1d9aW4KV/S1WXNoIJ0dB7ZJ16i96g1DdxdCwsNemnuVOw== X-Received: by 10.223.174.2 with SMTP id x2mr25344476wrc.211.1521830725153; Fri, 23 Mar 2018 11:45:25 -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 m62sm13391776wmc.25.2018.03.23.11.45.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Mar 2018 11:45:24 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet , Neil Horman Date: Fri, 23 Mar 2018 19:45:03 +0100 Message-Id: <20180323184503.13041-2-gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180323184503.13041-1-gaetan.rivet@6wind.com> References: <20180323131236.yagasxv2nxorfjl5@bidouze.vm.6wind.com> <20180323184503.13041-1-gaetan.rivet@6wind.com> Subject: [dpdk-dev] [PATCH 2/2] dev: use rte_kvargs 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, 23 Mar 2018 18:45:26 -0000 Signed-off-by: Gaetan Rivet --- Cc: Neil Horman I find using rte_parse_kv cleaner. The function rte_dev_iterator_init is already ugly enough as it is. This is really not helping. lib/librte_eal/common/eal_common_dev.c | 127 +++++++++++++++++++++------------ lib/librte_eal/linuxapp/eal/Makefile | 1 + 2 files changed, 83 insertions(+), 45 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 21703b777..9f1a0ebda 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "eal_private.h" @@ -270,12 +271,15 @@ rte_eal_hotplug_remove(const char *busname, const char *devname) } int __rte_experimental -rte_dev_iterator_init(struct rte_dev_iterator *it, const char *str) +rte_dev_iterator_init(struct rte_dev_iterator *it, + const char *devstr) { - struct rte_bus *bus = NULL; + struct rte_kvargs *kvlist = NULL; struct rte_class *cls = NULL; - struct rte_kvarg kv; - char *slash; + struct rte_bus *bus = NULL; + struct rte_kvargs_pair *kv; + char *slash = NULL; + char *str = NULL; /* Having both busstr and clsstr NULL is illegal, * marking this iterator as invalid unless @@ -283,98 +287,131 @@ rte_dev_iterator_init(struct rte_dev_iterator *it, const char *str) */ it->busstr = NULL; it->clsstr = NULL; + str = strdup(devstr); + if (str == NULL) { + rte_errno = ENOMEM; + goto get_out; + } + slash = strchr(str, '/'); + if (slash != NULL) { + slash[0] = '\0'; + slash = strchr(devstr, '/') + 1; + } /* Safety checks and prep-work */ - if (rte_parse_kv(str, &kv)) { + kvlist = rte_kvargs_parse(str, NULL); + if (kvlist == NULL) { RTE_LOG(ERR, EAL, "Could not parse: %s\n", str); rte_errno = EINVAL; - return -rte_errno; + goto get_out; } it->device = NULL; it->class_device = NULL; - if (strcmp(kv.key, "bus") == 0) { - bus = rte_bus_find_by_name(kv.value); + kv = &kvlist->pairs[0]; + if (strcmp(kv->key, "bus") == 0) { + bus = rte_bus_find_by_name(kv->value); if (bus == NULL) { RTE_LOG(ERR, EAL, "Could not find bus \"%s\"\n", - kv.value); + kv->value); rte_errno = EFAULT; - return -rte_errno; + goto get_out; } - slash = strchr(str, '/'); if (slash != NULL) { - if (rte_parse_kv(slash + 1, &kv)) { + rte_kvargs_free(kvlist); + kvlist = rte_kvargs_parse(slash, NULL); + if (kvlist == NULL) { RTE_LOG(ERR, EAL, "Could not parse: %s\n", - slash + 1); + slash); rte_errno = EINVAL; - return -rte_errno; + goto get_out; } - cls = rte_class_find_by_name(kv.value); + kv = &kvlist->pairs[0]; + if (strcmp(kv->key, "class")) { + RTE_LOG(ERR, EAL, "Additional layer must be a class\n"); + rte_errno = EINVAL; + goto get_out; + } + cls = rte_class_find_by_name(kv->value); if (cls == NULL) { RTE_LOG(ERR, EAL, "Could not find class \"%s\"\n", - kv.value); + kv->value); rte_errno = EFAULT; - return -rte_errno; + goto get_out; } } - } else if (strcmp(kv.key, "class") == 0) { - cls = rte_class_find_by_name(kv.value); + } else if (strcmp(kv->key, "class") == 0) { + cls = rte_class_find_by_name(kv->value); if (cls == NULL) { RTE_LOG(ERR, EAL, "Could not find class \"%s\"\n", - kv.value); + kv->value); rte_errno = EFAULT; - return -rte_errno; + goto get_out; } } else { rte_errno = EINVAL; - return -rte_errno; + goto get_out; } /* The string should have at least * one layer specified. */ if (bus == NULL && cls == NULL) { rte_errno = EINVAL; - return -rte_errno; + goto get_out; } if ((bus != NULL && bus->dev_iterate == NULL) || (cls != NULL && cls->dev_iterate == NULL)) { rte_errno = ENOTSUP; - return -rte_errno; + goto get_out; } if (bus != NULL) { - it->busstr = str; + it->busstr = devstr; if (cls != NULL) - it->clsstr = slash + 1; + it->clsstr = slash; } else if (cls != NULL) { - it->clsstr = str; + it->clsstr = devstr; } - it->devstr = str; + it->devstr = devstr; it->bus = bus; it->cls = cls; - return 0; +get_out: + rte_kvargs_free(kvlist); + free(str); + return -rte_errno; +} + +/* '\0' forbidden in sym */ +static const char * +strfirstof(const char *str, + const char *sym) +{ + const char *s; + + for (s = str; s[0] != '\0'; s++) { + const char *c; + + for (c = sym; c[0] != '\0'; c++) { + if (c[0] == s[0]) + return s; + } + } + return NULL; } static char * dev_str_sane_cpy(const char *str) { - struct rte_kvarg kv; - char *end; + const char *end; char *cpy; - if (rte_parse_kv(str, &kv)) { - rte_errno = EINVAL; - return NULL; - } - /* copying '\0' is valid. */ - if (kv.next != NULL) - cpy = strdup(kv.next); - else + end = strfirstof(str, ",/"); + if (end != NULL && + end[0] == ',') { + cpy = strdup(end + 1); + } else { + /* '/' or '\0' */ cpy = strdup(""); - if (cpy == NULL) { - rte_errno = ENOMEM; - return NULL; } - end = strchr(cpy, '/'); - if (end != NULL) - end[0] = '\0'; + if (cpy == NULL) + rte_errno = ENOMEM; return cpy; } diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile index a3edbbe76..87caa23a1 100644 --- a/lib/librte_eal/linuxapp/eal/Makefile +++ b/lib/librte_eal/linuxapp/eal/Makefile @@ -27,6 +27,7 @@ LDLIBS += -lrt ifeq ($(CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES),y) LDLIBS += -lnuma endif +LDLIBS += -lrte_kvargs # specific to linuxapp exec-env SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) := eal.c -- 2.11.0