summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQiuwen Lu <[email protected]>2017-04-20 14:57:53 +0800
committerQiuwen Lu <[email protected]>2017-04-20 14:57:53 +0800
commite6cbcd0d7a1cc2951f25992a952dae3d2b06ce22 (patch)
treebbe378fe2e4a83c37d4f15b1869295ab061eef9a
parenteaf1c0edac5025cf3a6b7f297665774d9e1edc4c (diff)
增加服务进程退出时关闭物理网卡的功能;APP侧:增加获取当前活跃句柄的功能;修正了计算子网掩码的Bug。
-rw-r--r--.editorconfig2
-rw-r--r--app/src/marsio.c9
-rw-r--r--app/src/sendpath.c5
-rw-r--r--app/src/version.map1
-rw-r--r--include/external/marsio.h2
-rw-r--r--service/src/core.c54
-rw-r--r--service/src/phydev.c20
7 files changed, 65 insertions, 28 deletions
diff --git a/.editorconfig b/.editorconfig
index 37cab03..74d028c 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -10,7 +10,7 @@ indent_size=4
[*.map]
end_of_line=lf
-charset=utf-8
+charset=latin1
indent_style=tab
trim_tailing_whitespace=true
insert_final_newline=true
diff --git a/app/src/marsio.c b/app/src/marsio.c
index 20e5cdc..d5f1051 100644
--- a/app/src/marsio.c
+++ b/app/src/marsio.c
@@ -22,6 +22,8 @@ unsigned int g_eal_inited = 0;
__thread struct mr_thread_info thread_info;
+struct mr_instance * _current_instance = NULL;
+
#define MRAPP_MONIT_FILE_PATH "/var/run/mrzcpd/mrmonit.app.%s"
#define MRAPP_SERVICE_MONIT_FILE_PATH "/var/run/mrzcpd/mrmonit.daemon"
#define MRAPP_GLOBAL_CONF_FILE_PATH "/etc/mrglobal.conf"
@@ -379,9 +381,16 @@ struct mr_instance * marsio_create()
struct mr_instance * instance;
instance = malloc(sizeof(struct mr_instance));
memset(instance, 0, sizeof(struct mr_instance));
+
+ _current_instance = instance;
return instance;
}
+struct mr_instance * marsio_current()
+{
+ return _current_instance;
+}
+
int marsio_init(struct mr_instance * instance, const char * appsym)
{
/* 写应用名称参数 */
diff --git a/app/src/sendpath.c b/app/src/sendpath.c
index f79d469..bd90194 100644
--- a/app/src/sendpath.c
+++ b/app/src/sendpath.c
@@ -10,7 +10,7 @@ static inline int is_same_subnet(struct in_addr a_addr, struct in_addr b_addr, s
in_addr_t in_addr_a = a_addr.s_addr;
in_addr_t in_addr_b = b_addr.s_addr;
in_addr_t in_addr_mask = mask.s_addr;
- return (in_addr_a & in_addr_mask) == (in_addr_b && in_addr_mask);
+ return (in_addr_a & in_addr_mask) == (in_addr_b & in_addr_mask);
}
static int droute_l2_construct_fn(struct mr_sendpath * sendpath,
@@ -77,6 +77,9 @@ struct mr_sendpath * marsio_sendpath_create_by_droute(struct mr_vdev * dest_devi
target_in_addr = vdev->in_gateway;
}
+ MR_DEBUG("SENDPATH: create_by_droute, in_addr=%u, target_in_addr=%u",
+ addr.s_addr, target_in_addr.s_addr);
+
struct mr_sendpath * sendpath = malloc(sizeof(struct mr_sendpath));
MR_VERIFY_MALLOC(sendpath);
diff --git a/app/src/version.map b/app/src/version.map
index c514b65..ce0f96a 100644
--- a/app/src/version.map
+++ b/app/src/version.map
@@ -2,6 +2,7 @@ LIBMARSIO {
global:
marsio_create;
marsio_init;
+ marsio_current;
marsio_thread_init;
marsio_destory;
marsio_option_set;
diff --git a/include/external/marsio.h b/include/external/marsio.h
index adf1f56..dc5c535 100644
--- a/include/external/marsio.h
+++ b/include/external/marsio.h
@@ -44,6 +44,8 @@ struct mr_sendpath;
struct mr_instance;
struct mr_instance * marsio_create();
+struct mr_instance * marsio_current();
+
int marsio_option_get(struct mr_instance * instance, int opt_type, void * out_opt, size_t out_opt_buffer);
int marsio_option_set(struct mr_instance * instance, marsio_opt_type_t opt_type, void * opt, size_t sz_opt);
int marsio_init(struct mr_instance * instance, const char * appsym);
diff --git a/service/src/core.c b/service/src/core.c
index 616d0ca..e3044ad 100644
--- a/service/src/core.c
+++ b/service/src/core.c
@@ -7,6 +7,7 @@
#include <rte_malloc.h>
#include <rte_launch.h>
#include <arpa/inet.h>
+#include <signal.h>
#include <MESA_prof_load.h>
#include <sc_common.h>
@@ -69,6 +70,7 @@ const char service_git_version[] = "";
unsigned int g_logger_to_stdout = 1;
unsigned int g_logger_level = LOG_DEBUG;
unsigned int g_monit_interval = 1;
+unsigned int g_keep_running = 1;
static struct sc_main * g_sc_main = NULL;
@@ -145,12 +147,14 @@ void * sc_ctrlplane_thread(void * args)
struct sc_main * sc_main = (struct sc_main *)args;
pthread_detach(pthread_self());
- while (1)
+ while (g_keep_running)
{
sc_monit_loop(sc_main);
sc_keepalive_loop(sc_main);
sleep(1);
}
+
+ return (void *)NULL;
}
int sc_dataplane_thread(void * arg)
@@ -160,7 +164,7 @@ int sc_dataplane_thread(void * arg)
uint64_t idle_counter = 0;
MR_INFO("Dataplane thread %d is running ... ", lcore_id);
- while (1)
+ while (g_keep_running)
{
/* 优化分支预测,以宏定义的默认行为为多数行为 */
@@ -381,9 +385,16 @@ static int __check_is_notify()
return notify_socket == NULL ? 0 : 1;
}
+static void signal_handler(int signum)
+{
+ g_keep_running = 0;
+ return;
+}
+
extern int hwinfo_init(struct sc_main * sc);
extern int phydev_init(struct sc_main * sc);
extern int phydev_early_init(struct sc_main * sc);
+extern void phydev_deinit(struct sc_main * sc);
extern int sw_forward_init(struct sc_main * sc);
extern int app_main_init(struct sc_main * sc);
extern int vdev_dump(struct sc_main * sc);
@@ -408,6 +419,7 @@ int main(int argc, char * argv[])
if(__check_is_notify()) g_logger_to_stdout = 0;
else g_logger_to_stdout = 1;
+ int ret = 0;
int opt = 0;
while ((opt = getopt(argc, argv, "hvc:w:d:")) != -1)
{
@@ -443,22 +455,22 @@ int main(int argc, char * argv[])
if (access(sc->local_cfgfile, R_OK) != 0)
{
MR_ERROR("Configure File %s is not existed. Failed. ", sc->local_cfgfile);
- exit(EXIT_FAILURE);
+ ret = EXIT_FAILURE; goto quit;
}
-#if 0
/* Check Hardware File */
if (access(sc->local_hwfile, R_OK) != 0)
{
- MR_ERROR("Hardware File %s is not existed. Failed. ", sc->local_hwfile);
- exit(EXIT_FAILURE);
+ MR_WARNING("Hardware File %s is not existed. ", sc->local_hwfile);
}
-#endif
+
+ signal(SIGINT, signal_handler);
+ signal(SIGTERM, signal_handler);
if (phydev_early_init(sc) != RT_SUCCESS)
{
MR_ERROR("PHY devices early initialization failed. ");
- exit(EXIT_FAILURE);
+ ret = EXIT_FAILURE; goto quit;
}
/* 加载EAL选项 */
@@ -466,49 +478,49 @@ int main(int argc, char * argv[])
if (sc_g_config_init(sc) != RT_SUCCESS)
{
MR_ERROR("Global configuration load failed. ");
- exit(EXIT_FAILURE);
+ ret = EXIT_FAILURE; goto quit;
}
if (sc_ctrlmsg_init(sc) != RT_SUCCESS)
{
MR_ERROR("Ctrlmsg module initialization failed. ");
- exit(EXIT_FAILURE);
+ ret = EXIT_FAILURE; goto quit;
}
if (app_main_init(sc) != RT_SUCCESS)
{
MR_ERROR("App management module initialization failed. ");
- exit(EXIT_FAILURE);
+ ret = EXIT_FAILURE; goto quit;
}
if (hwinfo_init(sc) != RT_SUCCESS)
{
MR_ERROR("Hardware information initialization failed. ");
- exit(EXIT_FAILURE);
+ ret = EXIT_FAILURE; goto quit;
}
if (mrb_init(sc) != RT_SUCCESS)
{
MR_ERROR("Pktmbuf pools initialization failed.");
- exit(EXIT_FAILURE);
+ ret = EXIT_FAILURE; goto quit;
}
if (phydev_init(sc) != RT_SUCCESS)
{
MR_ERROR("Physical devices initialization failed. ");
- exit(EXIT_FAILURE);
+ ret = EXIT_FAILURE; goto quit;
}
if (vdev_main_init(sc) != RT_SUCCESS)
{
MR_ERROR("Virtual devices initialization failed. ");
- exit(EXIT_FAILURE);
+ ret = EXIT_FAILURE; goto quit;
}
if (sw_forward_init(sc) != RT_SUCCESS)
{
MR_ERROR("Direct switch module initialization failed. ");
- exit(EXIT_FAILURE);
+ ret = EXIT_FAILURE; goto quit;
}
sc_config_dump(sc);
@@ -518,15 +530,15 @@ int main(int argc, char * argv[])
if (ctrlmsg_thread_launch(sc->ctrlmsg_handler) != RT_SUCCESS)
{
MR_ERROR("Launch ctrlmsg thread failed");
- exit(EXIT_FAILURE);
+ ret = EXIT_FAILURE; goto quit;
}
pthread_t ctrlplane_thread_id;
- int ret = pthread_create(&ctrlplane_thread_id, NULL, sc_ctrlplane_thread, sc);
+ ret = pthread_create(&ctrlplane_thread_id, NULL, sc_ctrlplane_thread, sc);
if (ret < 0)
{
MR_ERROR("Launch ctrlplane thread failed : %s", strerror(errno));
- exit(EXIT_FAILURE);
+ ret = EXIT_FAILURE; goto quit;
}
/* 采用NOTIFY方式启动,通知操作系统完成了初始化 */
@@ -548,6 +560,8 @@ int main(int argc, char * argv[])
}
}
- assert(0);
+quit:
+ //TODO: 其他模块的销毁
+ phydev_deinit(sc);
return 0;
} \ No newline at end of file
diff --git a/service/src/phydev.c b/service/src/phydev.c
index bd20d26..1152764 100644
--- a/service/src/phydev.c
+++ b/service/src/phydev.c
@@ -544,6 +544,19 @@ int phydev_early_init(struct sc_main * sc)
return phydev_main->en_early_scan ? phydev_early_scan(sc, phydev_main) : 0;
}
+
+void phydev_deinit(struct sc_main * sc)
+{
+ for (unsigned int port_id = 0; port_id < rte_eth_dev_count(); port_id++)
+ {
+ rte_eth_dev_stop(port_id);
+ rte_eth_dev_close(port_id);
+ MR_INFO("Port %d closed.", port_id);
+ }
+
+ return;
+}
+
/* 初始化 */
int phydev_init(struct sc_main * sc)
{
@@ -560,13 +573,8 @@ int phydev_init(struct sc_main * sc)
if (phydev_setup(sc, sc->phydev_main, phydev_iter) == RT_SUCCESS) continue;
return RT_ERR;
}
-
- return RT_SUCCESS;
-}
-int phydev_deinit(struct sc_main * instance)
-{
- return 0;
+ return RT_SUCCESS;
}
void phydev_stat_get(struct phydev * phydev, struct phydev_stat * phydev_stat)