From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gaetan Rivet Subject: [PATCH v4 17/19] devargs: clone function Date: Thu, 8 Jun 2017 01:57:03 +0200 Message-ID: References: Cc: Gaetan Rivet To: dev@dpdk.org Return-path: Received: from mail-wr0-f180.google.com (mail-wr0-f180.google.com [209.85.128.180]) by dpdk.org (Postfix) with ESMTP id E1A5D7CD6 for ; Thu, 8 Jun 2017 01:57:39 +0200 (CEST) Received: by mail-wr0-f180.google.com with SMTP id g76so11985762wrd.1 for ; Wed, 07 Jun 2017 16:57:39 -0700 (PDT) In-Reply-To: In-Reply-To: References: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This function returns a deep copy of an rte_devargs. Signed-off-by: Gaetan Rivet --- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_devargs.c | 20 ++++++++++++++++++++ lib/librte_eal/common/include/rte_devargs.h | 12 ++++++++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 4 files changed, 34 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 04fa882..a506968 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -203,5 +203,6 @@ DPDK_17.08 { rte_bus_from_name; rte_bus_from_dev; + rte_eal_devargs_clone; } DPDK_17.05; diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index b69a2b2..07b89ef 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -41,6 +41,7 @@ #include #include +#include #include "eal_private.h" /** Global list of user devices */ @@ -182,6 +183,25 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) return -1; } +/* Deep-copy of an rte_devargs. */ +struct rte_devargs * +rte_eal_devargs_clone(struct rte_devargs *da) +{ + struct rte_devargs *clone; + + clone = calloc(1, sizeof(*clone)); + if (clone == NULL) + return NULL; + snprintf(clone->name, sizeof(clone->name), "%s", da->name); + clone->args = strdup(da->args ? da->args : ""); + clone->bus = da->bus; + if (clone->args == NULL) { + free(clone); + return NULL; + } + return clone; +} + /* count the number of devices of a specified type */ unsigned int rte_eal_devargs_type_count(enum rte_devtype devtype) diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h index 2ab8864..892b035 100644 --- a/lib/librte_eal/common/include/rte_devargs.h +++ b/lib/librte_eal/common/include/rte_devargs.h @@ -163,6 +163,18 @@ rte_eal_devargs_parse(const char *dev, int rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str); /** + * Deep copy an rte_devargs. + * + * @param da + * Source devargs. + * + * @return + * The pointer to the new rte_devargs on success. + * NULL on error. + */ +struct rte_devargs *rte_eal_devargs_clone(struct rte_devargs *da); + +/** * Count the number of user devices of a specified type * * @param devtype diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index a5127d6..6e6638a 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -207,5 +207,6 @@ DPDK_17.08 { rte_bus_from_name; rte_bus_from_dev; + rte_eal_devargs_clone; } DPDK_17.05; -- 2.1.4