From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 11/13] shared/sec: move rest of ops in response_info_list
Date: Mon, 24 Jun 2019 13:36:11 +0900 [thread overview]
Message-ID: <20190624043613.19271-12-yasufum.o@gmail.com> (raw)
In-Reply-To: <20190624043613.19271-1-yasufum.o@gmail.com>
From: Yasufumi Ogawa <yasufum.o@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@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
next prev parent reply other threads:[~2019-06-24 4:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-24 4:36 [spp] [PATCH 00/13] Move JSON utils from libs for running cmds yasufum.o
2019-06-24 4:36 ` [spp] [PATCH 01/13] shared/sec: rename ops for setup cmd response yasufum.o
2019-06-24 4:36 ` [spp] [PATCH 02/13] shared/sec: rename functions for spp_mirror yasufum.o
2019-06-24 4:36 ` [spp] [PATCH 03/13] shared/sec: move principle JSON formatter funcs yasufum.o
2019-06-24 4:36 ` [spp] [PATCH 04/13] shared/sec: change order of args of JSON fmtters yasufum.o
2019-06-24 4:36 ` [spp] [PATCH 05/13] shared/sec: move JSON formatter to shard/secondary yasufum.o
2019-06-24 4:36 ` [spp] [PATCH 06/13] shared/sec: revise including headers yasufum.o
2019-06-24 4:36 ` [spp] [PATCH 07/13] shared/sec: move JSON formatters from cmd_runner yasufum.o
2019-06-24 4:36 ` [spp] [PATCH 08/13] shared/sec: move rest of JSON formatters yasufum.o
2019-06-24 4:36 ` [spp] [PATCH 09/13] shared/sec: move lcore funcs in response_info_list yasufum.o
2019-06-24 4:36 ` [spp] [PATCH 10/13] shared/sec: move ope cli-id " yasufum.o
2019-06-24 4:36 ` yasufum.o [this message]
2019-06-24 4:36 ` [spp] [PATCH 12/13] shared/sec: remove local funcs from header yasufum.o
2019-06-24 4:36 ` [spp] [PATCH 13/13] shared/sec: refactor comments for JSON formatter yasufum.o
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=20190624043613.19271-12-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).