Soft Patch Panel
 help / color / Atom feed
* [spp] [PATCH] shared/sec: move op funcs for getting status
@ 2019-06-24  7:11 yasufum.o
  0 siblings, 0 replies; only message in thread
From: yasufum.o @ 2019-06-24  7:11 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This update is to move a set of operation functions `response_info_list`
for getting status from shared dir to dirs of each of spp_vf and
spp_mirror as a function get_status_ops().

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/mirror/mir_cmd_runner.c                   | 34 +++++++++++++
 .../spp_worker_th/cmd_res_formatter.c         | 51 +++++++------------
 .../spp_worker_th/cmd_res_formatter.h         |  6 +++
 .../secondary/spp_worker_th/mirror_deps.h     |  6 +++
 src/shared/secondary/spp_worker_th/vf_deps.h  |  8 ++-
 src/vf/vf_cmd_runner.c                        | 35 +++++++++++++
 6 files changed, 105 insertions(+), 35 deletions(-)

diff --git a/src/mirror/mir_cmd_runner.c b/src/mirror/mir_cmd_runner.c
index 5f0932a..a4ca397 100644
--- a/src/mirror/mir_cmd_runner.c
+++ b/src/mirror/mir_cmd_runner.c
@@ -414,3 +414,37 @@ get_comp_type_from_str(const char *type_str)
 
 	return SPPWK_TYPE_NONE;
 }
+
+/**
+ * List of combination of tag and operator function. It is used to assemble
+ * a result of command in JSON like as following.
+ *
+ *     {
+ *         "client-id": 1,
+ *         "ports": ["phy:0", "phy:1", "vhost:0", "ring:0"],
+ *         "components": [
+ *             {
+ *                 "core": 2,
+ *                 ...
+ */
+/* TODO(yasufum) consider to create and move to vf_cmd_formatter.c */
+int get_status_ops(struct cmd_res_formatter_ops *ops_list)
+{
+	/* Num of entries should be the same as NOF_STAT_OPS in vf_deps.h. */
+	struct cmd_res_formatter_ops tmp_ops_list[] = {
+		{ "client-id", add_client_id },
+		{ "phy", add_interface },
+		{ "vhost", add_interface },
+		{ "ring", add_interface },
+		{ "master-lcore", add_master_lcore},
+		{ "core", add_core},
+		{ "", NULL }
+	};
+	memcpy(ops_list, tmp_ops_list, sizeof(tmp_ops_list));
+	if (unlikely(ops_list == NULL)) {
+		RTE_LOG(ERR, MIR_CMD_RUNNER, "Failed to setup ops_list.\n");
+		return -1;
+	}
+
+	return 0;
+}
diff --git a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
index 8d64c21..fdc8675 100644
--- a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
@@ -16,14 +16,10 @@
 
 #define RTE_LOGTYPE_WK_CMD_RES_FMT RTE_LOGTYPE_USER1
 
-/* Proto type declaration for a list of operator functions. */
+/* Proto type declaration for a list of operation functions. */
 static int append_result_value(const char *name, char **output, void *tmp);
 static int append_error_details_value(const char *name, char **output,
 		void *tmp);
-static int add_interface(const char *name, char **output,
-		void *tmp __attribute__ ((unused)));
-static int add_master_lcore(const char *name, char **output,
-		void *tmp __attribute__ ((unused)));
 
 /**
  * List of worker process type. The order of items should be same as the order
@@ -55,31 +51,6 @@ struct cmd_res_formatter_ops response_result_list[] = {
 	{ "", NULL }
 };
 
-/**
- * List of combination of tag and operator function. It is used to assemble
- * a result of command in JSON like as following.
- *
- *     {
- *         "client-id": 1,
- *         "ports": ["phy:0", "phy:1", "vhost:0", "ring:0"],
- *         "components": [
- *             {
- *                 "core": 2,
- *                 ...
- */
-struct cmd_res_formatter_ops response_info_list[] = {
-	{ "client-id", add_client_id },
-	{ "phy", add_interface },
-	{ "vhost", add_interface },
-	{ "ring", add_interface },
-	{ "master-lcore", add_master_lcore},
-	{ "core", add_core},
-#ifdef SPP_VF_MODULE
-	{ "classifier_table", add_classifier_table},
-#endif /* SPP_VF_MODULE */
-	{ "", NULL }
-};
-
 /* Append a command result in JSON format. */
 static int
 append_result_value(const char *name, char **output, void *tmp)
