Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 01/17] shared/sec: change prefix of common functions
Date: Wed,  8 May 2019 11:01:19 +0900	[thread overview]
Message-ID: <1557280895-7978-2-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1557280895-7978-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

Some of common functions are prefixed with `spp_`, but not common
especially for spp_vf siblings. From this patch, change the prefix to
`sppwk_` to be more specific. The meaning of `sppwk` is “SPP worker
(thread)”.

This patch is to refactor struct `spp_command_decode_error` to
`sppwk_parse_err_msg`. It also include refactor of func names, such as
from `set_decode_error()` to `set_parse_error()` for formatting error
message object because it does not decode actually.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 .../secondary/spp_worker_th/command_dec.c     | 36 +++++++++----------
 .../secondary/spp_worker_th/command_dec.h     |  6 ++--
 .../secondary/spp_worker_th/command_proc.c    | 28 +++++++--------
 3 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c
index 9523ab9..236cabf 100644
--- a/src/shared/secondary/spp_worker_th/command_dec.c
+++ b/src/shared/secondary/spp_worker_th/command_dec.c
@@ -201,26 +201,26 @@ spp_convert_component_type(const char *type_str)
 	return SPP_COMPONENT_UNUSE;
 }
 
-/* set decode error */
+/* Format error message object and return error code for an error case */
 static inline int
-set_decode_error(struct spp_command_decode_error *error,
-		const int error_code, const char *error_name)
+set_parse_error(struct sppwk_parse_err_msg *err_msg,
+		const int err_code, const char *err_name)
 {
-	error->code = error_code;
+	err_msg->code = err_code;
 
-	if (likely(error_name != NULL))
-		strcpy(error->value_name, error_name);
+	if (likely(err_name != NULL))
+		strcpy(err_msg->value_name, err_name);
 
-	return error->code;
+	return err_msg->code;
 }
 
 /* set decode error */
 static inline int
