From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id C29DD42C71;
	Fri,  9 Jun 2023 21:20:44 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id A8B2742D4E;
	Fri,  9 Jun 2023 21:20:11 +0200 (CEST)
Received: from mga09.intel.com (mga09.intel.com [134.134.136.24])
 by mails.dpdk.org (Postfix) with ESMTP id DE5C042D4B
 for <dev@dpdk.org>; Fri,  9 Jun 2023 21:20:09 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1686338409; x=1717874409;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=ScSpOVMjpO+88DyUFzdGE1NUCj47I2Su3wngTqH4gb0=;
 b=ZrhV3PqSC0S5OUi2iKnyY3RUgwcZ5FW3f8hR26IyQi8wVjSAJ4Eumfmm
 lxGQd1oAOLj43Q8OodcGTns7OmlsC2sg/RT+V4p7Vo1yjdM9wjCFYkTrC
 MviPBtBZFi4XHA0iN62z4rCTMoiz/oZ2jf4AGgeEg6gcuKsiq+b5EvTJb
 pLz+BzPctbCOflSeySBIGd9KiF1iw4BpFN2VThu2Tng+BSm9uTTD9XXdH
 /ZndHNnRx8rYNtac0wXCPKR29w+gPXSAOhmCAf+GezLEfpck1/Ievxpbx
 qhEpZUXq9jOAwqPhw1iZq0rL4WbjwVVD222M1sPMA/EjoaB8kE/0nqeJS Q==;
X-IronPort-AV: E=McAfee;i="6600,9927,10736"; a="360155026"
X-IronPort-AV: E=Sophos;i="6.00,230,1681196400"; d="scan'208";a="360155026"
Received: from fmsmga006.fm.intel.com ([10.253.24.20])
 by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 09 Jun 2023 12:20:09 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=McAfee;i="6600,9927,10736"; a="957254663"
X-IronPort-AV: E=Sophos;i="6.00,230,1681196400"; d="scan'208";a="957254663"
Received: from dpdk-zhirun-lmm.sh.intel.com ([10.67.119.94])
 by fmsmga006.fm.intel.com with ESMTP; 09 Jun 2023 12:20:06 -0700
From: Zhirun Yan <zhirun.yan@intel.com>
To: dev@dpdk.org, jerinj@marvell.com, kirankumark@marvell.com,
 ndabilpuram@marvell.com, stephen@networkplumber.org,
 pbhagavatula@marvell.com, jerinjacobk@gmail.com, david.marchand@redhat.com
Cc: cunming.liang@intel.com, haiyue.wang@intel.com,
 mattias.ronnblom@ericsson.com, Zhirun Yan <zhirun.yan@intel.com>
Subject: [PATCH v12 07/16] graph: move node clone name func into private as
 common
Date: Sat, 10 Jun 2023 03:12:36 +0800
Message-Id: <20230609191245.252521-8-zhirun.yan@intel.com>
X-Mailer: git-send-email 2.37.2
In-Reply-To: <20230609191245.252521-1-zhirun.yan@intel.com>
References: <20230608151844.1823783-1-zhirun.yan@intel.com>
 <20230609191245.252521-1-zhirun.yan@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Move clone_name() into graph_private.h as a common function for both node
and graph to naming a new cloned object.

Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>
Signed-off-by: Cunming Liang <cunming.liang@intel.com>
Signed-off-by: Zhirun Yan <zhirun.yan@intel.com>
Acked-by: Jerin Jacob <jerinj@marvell.com>
---
 lib/graph/graph_private.h | 41 +++++++++++++++++++++++++++++++++++++++
 lib/graph/node.c          | 26 +------------------------
 2 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/lib/graph/graph_private.h b/lib/graph/graph_private.h
index 6d2137c81b..a6d8c6e98b 100644
--- a/lib/graph/graph_private.h
+++ b/lib/graph/graph_private.h
@@ -11,6 +11,8 @@
 #include <rte_common.h>
 #include <rte_eal.h>
 #include <rte_spinlock.h>
+#include <rte_errno.h>
+#include <rte_string_fns.h>
 
 #include "rte_graph.h"
 #include "rte_graph_worker.h"
@@ -114,6 +116,45 @@ struct graph {
 	/**< Nodes in a graph. */
 };
 
+/* Node and graph common functions */
+/**
+ * @internal
+ *
+ * Naming a cloned graph or node by appending a string to base name.
+ *
+ * @param new_name
+ *   Pointer to the name of the cloned object.
+ * @param base_name
+ *   Pointer to the name of original object.
+ * @param append_str
+ *   Pointer to the appended string.
+ *
+ * @return
+ *   0 on success, negative errno value otherwise.
+ */
+static inline int clone_name(char *new_name, char *base_name, const char *append_str)
+{
+	ssize_t sz, rc;
+
+#define SZ RTE_MIN(RTE_NODE_NAMESIZE, RTE_GRAPH_NAMESIZE)
+	rc = rte_strscpy(new_name, base_name, SZ);
+	if (rc < 0)
+		goto fail;
+	sz = rc;
+	rc = rte_strscpy(new_name + sz, "-", RTE_MAX((int16_t)(SZ - sz), 0));
+	if (rc < 0)
+		goto fail;
+	sz += rc;
+	sz = rte_strscpy(new_name + sz, append_str, RTE_MAX((int16_t)(SZ - sz), 0));
+	if (sz < 0)
+		goto fail;
+
+	return 0;
+fail:
+	rte_errno = E2BIG;
+	return -rte_errno;
+}
+
 /* Node functions */
 STAILQ_HEAD(node_head, node);
 
diff --git a/lib/graph/node.c b/lib/graph/node.c
index 339b4a0da5..99a9622779 100644
--- a/lib/graph/node.c
+++ b/lib/graph/node.c
@@ -115,30 +115,6 @@ __rte_node_register(const struct rte_node_register *reg)
 	return RTE_NODE_ID_INVALID;
 }
 
-static int
-clone_name(struct rte_node_register *reg, struct node *node, const char *name)
-{
-	ssize_t sz, rc;
-
-#define SZ RTE_NODE_NAMESIZE
-	rc = rte_strscpy(reg->name, node->name, SZ);
-	if (rc < 0)
-		goto fail;
-	sz = rc;
-	rc = rte_strscpy(reg->name + sz, "-", RTE_MAX((int16_t)(SZ - sz), 0));
-	if (rc < 0)
-		goto fail;
-	sz += rc;
-	sz = rte_strscpy(reg->name + sz, name, RTE_MAX((int16_t)(SZ - sz), 0));
-	if (sz < 0)
-		goto fail;
-
-	return 0;
-fail:
-	rte_errno = E2BIG;
-	return -rte_errno;
-}
-
 static rte_node_t
 node_clone(struct node *node, const char *name)
 {
@@ -170,7 +146,7 @@ node_clone(struct node *node, const char *name)
 		reg->next_nodes[i] = node->next_nodes[i];
 
 	/* Naming ceremony of the new node. name is node->name + "-" + name */
-	if (clone_name(reg, node, name))
+	if (clone_name(reg->name, node->name, name))
 		goto free;
 
 	rc = __rte_node_register(reg);
-- 
2.37.2