代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/gazelle 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From dbf196207b57ec4a5184dd04f06b588bd36f8d9a Mon Sep 17 00:00:00 2001
From: jiangheng12 <jiangheng14@huawei.com>
Date: Sat, 25 Feb 2023 20:05:12 +0800
Subject: [PATCH] reduce duplicate code in lstack_cfg.c
---
src/lstack/core/lstack_cfg.c | 211 +++++++----------------------------
1 file changed, 38 insertions(+), 173 deletions(-)
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
index 0c4b55b..e1ea38d 100644
--- a/src/lstack/core/lstack_cfg.c
+++ b/src/lstack/core/lstack_cfg.c
@@ -65,6 +65,25 @@ static int32_t parse_nic_read_number(void);
static int32_t parse_tcp_conn_count(void);
static int32_t parse_mbuf_count_per_conn(void);
+static inline int32_t parse_int(void *arg, char * arg_string, int32_t default_val,
+ int32_t min_val, int32_t max_val)
+{
+ const config_setting_t *config_arg = NULL;
+ config_arg = config_lookup(&g_config, arg_string);
+ if (config_arg == NULL) {
+ *(int32_t *)arg = default_val;
+ return 0;
+ }
+ int32_t val = config_setting_get_int(config_arg);
+ if (val < min_val || val > max_val) {
+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg %s %d invaild, range is [%d, %d].\n",
+ arg_string, val, min_val, max_val);
+ return -EINVAL;
+ }
+ *(int32_t *)arg = val;
+ return 0;
+}
+
struct config_vector_t {
const char *name;
int32_t (*f)(void);
@@ -642,21 +661,12 @@ free_dpdk_args:
static int32_t parse_low_power_mode(void)
{
- const config_setting_t *setting = NULL;
-
/* Set parameter default value */
g_config_params.lpm_detect_ms = LSTACK_LPM_DETECT_MS;
g_config_params.lpm_rx_pkts = LSTACK_LPM_RX_PKTS;
g_config_params.lpm_pkts_in_detect = LSTACK_LPM_PKTS_IN_DETECT;
- setting = config_lookup(&g_config, "low_power_mode");
- if (setting == NULL) {
- g_config_params.low_power_mod = 0;
- return 0;
- }
- g_config_params.low_power_mod = (uint16_t)config_setting_get_int(setting);
-
- return 0;
+ return parse_int(&g_config_params.low_power_mod, "low_power_mode", 0, 0, 1);
}
static int32_t parse_wakeup_cpu_number(void)
@@ -695,211 +705,66 @@ static int32_t parse_wakeup_cpu_number(void)
static int32_t parse_use_ltran(void)
{
- const config_setting_t *arg = NULL;
-
- arg = config_lookup(&g_config, "use_ltran");
- if (arg == NULL) {
- g_config_params.use_ltran = true;
- return 0;
- }
-
- int32_t val = config_setting_get_int(arg);
- g_config_params.use_ltran = (val == 0) ? false : true;
-
- return 0;
+ return parse_int(&g_config_params.use_ltran, "use_ltran", 1, 0, 1);
}
static int32_t parse_tcp_conn_count(void)
{
- const config_setting_t *arg = NULL;
-
- arg = config_lookup(&g_config, "tcp_conn_count");
- if (arg == NULL) {
- g_config_params.tcp_conn_count = TCP_CONN_COUNT;
- return 0;
- }
-
- int32_t val = config_setting_get_int(arg);
- if (val <= 0 || val > TCP_CONN_COUNT) {
- LSTACK_PRE_LOG(LSTACK_ERR, "cfg tcp_conn_count %d invaild, it should be in (0,%d].\n", val, TCP_CONN_COUNT);
- return -EINVAL;
- }
-
- g_config_params.tcp_conn_count = val;
-
- return 0;
+ return parse_int(&g_config_params.tcp_conn_count, "tcp_conn_count", TCP_CONN_COUNT, 1, TCP_CONN_COUNT);
}
static int32_t parse_mbuf_count_per_conn(void)
{
- const config_setting_t *arg = NULL;
-
- arg = config_lookup(&g_config, "mbuf_count_per_conn");
- if (arg == NULL) {
- g_config_params.tcp_conn_count = MBUF_COUNT_PER_CONN;
- return 0;
- }
-
- int32_t val = config_setting_get_int(arg);
- if (val <= 0) {
- LSTACK_PRE_LOG(LSTACK_ERR, "cfg mbuf_count_per_conn %d invaild, it should be > 0.\n", val);
- return -EINVAL;
- }
-
- g_config_params.mbuf_count_per_conn = val;
-
- return 0;
+ return parse_int(&g_config_params.mbuf_count_per_conn, "mbuf_count_per_conn",
+ MBUF_COUNT_PER_CONN, 1, INT32_MAX);
}
static int32_t parse_send_connect_number(void)
{
- const config_setting_t *arg = NULL;
-
- arg = config_lookup(&g_config, "send_connect_number");
- if (arg == NULL) {
- g_config_params.send_connect_number = STACK_THREAD_DEFAULT;
- LSTACK_PRE_LOG(LSTACK_ERR, "use default send_connect_number %d.\n", STACK_THREAD_DEFAULT);
- return 0;
- }
-
- int32_t val = config_setting_get_int(arg);
- if (val <= 0) {
- LSTACK_PRE_LOG(LSTACK_ERR, "cfg send_connect_number %d invaild.\n", val);
- return -EINVAL;
- }
-
- g_config_params.send_connect_number = val;
-
- return 0;
+ return parse_int(&g_config_params.send_connect_number, "send_connect_number",
+ STACK_THREAD_DEFAULT, 1, INT32_MAX);
}
static int32_t parse_read_connect_number(void)
{
- const config_setting_t *arg = NULL;
-
- arg = config_lookup(&g_config, "read_connect_number");
- if (arg == NULL) {
- g_config_params.read_connect_number = STACK_THREAD_DEFAULT;
- LSTACK_PRE_LOG(LSTACK_ERR, "use default read_connect_number %d.\n", STACK_THREAD_DEFAULT);
- return 0;
- }
-
- int32_t val = config_setting_get_int(arg);
- if (val <= 0) {
- LSTACK_PRE_LOG(LSTACK_ERR, "cfg read_connect_number %d invaild.\n", val);
- return -EINVAL;
- }
-
- g_config_params.read_connect_number = val;
-
- return 0;
+ return parse_int(&g_config_params.read_connect_number, "read_connect_number",
+ STACK_THREAD_DEFAULT, 1, INT32_MAX);
}
static int32_t parse_rpc_number(void)
{
- const config_setting_t *arg = NULL;
-
- arg = config_lookup(&g_config, "rpc_number");
- if (arg == NULL) {
- g_config_params.rpc_number = STACK_THREAD_DEFAULT;
- LSTACK_PRE_LOG(LSTACK_ERR, "use default rpc_number %d.\n", STACK_THREAD_DEFAULT);
- return 0;
- }
-
- int32_t val = config_setting_get_int(arg);
- if (val <= 0) {
- LSTACK_PRE_LOG(LSTACK_ERR, "cfg rpc_number %d invaild.\n", val);
- return -EINVAL;
- }
-
- g_config_params.rpc_number = val;
-
- return 0;
+ return parse_int(&g_config_params.rpc_number, "rpc_number",
+ STACK_THREAD_DEFAULT, 1, INT32_MAX);
}
static int32_t parse_nic_read_number(void)
{
- const config_setting_t *arg = NULL;
-
- arg = config_lookup(&g_config, "nic_read_number");
- if (arg == NULL) {
- g_config_params.nic_read_number = STACK_NIC_READ_DEFAULT;
- LSTACK_PRE_LOG(LSTACK_ERR, "use default nic_read_number %d.\n", STACK_NIC_READ_DEFAULT);
- return 0;
- }
-
- int32_t val = config_setting_get_int(arg);
- if (val <= 0) {
- LSTACK_PRE_LOG(LSTACK_ERR, "cfg nic_read_number %d invaild.\n", val);
- return -EINVAL;
- }
-
- g_config_params.nic_read_number = val;
-
- return 0;
+ return parse_int(&g_config_params.nic_read_number, "nic_read_number",
+ STACK_NIC_READ_DEFAULT, 1, INT32_MAX);
}
static int32_t parse_listen_shadow(void)
{
- const config_setting_t *arg = NULL;
-
- arg = config_lookup(&g_config, "listen_shadow");
- if (arg == NULL) {
- g_config_params.listen_shadow = false;
- return 0;
- }
-
- int32_t val = config_setting_get_int(arg);
- g_config_params.listen_shadow = (val == 0) ? false : true;
-
- return 0;
+ return parse_int(&g_config_params.listen_shadow, "listen_shadow", 0, 0, 1);
}
+
static int32_t parse_app_bind_numa(void)
{
- const config_setting_t *arg = NULL;
-
- arg = config_lookup(&g_config, "app_bind_numa");
- if (arg == NULL) {
- g_config_params.app_bind_numa = true;
- return 0;
- }
-
- int32_t val = config_setting_get_int(arg);
- g_config_params.app_bind_numa = (val == 0) ? false : true;
-
- return 0;
+ return parse_int(&g_config_params.app_bind_numa, "app_bind_numa", 1, 0, 1);
}
static int32_t parse_main_thread_affinity(void)
{
- const config_setting_t *arg = NULL;
-
- arg = config_lookup(&g_config, "main_thread_affinity");
- if (arg == NULL) {
- g_config_params.main_thread_affinity = false;
- return 0;
- }
-
- int32_t val = config_setting_get_int(arg);
- g_config_params.main_thread_affinity = (val == 0) ? false : true;
-
- return 0;
+ return parse_int(&g_config_params.main_thread_affinity, "main_thread_affinity", 0, 0, 1);
}
static int32_t parse_kni_switch(void)
{
- const config_setting_t *arg = NULL;
-
- arg = config_lookup(&g_config, "kni_switch");
- if (arg == NULL) {
- g_config_params.kni_switch = false;
- return 0;
+ if (parse_int(&g_config_params.kni_switch, "kni_switch", 0, 0, 1) != 0) {
+ return -1;
}
- int32_t val = config_setting_get_int(arg);
- g_config_params.kni_switch = (val == 0) ? false : true;
-
if (g_config_params.use_ltran && g_config_params.kni_switch) {
LSTACK_PRE_LOG(LSTACK_ERR, "kni_switch=1 when use_ltran=1, invaild.\n");
return -1;
--
2.23.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。