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: remove client ID from global variable
Date: Mon, 24 Jun 2019 19:41:35 +0900	[thread overview]
Message-ID: <20190624104135.24816-1-yasufum.o@gmail.com> (raw)

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

Client ID of secondary process is defined as a member of global
variable `g_startup_params` is defined in shared library, but no need to
be global. This update is to remove client ID from the global var and
add functions to get and set the client ID.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/mirror/spp_mirror.c                       | 35 +++--------------
 .../spp_worker_th/cmd_res_formatter.c         | 12 +-----
 .../secondary/spp_worker_th/cmd_utils.h       |  1 -
 .../secondary/spp_worker_th/mirror_deps.h     |  2 +
 src/shared/secondary/spp_worker_th/vf_deps.h  |  2 +
 src/shared/secondary/utils.c                  | 39 +++++++++++++++++--
 src/shared/secondary/utils.h                  | 12 ++++++
 src/vf/spp_vf.c                               | 36 ++++-------------
 8 files changed, 66 insertions(+), 73 deletions(-)

diff --git a/src/mirror/spp_mirror.c b/src/mirror/spp_mirror.c
index aad74a9..19d79ef 100644
--- a/src/mirror/spp_mirror.c
+++ b/src/mirror/spp_mirror.c
@@ -101,30 +101,6 @@ usage(const char *progname)
 			, progname);
 }
 
-/**
- * Convert string of given client id to integer
- *
- * If succeeded, client id of integer is assigned to client_id and
- * return SPP_RET_OK. Or return -SPP_RET_NG if failed.
- */
-static int
-parse_app_client_id(const char *client_id_str, int *client_id)
-{
-	int id = 0;
-	char *endptr = NULL;
-
-	id = strtol(client_id_str, &endptr, 0);
-	if (unlikely(client_id_str == endptr) || unlikely(*endptr != '\0'))
-		return SPP_RET_NG;
-
-	if (id >= RTE_MAX_LCORE)
-		return SPP_RET_NG;
-
-	*client_id = id;
-	RTE_LOG(DEBUG, MIRROR, "Set client id = %d\n", *client_id);
-	return SPP_RET_OK;
-}
-
 /* Parse options for server IP and port */
 static int
 parse_app_server(const char *server_str, char *server_ip, int *server_port)