@@ -527,6 +498,8 @@ append_info_value(const char *name, char **output)
 {
 	int ret = SPP_RET_NG;
 	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
+	struct cmd_res_formatter_ops ops_list[NOF_STAT_OPS];
+
 	if (unlikely(tmp_buff == NULL)) {
 		RTE_LOG(ERR, WK_CMD_RES_FMT,
 				"Failed to get empty buf for append `%s`.\n",
@@ -534,8 +507,18 @@ append_info_value(const char *name, char **output)
 		return SPP_RET_NG;
 	}
 
+	memset(ops_list, 0x00,
+			sizeof(struct cmd_res_formatter_ops) * NOF_STAT_OPS);
+
+	int is_got_ops = get_status_ops(ops_list);
+	if (unlikely(is_got_ops < 0)) {
+		RTE_LOG(ERR, WK_CMD_RES_FMT,
+				"Failed to get ops_list.\n");
+		return SPP_RET_NG;
+	}
+
 	/* Setup JSON msg in value of `info` key. */
-	ret = append_response_list_value(&tmp_buff, response_info_list, NULL);
+	ret = append_response_list_value(&tmp_buff, ops_list, NULL);
 	if (unlikely(ret < SPP_RET_OK)) {
 		spp_strbuf_free(tmp_buff);
 		return SPP_RET_NG;
@@ -558,7 +541,7 @@ wk_get_client_id(void)
 }
 
 /**
- * Operator functions start with prefix `add_` defined in `response_info_list`
+ * Operation functions start with prefix `add_` defined in get_status_ops()
  * of struct `cmd_res_formatter_ops` which are for making each of parts of
  * command response.
  */
@@ -572,7 +555,7 @@ add_client_id(const char *name, char **output,
 }
 
 /* Add entry of port to a response in JSON such as "phy:0". */
-static int
+int
 add_interface(const char *name, char **output,
 		void *tmp __attribute__ ((unused)))
 {
@@ -606,7 +589,7 @@ add_interface(const char *name, char **output,
 }
 
 /* Add entry of master lcore to a response in JSON. */
-static int
+int
 add_master_lcore(const char *name, char **output,
 		void *tmp __attribute__ ((unused)))
 {
diff --git a/src/shared/secondary/spp_worker_th/cmd_res_formatter.h b/src/shared/secondary/spp_worker_th/cmd_res_formatter.h
index b1de209..d304e4f 100644
--- a/src/shared/secondary/spp_worker_th/cmd_res_formatter.h
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.h
@@ -73,4 +73,10 @@ int add_client_id(const char *name, char **output,
 
 int add_classifier_table(const char *name, char **output,
 		void *tmp __attribute__ ((unused)));
+
+int add_interface(const char *name, char **output,
+		void *tmp __attribute__ ((unused)));
+
+int add_master_lcore(const char *name, char **output,
+		void *tmp __attribute__ ((unused)));
 #endif
diff --git a/src/shared/secondary/spp_worker_th/mirror_deps.h b/src/shared/secondary/spp_worker_th/mirror_deps.h
index 43326ed..31f0b0c 100644
--- a/src/shared/secondary/spp_worker_th/mirror_deps.h
+++ b/src/shared/secondary/spp_worker_th/mirror_deps.h
@@ -7,6 +7,10 @@
 
 #include "cmd_utils.h"
 #include "cmd_parser.h"
+#include "cmd_res_formatter.h"
+
+/* Num of entries of ops_list in mir_cmd_runner.c. */
+#define NOF_STAT_OPS 7
 
 int exec_one_cmd(const struct sppwk_cmd_attrs *cmd);
 
@@ -34,4 +38,6 @@ int update_comp_info(struct sppwk_comp_info *p_comp_info, int *p_change_comp);
 
 enum sppwk_worker_type get_comp_type_from_str(const char *type_str);
 
+int get_status_ops(struct cmd_res_formatter_ops *ops_list);
+
 #endif  /* __SPP_WORKER_TH_MIRROR_DEPS_H__ */
diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h
index 72a6960..41ea1b9 100644
--- a/src/shared/secondary/spp_worker_th/vf_deps.h
+++ b/src/shared/secondary/spp_worker_th/vf_deps.h
@@ -9,10 +9,14 @@
 #include <rte_hash.h>
 #include "cmd_utils.h"
 #include "cmd_parser.h"
+#include "cmd_res_formatter.h"
 
-/** Number of VLAN ID */
+/* Number of VLAN ID */
 #define NOF_VLAN 4096
 
+/* Num of entries of ops_list in vf_cmd_runner.c. */
+#define NOF_STAT_OPS 8
+
 /* Classifier for MAC addresses. */
 struct mac_classifier {
 	struct rte_hash *cls_tbl;  /* Hash table for MAC classification. */
@@ -111,4 +115,6 @@ int add_classifier_table(const char *name, char **output,
 
 enum sppwk_worker_type get_comp_type_from_str(const char *type_str);
 
+int get_status_ops(struct cmd_res_formatter_ops *ops_list);
+
 #endif  /* _SPPWK_TH_VF_DEPS_H_ */
diff --git a/src/vf/vf_cmd_runner.c b/src/vf/vf_cmd_runner.c
index 4c75b7e..46d54b4 100644
--- a/src/vf/vf_cmd_runner.c
+++ b/src/vf/vf_cmd_runner.c
@@ -624,3 +624,38 @@ get_comp_type_from_str(const char *type_str)
 
 	return SPPWK_TYPE_NONE;
 }
+
+/**
+ * List of combination of tag and operator function. It is used to assemble
+ * a result of command in JSON like as following.
+ *
+ *     {
+ *         "client-id": 1,
+ *         "ports": ["phy:0", "phy:1", "vhost:0", "ring:0"],
+ *         "components": [
+ *             {
+ *                 "core": 2,
+ *                 ...
+ */
+/* TODO(yasufum) consider to create and move to vf_cmd_formatter.c */
+int get_status_ops(struct cmd_res_formatter_ops *ops_list)
+{
+	/* Num of entries should be the same as NOF_STAT_OPS in vf_deps.h. */
+	struct cmd_res_formatter_ops tmp_ops_list[] = {
+		{ "client-id", add_client_id },
+		{ "phy", add_interface },
+		{ "vhost", add_interface },
+		{ "ring", add_interface },
+		{ "master-lcore", add_master_lcore},
+		{ "core", add_core},
+		{ "classifier_table", add_classifier_table},
+		{ "", NULL }
+	};
+	memcpy(ops_list, tmp_ops_list, sizeof(tmp_ops_list));
+	if (unlikely(ops_list == NULL)) {
+		RTE_LOG(ERR, VF_CMD_RUNNER, "Failed to setup ops_list.\n");
+		return -1;
+	}
+
+	return 0;
+}
-- 
2.17.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24  7:11 [spp] [PATCH] shared/sec: move op funcs for getting status yasufum.o

Soft Patch Panel

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/spp/0 spp/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 spp spp/ http://inbox.dpdk.org/spp \
		spp@dpdk.org
	public-inbox-index spp


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.spp


AGPL code for this site: git clone https://public-inbox.org/ public-inbox