-set_string_value_decode_error(struct spp_command_decode_error *error,
+set_string_value_decode_error(struct sppwk_parse_err_msg *error,
 		const char *value, const char *error_name)
 {
 	strcpy(error->value, value);
-	return set_decode_error(error, SPP_CMD_DERR_BAD_VALUE, error_name);
+	return set_parse_error(error, SPP_CMD_DERR_BAD_VALUE, error_name);
 }
 
 /* Split command line parameter with spaces */
@@ -898,7 +898,7 @@ parameter_list[][SPP_CMD_MAX_PARAMETERS] = {
 static int
 decode_command_parameter_component(struct spp_command_request *request,
 				int argc, char *argv[],
-				struct spp_command_decode_error *error,
+				struct sppwk_parse_err_msg *error,
 				int maxargc __attribute__ ((unused)))
 {
 	int ret = SPP_RET_OK;
@@ -926,7 +926,7 @@ decode_command_parameter_component(struct spp_command_request *request,
 static int
 decode_command_parameter_cls_table(struct spp_command_request *request,
 				int argc, char *argv[],
-				struct spp_command_decode_error *error,
+				struct sppwk_parse_err_msg *error,
 				int maxargc)
 {
 	return decode_command_parameter_component(request,
@@ -939,7 +939,7 @@ decode_command_parameter_cls_table(struct spp_command_request *request,
 static int
 decode_command_parameter_cls_table_vlan(struct spp_command_request *request,
 				int argc, char *argv[],
-				struct spp_command_decode_error *error,
+				struct sppwk_parse_err_msg *error,
 				int maxargc __attribute__ ((unused)))
 {
 	int ret = SPP_RET_OK;
@@ -966,7 +966,7 @@ decode_command_parameter_cls_table_vlan(struct spp_command_request *request,
 static int
 decode_command_parameter_port(struct spp_command_request *request,
 				int argc, char *argv[],
-				struct spp_command_decode_error *error,
+				struct sppwk_parse_err_msg *error,
 				int maxargc)
 {
 	int ret = SPP_RET_OK;
@@ -1001,7 +1001,7 @@ struct decode_command_list {
 	int   param_min;        /* Min number of parameters */
 	int   param_max;        /* Max number of parameters */
 	int (*func)(struct spp_command_request *request, int argc,
-			char *argv[], struct spp_command_decode_error *error,
+			char *argv[], struct sppwk_parse_err_msg *error,
 			int maxargc);
 				/* Pointer to command handling function */
 };
@@ -1028,7 +1028,7 @@ static struct decode_command_list command_list[] = {
 static int
 decode_command_in_list(struct spp_command_request *request,
 			const char *request_str,
-			struct spp_command_decode_error *error)
+			struct sppwk_parse_err_msg *error)
 {
 	int ret = SPP_RET_OK;
 	int command_name_check = 0;
@@ -1046,7 +1046,7 @@ decode_command_in_list(struct spp_command_request *request,
 	if (ret < SPP_RET_OK) {
 		RTE_LOG(ERR, SPP_COMMAND_PROC, "Parameter number over limit."
 				"request_str=%s\n", request_str);
-		return set_decode_error(error, SPP_CMD_DERR_BAD_FORMAT, NULL);
+		return set_parse_error(error, SPP_CMD_DERR_BAD_FORMAT, NULL);
 	}
 	RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Decode array. num=%d\n", argc);
 
@@ -1072,7 +1072,7 @@ decode_command_in_list(struct spp_command_request *request,
 	if (command_name_check != 0) {
 		RTE_LOG(ERR, SPP_COMMAND_PROC, "Parameter number out of range."
 				"request_str=%s\n", request_str);
-		return set_decode_error(error, SPP_CMD_DERR_BAD_FORMAT, NULL);
+		return set_parse_error(error, SPP_CMD_DERR_BAD_FORMAT, NULL);
 	}
 
 	RTE_LOG(ERR, SPP_COMMAND_PROC,
@@ -1086,7 +1086,7 @@ int
 spp_command_decode_request(
 		struct spp_command_request *request,
 		const char *request_str, size_t request_str_len,
-		struct spp_command_decode_error *error)
+		struct sppwk_parse_err_msg *error)
 {
 	int ret = SPP_RET_NG;
 	int i;
diff --git a/src/shared/secondary/spp_worker_th/command_dec.h b/src/shared/secondary/spp_worker_th/command_dec.h
index 93b4ebe..da94cf3 100644
--- a/src/shared/secondary/spp_worker_th/command_dec.h
+++ b/src/shared/secondary/spp_worker_th/command_dec.h
@@ -171,7 +171,7 @@ struct spp_command_request {
 };
 
 /** decode error information */
-struct spp_command_decode_error {
+struct sppwk_parse_err_msg {
 	int code;                            /**< Error code */
 	char value_name[SPP_CMD_NAME_BUFSZ]; /**< Error value name */
 	char value[SPP_CMD_VALUE_BUFSZ];     /**< Error value */
@@ -188,7 +188,7 @@ struct spp_command_decode_error {
  * @param request_str_len
  *  The length of requested command message.
  * @param error
- *  The pointer to struct spp_command_decode_error.@n
+ *  The pointer to struct sppwk_parse_err_msg.@n
  *  Detailed error information will be stored.
  *
  * @retval SPP_RET_OK succeeded.
@@ -196,6 +196,6 @@ struct spp_command_decode_error {
  */
 int spp_command_decode_request(struct spp_command_request *request,
 		const char *request_str, size_t request_str_len,
-		struct spp_command_decode_error *error);
+		struct sppwk_parse_err_msg *err_msg);
 
 #endif /* _COMMAND_DEC_H_ */
diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c
index 1e16bd0..40b3121 100644
--- a/src/shared/secondary/spp_worker_th/command_proc.c
+++ b/src/shared/secondary/spp_worker_th/command_proc.c
@@ -805,30 +805,30 @@ execute_command(const struct spp_command *command)
 /* make decode error message for response */
 static const char *
 make_decode_error_message(
-		const struct spp_command_decode_error *decode_error,
+		const struct sppwk_parse_err_msg *err_msg,
 		char *message)
 {
-	switch (decode_error->code) {
+	switch (err_msg->code) {
 	case SPP_CMD_DERR_BAD_FORMAT:
 		sprintf(message, "bad message format");
 		break;
 
 	case SPP_CMD_DERR_UNKNOWN_COMMAND:
-		sprintf(message, "unknown command(%s)", decode_error->value);
+		sprintf(message, "unknown command(%s)", err_msg->value);
 		break;
 
 	case SPP_CMD_DERR_NO_PARAM:
 		sprintf(message, "not enough parameter(%s)",
-				decode_error->value_name);
+				err_msg->value_name);
 		break;
 
 	case SPP_CMD_DERR_BAD_TYPE:
 		sprintf(message, "bad value type(%s)",
-				decode_error->value_name);
+				err_msg->value_name);
 		break;
 
 	case SPP_CMD_DERR_BAD_VALUE:
-		sprintf(message, "bad value(%s)", decode_error->value_name);
+		sprintf(message, "bad value(%s)", err_msg->value_name);
 		break;
 
 	default:
@@ -866,21 +866,21 @@ set_command_results(struct command_result *result,
 static void
 set_decode_error_to_results(struct command_result *results,
 		const struct spp_command_request *request,
-		const struct spp_command_decode_error *decode_error)
+		const struct sppwk_parse_err_msg *err_msg)
 {
 	int i;
 	const char *tmp_buff;
 	char error_messege[CMD_RES_ERR_MSG_SIZE];
 
 	for (i = 0; i < request->num_command; i++) {
-		if (decode_error->code == 0)
+		if (err_msg->code == 0)
 			set_command_results(&results[i], CRES_SUCCESS, "");
 		else
 			set_command_results(&results[i], CRES_INVALID, "");
 	}
 
-	if (decode_error->code != 0) {
-		tmp_buff = make_decode_error_message(decode_error,
+	if (err_msg->code != 0) {
+		tmp_buff = make_decode_error_message(err_msg,
 				error_messege);
 		set_command_results(&results[request->num_valid_command],
 				CRES_FAILURE, tmp_buff);
@@ -1646,11 +1646,11 @@ process_request(int *sock, const char *request_str, size_t request_str_len)
 	int i;
 
 	struct spp_command_request request;
-	struct spp_command_decode_error decode_error;
+	struct sppwk_parse_err_msg wk_err_msg;
 	struct command_result command_results[SPP_CMD_MAX_COMMANDS];
 
 	memset(&request, 0, sizeof(struct spp_command_request));
-	memset(&decode_error, 0, sizeof(struct spp_command_decode_error));
+	memset(&wk_err_msg, 0, sizeof(struct sppwk_parse_err_msg));
 	memset(command_results, 0, sizeof(command_results));
 
 	RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Start command request processing. "
@@ -1659,11 +1659,11 @@ process_request(int *sock, const char *request_str, size_t request_str_len)
 
 	/* decode request message */
 	ret = spp_command_decode_request(
-			&request, request_str, request_str_len, &decode_error);
+			&request, request_str, request_str_len, &wk_err_msg);
 	if (unlikely(ret != SPP_RET_OK)) {
 		/* send error response */
 		set_decode_error_to_results(command_results, &request,
-				&decode_error);
+				&wk_err_msg);
 		send_decode_error_response(sock, &request, command_results);
 		RTE_LOG(DEBUG, SPP_COMMAND_PROC,
 				"End command request processing.\n");
-- 
2.17.1


  reply	other threads:[~2019-05-08  2:03 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-08  2:01 [spp] [PATCH 00/17] Refactor command parser of SPP worker ogawa.yasufumi
2019-05-08  2:01 ` ogawa.yasufumi [this message]
2019-05-08  2:01 ` [spp] [PATCH 02/17] shared/sec: refactor parse error code ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 03/17] shared/sec: revice cmd parser of SPP worker ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 04/17] shared/sec: refactor branching for cmd action ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 05/17] shared/sec: rename define starts from SPP_CMD_MAX ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 06/17] shared/sec: rename define of buffer size for cmds ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 07/17] shared/sec: remove unused define of cmd parser ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 08/17] shared/sec: refactor commad type of SPP worker ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 09/17] shared/sec: change struct of classier table attrs ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 10/17] shared/sec: refactor function parsing cls port ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 11/17] shared/sec: rename func of flush command ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 12/17] shared/sec: change struct of comp command ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 13/17] shared/sec: revise port info of SPP worker ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 14/17] shared/sec: rename func for getting port ID ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 15/17] shared/sec: rename dpdk_port attr ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 16/17] shared/sec: rename struct for command request ogawa.yasufumi
2019-05-08  2:01 ` [spp] [PATCH 17/17] shared/sec: rename func for parsing request ogawa.yasufumi

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=1557280895-7978-2-git-send-email-ogawa.yasufumi@lab.ntt.co.jp \
    --to=ogawa.yasufumi@lab.ntt.co.jp \
    --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).