[v11,07/16] graph: move node clone name func into private as common

Message ID 20230608151844.1823783-8-zhirun.yan@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series graph enhancement for multi-core dispatch |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Yan, Zhirun June 8, 2023, 3:18 p.m. UTC
  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(-)
  

Patch

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);