[spp] [PATCH 11/13] shared/sec: move rest of ops in response_info_list

yasufum.o at gmail.com yasufum.o at gmail.com
Mon Jun 24 06:36:11 CEST 2019


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

This update is to move the rest of operation functions for making
command response which is defined in `cmd_runner.c` to
`cmd_res_formatter.c`.

Signed-off-by: Yasufumi Ogawa <yasufum.o at gmail.com>
---
 .../spp_worker_th/cmd_res_formatter.c         | 106 +++++++++++++++++
 .../spp_worker_th/cmd_res_formatter.h         |   4 +
 .../secondary/spp_worker_th/cmd_runner.c      | 108 ------------------
 3 files changed, 110 insertions(+), 108 deletions(-)

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 3476580..ab08fcd 100644
--- a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
@@ -52,6 +52,31 @@ struct cmd_response 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_response 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 for JSON format */
 int
 append_result_value(const char *name, char **output, void *tmp)
@@ -535,6 +560,32 @@ append_command_results_value(const char *name, char **output,
 	return ret;
 }
 
+/* append a list of status information for JSON format. */
+int
+append_info_value(const char *name, char **output)
+{
+	int ret = SPP_RET_NG;
+	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
+	if (unlikely(tmp_buff == NULL)) {
+		RTE_LOG(ERR, WK_CMD_RES_FMT,
+				/* TODO(yasufum) refactor no meaning err msg */
+				"allocate error. (name = %s)\n",
+				name);
+		return SPP_RET_NG;
+	}
+
+	ret = append_response_list_value(&tmp_buff,
+			response_info_list, NULL);
+	if (unlikely(ret < SPP_RET_OK)) {
+		spp_strbuf_free(tmp_buff);
+		return SPP_RET_NG;
+	}
+
+	ret = append_json_block_brackets(output, name, tmp_buff);
+	spp_strbuf_free(tmp_buff);
+	return ret;
+}
+
 /* Iterate core information to create response to status command */
 static int
 spp_iterate_core_info(struct spp_iterate_core_params *params)
@@ -694,3 +745,58 @@ add_core(const char *name, char **output,
 	return ret;
 }
 
+#ifdef SPP_VF_MODULE
+/* Iterate classifier_table to create response to status command */
+static int
+_add_classifier_table(
+		struct spp_iterate_classifier_table_params *params)
+{
+	int ret;
+
+	ret = add_classifier_table_val(params);
+	if (unlikely(ret != 0)) {
+		RTE_LOG(ERR, WK_CMD_RES_FMT,
+				"Cannot iterate classifier_mac_table.\n");
+		return SPP_RET_NG;
+	}
+
+	return SPP_RET_OK;
+}
+
+/**
+ * Add entries of classifier table in JSON. Before iterating the entries,
+ * this function calls several nested functions.
+ *   add_classifier_table()  // This function.
+ *     -> _add_classifier_table()  // Wrapper and doesn't almost nothing.
+ *       -> add_classifier_table_val()  // Setup data and call iterator.
+ *         -> iterate_adding_mac_entry()
+ */
+int
+add_classifier_table(const char *name, char **output,
+		void *tmp __attribute__ ((unused)))
+{
+	int ret = SPP_RET_NG;
+	struct spp_iterate_classifier_table_params itr_params;
+	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
+	if (unlikely(tmp_buff == NULL)) {
+		RTE_LOG(ERR, WK_CMD_RES_FMT,
+				/* TODO(yasufum) refactor no meaning err msg */
+				"allocate error. (name = %s)\n",
+				name);
+		return SPP_RET_NG;
+	}
+
+	itr_params.output = tmp_buff;
+	itr_params.element_proc = append_classifier_element_value;
+
+	ret = _add_classifier_table(&itr_params);
+	if (unlikely(ret != SPP_RET_OK)) {
+		spp_strbuf_free(itr_params.output);
+		return SPP_RET_NG;
+	}
+
+	ret = append_json_array_brackets(output, name, itr_params.output);
+	spp_strbuf_free(itr_params.output);
+	return ret;
+}
+#endif /* SPP_VF_MODULE */
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 bc0109c..d9481e3 100644
--- a/src/shared/secondary/spp_worker_th/cmd_res_formatter.h
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.h
@@ -72,6 +72,8 @@ int append_response_list_value(char **output, struct cmd_response *responses,
 int append_command_results_value(const char *name, char **output,
 		int num, struct cmd_result *results);
 
+int append_info_value(const char *name, char **output);
+
 /**
  * Operator functions start with prefix `add_` defined in `response_info_list`
  * of struct `cmd_response` which are for making each of parts of command
@@ -89,4 +91,6 @@ int add_master_lcore(const char *name, char **output,
 int add_core(const char *name, char **output,
 		void *tmp __attribute__ ((unused)));
 
+int add_classifier_table(const char *name, char **output,
+		void *tmp __attribute__ ((unused)));
 #endif
diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c
index 007d62e..7c4c91c 100644
--- a/src/shared/secondary/spp_worker_th/cmd_runner.c
+++ b/src/shared/secondary/spp_worker_th/cmd_runner.c
@@ -408,24 +408,6 @@ flush_cmd(void)
 	return ret;
 }
 
-/* Iterate classifier_table to create response to status command */
-#ifdef SPP_VF_MODULE
-static int
-_add_classifier_table(
-		struct spp_iterate_classifier_table_params *params)
-{
-	int ret;
-
-	ret = add_classifier_table_val(params);
-	if (unlikely(ret != 0)) {
-		RTE_LOG(ERR, WK_CMD_RUNNER, "Cannot iterate classifier_mac_table.\n");
-		return SPP_RET_NG;
-	}
-
-	return SPP_RET_OK;
-}
-#endif /* SPP_VF_MODULE */
-
 /* Execute one command. */
 static int
 exec_one_cmd(const struct sppwk_cmd_attrs *cmd)
@@ -572,96 +554,6 @@ prepare_parse_err_msg(struct cmd_result *results,
 	}
 }
 
