1 Star 0 Fork 32

shafeipaozi/gazelle

forked from src-openEuler/gazelle 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0148-fix-rpc_pool-create-failed-coredump.patch 3.26 KB
一键复制 编辑 原始数据 按行查看 历史
jinag12 提交于 2024-03-14 16:57 . sync fix rpc_pool create failed coredump
From 98b8e8cea061d65ece3865ce8e772f5b4226199e Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Tue, 27 Feb 2024 22:37:47 +0800
Subject: [PATCH] fix rpc_pool create failed coredump
---
src/lstack/core/lstack_thread_rpc.c | 34 ++++++++++++++++++++------
src/lstack/include/lstack_thread_rpc.h | 6 ++++-
2 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c
index 1fdb037..20c5a43 100644
--- a/src/lstack/core/lstack_thread_rpc.c
+++ b/src/lstack/core/lstack_thread_rpc.c
@@ -36,6 +36,27 @@ static inline __attribute__((always_inline)) struct rpc_msg *get_rpc_msg(struct
return msg;
}
+static void rpc_msg_init(struct rpc_msg *msg, rpc_msg_func func, struct rpc_msg_pool *pool)
+{
+ msg->rpcpool = pool;
+ pthread_spin_init(&msg->lock, PTHREAD_PROCESS_PRIVATE);
+ msg->func = func;
+ msg->sync_flag = 1;
+ msg->recall_flag = 0;
+}
+
+static struct rpc_msg *rpc_msg_alloc_except(rpc_msg_func func)
+{
+ struct rpc_msg *msg = calloc(1, sizeof(struct rpc_msg));
+ if (msg == NULL) {
+ return NULL;
+ }
+
+ rpc_msg_init(msg, func, NULL);
+
+ return msg;
+}
+
static struct rpc_msg *rpc_msg_alloc(rpc_msg_func func)
{
struct rpc_msg *msg = NULL;
@@ -45,14 +66,15 @@ static struct rpc_msg *rpc_msg_alloc(rpc_msg_func func)
if (g_rpc_pool == NULL) {
LSTACK_LOG(INFO, LSTACK, "g_rpc_pool calloc failed\n");
g_rpc_stats.call_alloc_fail++;
- return NULL;
+ exit(-1);
}
g_rpc_pool->mempool = create_mempool("rpc_pool", RPC_MSG_MAX, sizeof(struct rpc_msg),
0, rte_gettid());
if (g_rpc_pool->mempool == NULL) {
+ LSTACK_LOG(INFO, LSTACK, "rpc_pool create failed, errno is %d\n", errno);
g_rpc_stats.call_alloc_fail++;
- return NULL;
+ exit(-1);
}
}
@@ -61,12 +83,8 @@ static struct rpc_msg *rpc_msg_alloc(rpc_msg_func func)
g_rpc_stats.call_alloc_fail++;
return NULL;
}
- msg->rpcpool = g_rpc_pool;
+ rpc_msg_init(msg, func, g_rpc_pool);
- pthread_spin_init(&msg->lock, PTHREAD_PROCESS_PRIVATE);
- msg->func = func;
- msg->sync_flag = 1;
- msg->recall_flag = 0;
return msg;
}
@@ -247,7 +265,7 @@ int32_t rpc_call_close(rpc_queue *queue, int fd)
int32_t rpc_call_stack_exit(rpc_queue *queue)
{
- struct rpc_msg *msg = rpc_msg_alloc(stack_exit_by_rpc);
+ struct rpc_msg *msg = rpc_msg_alloc_except(stack_exit_by_rpc);
if (msg == NULL) {
return -1;
}
diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h
index 30caa66..4d89604 100644
--- a/src/lstack/include/lstack_thread_rpc.h
+++ b/src/lstack/include/lstack_thread_rpc.h
@@ -104,7 +104,11 @@ static inline __attribute__((always_inline)) void rpc_call(rpc_queue *queue, str
static inline __attribute__((always_inline)) void rpc_msg_free(struct rpc_msg *msg)
{
pthread_spin_destroy(&msg->lock);
- rte_mempool_put(msg->rpcpool->mempool, (void *)msg);
+ if (msg->rpcpool != NULL && msg->rpcpool->mempool != NULL) {
+ rte_mempool_put(msg->rpcpool->mempool, (void *)msg);
+ } else {
+ free(msg);
+ }
}
#endif
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/shafeipaozi/gazelle.git
git@gitee.com:shafeipaozi/gazelle.git
shafeipaozi
gazelle
gazelle
master

搜索帮助