[spp] [PATCH 10/13] shared/sec: move ope cli-id in response_info_list
yasufum.o at gmail.com
yasufum.o at gmail.com
Mon Jun 24 06:36:10 CEST 2019
From: Yasufumi Ogawa <yasufum.o at gmail.com>
This update is to move operation functions `add_client_id` and
`add_interface` 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 | 57 +++++++++++++++++++
.../spp_worker_th/cmd_res_formatter.h | 11 ++++
.../secondary/spp_worker_th/cmd_runner.c | 52 -----------------
3 files changed, 68 insertions(+), 52 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 d838a18..3476580 100644
--- a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
@@ -597,6 +597,63 @@ spp_iterate_core_info(struct spp_iterate_core_params *params)
return SPP_RET_OK;
}
+/* TODO(yasufum) move to another file for util funcs. */
+/* Get client ID from global command params. */
+static int
+wk_get_client_id(void)
+{
+ struct startup_param *params;
+ sppwk_get_mng_data(¶ms, NULL, NULL, NULL, NULL, NULL, NULL);
+ return params->client_id;
+}
+
+/**
+ * Operator functions start with prefix `add_` defined in `response_info_list`
+ * of struct `cmd_response` which are for making each of parts of command
+ * response.
+ */
+/* Add entry of client ID to a response in JSON. */
+int
+add_client_id(const char *name, char **output,
+ void *tmp __attribute__ ((unused)))
+{
+ return append_json_int_value(output, name, wk_get_client_id());
+}
+
+/* Add entry of port to a response in JSON such as "phy:0". */
+int
+add_interface(const char *name, char **output,
+ void *tmp __attribute__ ((unused)))
+{
+ 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;
+ }
+
+ if (strcmp(name, SPP_IFTYPE_NIC_STR) == 0)
+ ret = append_interface_array(&tmp_buff, PHY);
+
+ else if (strcmp(name, SPP_IFTYPE_VHOST_STR) == 0)
+ ret = append_interface_array(&tmp_buff, VHOST);
+
+ else if (strcmp(name, SPP_IFTYPE_RING_STR) == 0)
+ ret = append_interface_array(&tmp_buff, RING);
+
+ if (unlikely(ret < SPP_RET_OK)) {
+ spp_strbuf_free(tmp_buff);
+ return SPP_RET_NG;
+ }
+
+ ret = append_json_array_brackets(output, name, tmp_buff);
+ spp_strbuf_free(tmp_buff);
+ return ret;
+}
+
/* Add entry of master lcore to a response in JSON. */
int
add_master_lcore(const char *name, char **output,
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 9c77763..bc0109c 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,17 @@ 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);
+/**
+ * Operator functions start with prefix `add_` defined in `response_info_list`
+ * of struct `cmd_response` which are for making each of parts of command
+ * response.
+ */
+int add_client_id(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)));
diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c
index a6894fc..007d62e 100644
--- a/src/shared/secondary/spp_worker_th/cmd_runner.c
+++ b/src/shared/secondary/spp_worker_th/cmd_runner.c
@@ -29,16 +29,6 @@ enum cmd_res_code {
CMD_INVALID,
};
-/* TODO(yasufum) move to another file for util funcs. */
-/* Get client ID from global command params. */
-static int
-sppwk_get_client_id(void)
-{
- struct startup_param *params;
- sppwk_get_mng_data(¶ms, NULL, NULL, NULL, NULL, NULL, NULL);
- return params->client_id;
-}
-
/* Update classifier table with given action, add or del. */
static int
update_cls_table(enum sppwk_action wk_action,
@@ -582,48 +572,6 @@ prepare_parse_err_msg(struct cmd_result *results,
}
}
-/* Add entry of client ID to a response in JSON. */
-static int
-add_client_id(const char *name, char **output,
- void *tmp __attribute__ ((unused)))
-{
- return append_json_int_value(output, name, sppwk_get_client_id());
-}
-
-/* Add entry of port to a response in JSON such as "phy:0". */
-static int
-add_interface(const char *name, char **output,
- void *tmp __attribute__ ((unused)))
-{
- 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;
- }
-
- if (strcmp(name, SPP_IFTYPE_NIC_STR) == 0)
- ret = append_interface_array(&tmp_buff, PHY);
-
- else if (strcmp(name, SPP_IFTYPE_VHOST_STR) == 0)
- ret = append_interface_array(&tmp_buff, VHOST);
-
- else if (strcmp(name, SPP_IFTYPE_RING_STR) == 0)
- ret = append_interface_array(&tmp_buff, RING);
-
- if (unlikely(ret < SPP_RET_OK)) {
- spp_strbuf_free(tmp_buff);
- return SPP_RET_NG;
- }
-
- ret = append_json_array_brackets(output, name, tmp_buff);
- spp_strbuf_free(tmp_buff);
- return ret;
-}
-
#ifdef SPP_VF_MODULE
/**
* Add entries of classifier table in JSON. Before iterating the entries,
--
2.17.1
More information about the spp
mailing list