-#ifdef SPP_VF_MODULE
-/**
- * Add entries of classifier table in JSON. Before iterating the entries,
- * this function calls several nested functions.
- *   add_classifier_table()  // This function.
- *     -> _add_classifier_table()  // Wrapper and doesn't almost nothing.
- *       -> add_classifier_table_val()  // Setup data and call iterator.
- *         -> iterate_adding_mac_entry()
- */
-static int
-add_classifier_table(const char *name, char **output,
-		void *tmp __attribute__ ((unused)))
-{
-	int ret = SPP_RET_NG;
-	struct spp_iterate_classifier_table_params itr_params;
-	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
-	if (unlikely(tmp_buff == NULL)) {
-		RTE_LOG(ERR, WK_CMD_RUNNER,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = %s)\n",
-				name);
-		return SPP_RET_NG;
-	}
-
-	itr_params.output = tmp_buff;
-	itr_params.element_proc = append_classifier_element_value;
-
-	ret = _add_classifier_table(&itr_params);
-	if (unlikely(ret != SPP_RET_OK)) {
-		spp_strbuf_free(itr_params.output);
-		return SPP_RET_NG;
-	}
-
-	ret = append_json_array_brackets(output, name, itr_params.output);
-	spp_strbuf_free(itr_params.output);
-	return ret;
-}
-#endif /* SPP_VF_MODULE */
-
-/**
- * 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_response 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 list of status information for JSON format. */
-static int
-append_info_value(const char *name, char **output)
-{
-	int ret = SPP_RET_NG;
-	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
-	if (unlikely(tmp_buff == NULL)) {
-		RTE_LOG(ERR, WK_CMD_RUNNER,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = %s)\n",
-				name);
-		return SPP_RET_NG;
-	}
-
-	ret = append_response_list_value(&tmp_buff,
-			response_info_list, NULL);
-	if (unlikely(ret < SPP_RET_OK)) {
-		spp_strbuf_free(tmp_buff);
-		return SPP_RET_NG;
-	}
-
-	ret = append_json_block_brackets(output, name, tmp_buff);
-	spp_strbuf_free(tmp_buff);
-	return ret;
-}
-
 /* send response for decode error */
 static void
 send_decode_error_response(int *sock,
-- 
2.17.1



More information about the spp mailing list