@@ -155,6 +131,7 @@ static int
 parse_app_args(int argc, char *argv[])
 {
 	int cnt;
+	int cli_id;
 	int proc_flg = 0;
 	int server_flg = 0;
 	int option_index, opt;
@@ -186,12 +163,12 @@ parse_app_args(int argc, char *argv[])
 			&option_index)) != EOF) {
 		switch (opt) {
 		case SPP_LONGOPT_RETVAL_CLIENT_ID:
-			if (parse_app_client_id(optarg,
-						&g_startup_param.client_id) !=
-						SPP_RET_OK) {
+			if (parse_client_id(&cli_id, optarg) != SPP_RET_OK) {
 				usage(progname);
 				return SPP_RET_NG;
 			}
+			set_client_id(cli_id);
+
 			proc_flg = 1;
 			break;
 		case SPP_LONGOPT_RETVAL_VHOST_CLIENT:
@@ -221,7 +198,7 @@ parse_app_args(int argc, char *argv[])
 	RTE_LOG(INFO, MIRROR,
 			"app opts (client_id=%d,type=%d,"
 			"server=%s:%d,vhost_client=%d,)\n",
-			g_startup_param.client_id,
+			cli_id,
 			g_startup_param.wk_proc_type,
 			g_startup_param.server_ip,
 			g_startup_param.server_port,
@@ -555,7 +532,7 @@ main(int argc, char *argv[])
 		}
 
 		/* create the mbuf pool */
-		ret = mirror_pool_create(g_startup_param.client_id);
+		ret = mirror_pool_create(get_client_id());
 		if (ret == SPP_RET_NG) {
 			RTE_LOG(ERR, MIRROR,
 					"mirror mnuf pool create failed.\n");
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 7d7388d..291c1f5 100644
--- a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
@@ -530,16 +530,6 @@ append_info_value(const char *name, char **output)
 	return ret;
 }
 
-/* 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(&params, NULL, NULL, NULL, NULL, NULL, NULL);
-	return params->client_id;
-}
-
 /**
  * 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
@@ -551,7 +541,7 @@ int
 add_client_id(const char *name, char **output,
 		void *tmp __attribute__ ((unused)))
 {
-	return append_json_int_value(output, name, wk_get_client_id());
+	return append_json_int_value(output, name, get_client_id());
 }
 
 /* Add entry of port to a response in JSON such as "phy:0". */
diff --git a/src/shared/secondary/spp_worker_th/cmd_utils.h b/src/shared/secondary/spp_worker_th/cmd_utils.h
index f3e2303..9022589 100644
--- a/src/shared/secondary/spp_worker_th/cmd_utils.h
+++ b/src/shared/secondary/spp_worker_th/cmd_utils.h
@@ -201,7 +201,6 @@ struct sppwk_comp_info {
 
 /* Manage cmd arg as global variable, used for spp_vf and spp_mirror. */
 struct startup_param {
-	int client_id;  /* Client ID */
 	char server_ip[INET_ADDRSTRLEN];  /* IP address of spp-ctl */
 	int server_port;   /* Port Number of spp-ctl */
 	enum sppwk_proc_type wk_proc_type;
diff --git a/src/shared/secondary/spp_worker_th/mirror_deps.h b/src/shared/secondary/spp_worker_th/mirror_deps.h
index 31f0b0c..1446027 100644
--- a/src/shared/secondary/spp_worker_th/mirror_deps.h
+++ b/src/shared/secondary/spp_worker_th/mirror_deps.h
@@ -40,4 +40,6 @@ enum sppwk_worker_type get_comp_type_from_str(const char *type_str);
 
 int get_status_ops(struct cmd_res_formatter_ops *ops_list);
 
+int get_client_id(void);
+
 #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 41ea1b9..8da81a5 100644
--- a/src/shared/secondary/spp_worker_th/vf_deps.h
+++ b/src/shared/secondary/spp_worker_th/vf_deps.h
@@ -117,4 +117,6 @@ enum sppwk_worker_type get_comp_type_from_str(const char *type_str);
 
 int get_status_ops(struct cmd_res_formatter_ops *ops_list);
 
+int get_client_id(void);
+
 #endif  /* _SPPWK_TH_VF_DEPS_H_ */
diff --git a/src/shared/secondary/utils.c b/src/shared/secondary/utils.c
index 7c676a0..73800d3 100644
--- a/src/shared/secondary/utils.c
+++ b/src/shared/secondary/utils.c
@@ -8,6 +8,42 @@
 
 #define RTE_LOGTYPE_SHARED RTE_LOGTYPE_USER1
 
+int client_id;
+
+int set_client_id(int cid)
+{
+	client_id = cid;
+	return 0;
+}
+
+int get_client_id(void)
+{
+	if (client_id < 0) {
+		RTE_LOG(ERR, SHARED, "Client ID is not initialized.\n");
+		return -1;
+	}
+	return client_id;
+}
+
+/* Parse client ID from given value of string. */
+int
+parse_client_id(int *cli_id, const char *cli_id_str)
+{
+	int id = 0;
+	char *endptr = NULL;
+
+	id = strtol(cli_id_str, &endptr, 0);
+	if (unlikely(cli_id_str == endptr) || unlikely(*endptr != '\0'))
+		return -1;
+
+	if (id >= RTE_MAX_LCORE)
+		return -1;
+
+	*cli_id = id;
+	RTE_LOG(DEBUG, SHARED, "Parse client ID %d.\n", *cli_id);
+	return 0;
+}
+
 /**
  * Retieve port type and ID from resource UID. For example, resource UID
  * 'ring:0' is  parsed to retrieve port tyep 'ring' and ID '0'.
@@ -43,14 +79,11 @@ int
 spp_atoi(const char *str, int *val)
 {
 	char *end;
-
 	*val = strtol(str, &end, 10);
-
 	if (*end) {
 		RTE_LOG(ERR, SHARED, "Bad integer value: %s\n", str);
 		return -1;
 	}
-
 	return 0;
 }
 
diff --git a/src/shared/secondary/utils.h b/src/shared/secondary/utils.h
index c905b12..74531b0 100644
--- a/src/shared/secondary/utils.h
+++ b/src/shared/secondary/utils.h
@@ -9,6 +9,18 @@ int parse_resource_uid(char *str, char **port_type, int *port_id);
 
 int spp_atoi(const char *str, int *val);
 
+int set_client_id(int cid);
+int get_client_id(void);
+
+/**
+ * Parse client ID from given value of string.
+ *
+ * @params[in] cli_id_str String value of client ID.
+ * @params[in,out] cli_id client ID of int value.
+ * @return 0 if succeeded, or -1 if failed.
+ */
+int parse_client_id(int *cli_id, const char *cli_id_str);
+
 /**
  * Attach a new Ethernet device specified by arguments.
  *
diff --git a/src/vf/spp_vf.c b/src/vf/spp_vf.c
index 4513a0c..d8b0c87 100644
--- a/src/vf/spp_vf.c
+++ b/src/vf/spp_vf.c
@@ -7,9 +7,10 @@
 #include <getopt.h>
 
 #include "spp_vf.h"
-#include "shared/secondary/spp_worker_th/cmd_utils.h"
 #include "classifier_mac.h"
 #include "forwarder.h"
+#include "shared/secondary/utils.h"
+#include "shared/secondary/spp_worker_th/cmd_utils.h"
 #include "shared/secondary/return_codes.h"
 #include "shared/secondary/add_port.h"
 #include "shared/secondary/spp_worker_th/cmd_runner.h"
@@ -56,30 +57,6 @@ usage(const char *progname)
 			, progname);
 }
 
-/**
- * Convert string of given client id to integer
- *
- * If succeeded, client id of integer is assigned to client_id and
- * return SPP_RET_OK Or return SPP_RET_NG if failed.
- */
-static int
-parse_app_client_id(const char *client_id_str, int *client_id)
-{
-	int id = 0;
-	char *endptr = NULL;
-
-	id = strtol(client_id_str, &endptr, 0);
-	if (unlikely(client_id_str == endptr) || unlikely(*endptr != '\0'))
-		return SPP_RET_NG;
-
-	if (id >= RTE_MAX_LCORE)
-		return SPP_RET_NG;
-
-	*client_id = id;
-	RTE_LOG(DEBUG, APP, "Set client id = %d\n", *client_id);
-	return SPP_RET_OK;
-}
-
 /* Parse options for server IP and port */
 static int
 parse_app_server(const char *server_str, char *server_ip, int *server_port)
@@ -111,6 +88,7 @@ static int
 parse_app_args(int argc, char *argv[])
 {
 	int cnt;
+	int cli_id;
 	int proc_flg = 0;
 	int server_flg = 0;
 	int option_index, opt;
@@ -142,12 +120,12 @@ parse_app_args(int argc, char *argv[])
 			&option_index)) != EOF) {
 		switch (opt) {
 		case SPP_LONGOPT_RETVAL_CLIENT_ID:
-			if (parse_app_client_id(optarg,
-					&g_startup_param.client_id) !=
-								SPP_RET_OK) {
+			if (parse_client_id(&cli_id, optarg) != SPP_RET_OK) {
 				usage(progname);
 				return SPP_RET_NG;
 			}
+			set_client_id(cli_id);
+
 			proc_flg = 1;
 			break;
 		case SPP_LONGOPT_RETVAL_VHOST_CLIENT:
@@ -177,7 +155,7 @@ parse_app_args(int argc, char *argv[])
 	RTE_LOG(INFO, APP,
 			"app opts (client_id=%d,type=%d,server=%s:%d,"
 			"vhost_client=%d)\n",
-			g_startup_param.client_id,
+			cli_id,
 			g_startup_param.wk_proc_type,
 			g_startup_param.server_ip,
 			g_startup_param.server_port,
-- 
2.17.1


                 reply	other threads:[~2019-06-24 10:41 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=20190624104135.24816-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).