Soft Patch Panel
 help / color / Atom feed
* [spp] [PATCH] shared/sec: remove client ID from global variable
@ 2019-06-24 10:41 yasufum.o
  0 siblings, 0 replies; only message in thread
From: yasufum.o @ 2019-06-24 10:41 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24 10:41 [spp] [PATCH] shared/sec: remove client ID from global variable yasufum.o

Soft Patch Panel

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/spp/0 spp/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 spp spp/ http://inbox.dpdk.org/spp \
		spp@dpdk.org
	public-inbox-index spp


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.spp


AGPL code for this site: git clone https://public-inbox.org/ public-inbox