Soft Patch Panel
 help / color / mirror / Atom feed
From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH] shared/sec: move op funcs for getting status
Date: Mon, 24 Jun 2019 16:11:07 +0900	[thread overview]
Message-ID: <20190624071107.23398-1-yasufum.o@gmail.com> (raw)

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


                 reply	other threads:[~2019-06-24  7:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190624071107.23398-1-yasufum.o@gmail.com \
    --to=yasufum.o@gmail.com \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).