diff --git a/CMakeLists.txt b/CMakeLists.txt index caeaac57827adcc56d47262c178a69d5aa4113e6..846f79ecbb0220a4b3f85ce4755d9389600d4c9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,32 +26,6 @@ else () message(FATAL_ERROR "unknown CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE}) endif () -set(COMPONENT "GaussDB Kernel") - -if(OPENGAUSS STREQUAL "yes") - message(STATUS "OPENGAUSS=yes") - add_definitions(-DOPENGAUSS) - set(COMPONENT "openGauss") -endif() - -EXECUTE_PROCESS( - COMMAND bash -c "git rev-parse HEAD | cut -b 1-8" - OUTPUT_VARIABLE COMMIT_ID - OUTPUT_STRIP_TRAILING_WHITESPACE -) -EXECUTE_PROCESS( - COMMAND bash -c "date \"+%Y-%m-%d %H:%M:%S\"" - OUTPUT_VARIABLE COMPILE_TIME - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -# CBB_VERSION_STR like: libcbb.a (openGauss build ab4a14da) compiled at 2000-01-01 00:00:00 debug) -SET(CBB_VERSION_STR - "libcbb.a (${COMPONENT} build ${COMMIT_ID}) compiled at ${COMPILE_TIME} ${CMAKE_BUILD_TYPE}" -) - -message(STATUS "Version info: ${CBB_VERSION_STR}") - set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS} -D__FILE_NAME__='\"$(notdir $(subst .o,,$(abspath $@)))\"'") add_compile_options(-fPIC -Wall -MMD -fno-strict-aliasing -fsigned-char -fms-extensions -lpthread) @@ -138,7 +112,6 @@ set(CBB_SERVICE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/ddes_perctrl/service) set(CBB_MEC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/cm_mec_adapter) set(CBB_COMPRESS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/cm_compress) set(CBB_FAULT_INJECTION_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/ddes_fi) -CONFIGURE_FILE(cm_version.h.in ${CBB_UTIL_PATH}/cm_version.h) ## other dependency include set(CBB_SECUREC_INC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/library/huawei_security/include/") diff --git a/README.md b/README.md index 349cbfebc87e551e96fafe22bfbbb71bb0e6f56c..b516706a024cda8b1ac42f51ee8736701d0bee19 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,6 @@ DCC等组件依赖的公共函数模块。 支持以下操作系统: - CentOS 7.6(x86) - openEuler-20.03-LTS -- openEuler-22.03-LTS -- openEuler-24.03-LTS - 适配其他系统,可参照openGauss数据库编译指导 ##### 2、下载CBB 可以从开源社区下载CBB。 diff --git a/cm_version.h.in b/cm_version.h.in deleted file mode 100644 index 2cf654c94a500d63d1f0f1d6eed025f7c917c44e..0000000000000000000000000000000000000000 --- a/cm_version.h.in +++ /dev/null @@ -1,3 +0,0 @@ -#ifndef DEF_CBB_VERSION -#define DEF_CBB_VERSION "@CBB_VERSION_STR@" -#endif \ No newline at end of file diff --git a/src/cm_concurrency/cm_spinlock.h b/src/cm_concurrency/cm_spinlock.h index 720a65db56d76507108d86bd5a0d6918f4958e9b..7b96a1569e062b0a519c7df48937ecfeb6c73018 100644 --- a/src/cm_concurrency/cm_spinlock.h +++ b/src/cm_concurrency/cm_spinlock.h @@ -96,17 +96,17 @@ void cm_set_spin_sleep_time(uint32 sleep_time_nanosecs); #ifdef WIN32 -static forceinline uint32 cm_spin_set(spinlock_t *ptr, uint32 value) +static inline uint32 cm_spin_set(spinlock_t *ptr, uint32 value) { return (uint32)InterlockedExchange(ptr, value); } -static forceinline void cm_spin_sleep() +static inline void cm_spin_sleep() { Sleep(1); } -static forceinline void cm_spin_sleep_ex(uint32 tick) +static inline void cm_spin_sleep_ex(uint32 tick) { Sleep(tick); } @@ -114,25 +114,25 @@ static forceinline void cm_spin_sleep_ex(uint32 tick) #else #if defined(__arm__) || defined(__aarch64__) -static forceinline uint32 cm_spin_set(spinlock_t *ptr, uint32 value) +static inline uint32 cm_spin_set(spinlock_t *ptr, uint32 value) { uint32 oldvalue = 0; return !__atomic_compare_exchange_n(ptr, &oldvalue, value, CM_FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } -static forceinline void cm_spin_unlock(spinlock_t *lock) +static inline void cm_spin_unlock(spinlock_t *lock) { __atomic_store_n(lock, 0, __ATOMIC_SEQ_CST); } #else -static forceinline uint32 cm_spin_set(spinlock_t *ptr, uint32 value) +static inline uint32 cm_spin_set(spinlock_t *ptr, uint32 value) { uint32 oldvalue = 0; return (uint32)__sync_val_compare_and_swap(ptr, oldvalue, value); } #endif -static forceinline void cm_spin_sleep(void) +static inline void cm_spin_sleep(void) { struct timespec ts; ts.tv_sec = 0; @@ -140,7 +140,7 @@ static forceinline void cm_spin_sleep(void) (void)nanosleep(&ts, NULL); } -static forceinline void cm_spin_sleep_ex(uint32 tick) +static inline void cm_spin_sleep_ex(uint32 tick) { struct timespec ts; ts.tv_sec = 0; @@ -150,8 +150,7 @@ static forceinline void cm_spin_sleep_ex(uint32 tick) #endif -static forceinline void cm_spin_lock_with_stat(spinlock_t *lock, spin_statis_t *stat, - spin_statis_instance_t *stat_instance) +static inline void cm_spin_lock_with_stat(spinlock_t *lock, spin_statis_t *stat, spin_statis_instance_t *stat_instance) { uint32 spin_times = 0; uint32 sleep_times = 0; @@ -191,7 +190,7 @@ static forceinline void cm_spin_lock_with_stat(spinlock_t *lock, spin_statis_t * #define cm_spin_lock(lock, stat) cm_spin_lock_with_stat(lock, stat, NULL) -static forceinline void cm_spin_lock_ex(spinlock_t *lock, spin_statis_t *stat, uint32 spin_count) +static inline void cm_spin_lock_ex(spinlock_t *lock, spin_statis_t *stat, uint32 spin_count) { uint32 spin_times = 0; uint32 sleep_times = 0; @@ -232,7 +231,7 @@ static forceinline void cm_spin_lock_ex(spinlock_t *lock, spin_statis_t *stat, u } #if !defined(__arm__) && !defined(__aarch64__) -static forceinline void cm_spin_unlock(spinlock_t *lock) +static inline void cm_spin_unlock(spinlock_t *lock) { if (SECUREC_UNLIKELY(lock == NULL)) { return; @@ -242,7 +241,7 @@ static forceinline void cm_spin_unlock(spinlock_t *lock) } #endif -static forceinline bool32 cm_spin_try_lock(spinlock_t *lock) +static inline bool32 cm_spin_try_lock(spinlock_t *lock) { #if defined(__arm__) || defined(__aarch64__) if (__atomic_load_n(lock, __ATOMIC_SEQ_CST) != 0) { @@ -255,7 +254,7 @@ static forceinline bool32 cm_spin_try_lock(spinlock_t *lock) return (cm_spin_set(lock, 1) == 0); } -static forceinline bool32 cm_spin_timed_lock(spinlock_t *lock, uint32 timeout_ticks) +static inline bool32 cm_spin_timed_lock(spinlock_t *lock, uint32 timeout_ticks) { uint32 spin_times = 0, wait_ticks = 0; uint32 sleep_times = 0; @@ -297,7 +296,7 @@ static forceinline bool32 cm_spin_timed_lock(spinlock_t *lock, uint32 timeout_ti return CM_TRUE; } -static forceinline void cm_spin_lock_by_sid(uint32 sid, spinlock_t *lock, spin_statis_t *stat) +static inline void cm_spin_lock_by_sid(uint32 sid, spinlock_t *lock, spin_statis_t *stat) { uint32 spin_times = 0; uint32 sleep_times = 0; diff --git a/src/cm_concurrency/cm_thread.c b/src/cm_concurrency/cm_thread.c index 7bbcf7627d228575db6337bc394e689837de3db9..fa9dd5f6fe6c86ea357b3e1fb05d8f24a705a99f 100644 --- a/src/cm_concurrency/cm_thread.c +++ b/src/cm_concurrency/cm_thread.c @@ -166,11 +166,6 @@ void cm_thread_unlock(thread_lock_t *lock) LeaveCriticalSection(lock); } -void cm_destroy_thread_lock(thread_lock_t *lock) -{ - DeleteCriticalSection(lock); -} - #else void cm_init_thread_lock(thread_lock_t *lock) @@ -188,11 +183,6 @@ void cm_thread_unlock(thread_lock_t *lock) (void)pthread_mutex_unlock(lock); } -void cm_destroy_thread_lock(thread_lock_t *lock) -{ - (void)pthread_mutex_destroy(lock); -} - #endif #ifdef WIN32 diff --git a/src/cm_concurrency/cm_thread.h b/src/cm_concurrency/cm_thread.h index 47bd7fcd2481e484e758fb589f76383d9182c3d5..3bb8c2896ee9c787ee4278c13ffe62a303c17b5c 100644 --- a/src/cm_concurrency/cm_thread.h +++ b/src/cm_concurrency/cm_thread.h @@ -91,7 +91,6 @@ void cm_destory_cond(cm_thread_cond_t *cond); void cm_init_thread_lock(thread_lock_t *lock); void cm_thread_lock(thread_lock_t *lock); void cm_thread_unlock(thread_lock_t *lock); -void cm_destroy_thread_lock(thread_lock_t *lock); /* thread */ typedef struct st_thread { diff --git a/src/cm_concurrency/cm_thread_pool.c b/src/cm_concurrency/cm_thread_pool.c index 7235671ca08831e002da0cfb6a110434eb5dc460..37d0d4c542427e35fee50c919f10676a70f3d0d3 100644 --- a/src/cm_concurrency/cm_thread_pool.c +++ b/src/cm_concurrency/cm_thread_pool.c @@ -25,7 +25,6 @@ #include "cm_thread_pool.h" #include "cm_log.h" #include "cm_error.h" -#include "cm_system.h" #ifdef __cplusplus extern "C" { @@ -37,7 +36,6 @@ static void cm_pooling_thread_entry(thread_t *obj) status_t ret; cm_set_thread_name("pooling_thread"); - cm_block_sighup_signal(); pooling_thread->spid = cm_get_current_thread_id(); diff --git a/src/cm_defines/cm_defs.h b/src/cm_defines/cm_defs.h index 2f2e3371206eea6bfa712552f35b9346604869da..41e75790075ba2a31cee82ba9f7a2630ac55ff23 100644 --- a/src/cm_defines/cm_defs.h +++ b/src/cm_defines/cm_defs.h @@ -114,6 +114,7 @@ extern "C" { #define CM_MES_ROOMS_PER_FREELIST (uint32)(CM_MAX_MES_ROOMS / CM_MAX_ROOM_FREELIST_NUM) #define CM_MAX_MES_MSG_CMD (uint8)255 +/* DAAC */ #define CM_MES_MIN_CHANNEL_NUM (uint32)(1) #define CM_MES_MAX_CHANNEL_NUM (uint32)(32) #define CM_MES_MIN_TASK_NUM (16) @@ -308,10 +309,6 @@ void cm_free_prot(void *pointer); } \ } while (0) -#define CM_RETVALUE_IFTRUE(cond, value) \ - if (cond) { \ - return value; \ - } /* is letter */ #define CM_IS_LETER(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z')) @@ -496,14 +493,6 @@ typedef enum en_node_status { NODE_BLOCKED, } node_status_t; -#ifdef _MSC_VER //for MSVC -#define forceinline __forceinline -#elif (defined(__GNUC__) && __GNUC__ > 3 && defined(__OPTIMIZE__)) || defined(__SUNPRO_C) || defined(__IBMC__) -/* GCC > 3, Sunpro and XLC support always inline via __attribute__*/ -#define forceinline __attribute__((always_inline)) inline -#else -#define forceinline inline -#endif #ifdef __cplusplus } diff --git a/src/cm_defines/cm_error.c b/src/cm_defines/cm_error.c index 76be6bef6ea6da97de4488be67d8af29791ff5ef..9c371039aab8be303038aa8470517335971ca542 100644 --- a/src/cm_defines/cm_error.c +++ b/src/cm_defines/cm_error.c @@ -107,12 +107,6 @@ const char *g_error_desc[CM_ERROR_COUNT] = { "D. at least one special character: `~!@#$%%^&*()-_=+\\|[{}]:\'\",<.>/? and space", [ERR_PASSWORD_FORMAT_ERROR] = "The password was invalid: %s", [ERR_INVALID_PARAM] = "Invalid parameter: %s", - [ERR_PARAMETER_TOO_LARGE] = "The value of parameter \"%s\" is too large, at most %lld", - [ERR_PARAMETER_TOO_SMALL] = "The value of parameter \"%s\" is too small, at least %lld", - [ERR_OPERATIONS_NOT_SUPPORT] = "Operation \"%s\" is not support on %s", - [ERR_LINE_TOO_LONG] = "The length of row %d is too long", - [ERR_INVALID_PARAMETER_ENUM] = "The value of parameter \"%s\" cannot be recognized: \"%s\"", - [ERR_PARAM_COUNT_OVERFLOW] = "The parameter count %d is too large, at most %lld", /* Error msg for access interface of SCSI */ [ERR_SCSI_LOCK_OCCUPIED] = "The lock is already occupied", [ERR_SCSI_REG_CONFLICT] = "Register conflict, rk %llu", @@ -147,9 +141,6 @@ const char *g_error_desc[CM_ERROR_COUNT] = { [ERR_SSL_CONNECT_FAILED] = "The SSL connection failed, %s", [ERR_SSL_FILE_PERMISSION] = "SSL certificate file \"%s\" has execute, group or world access permission", [ERR_FULL_PACKET] = "%s packet size(%u) exceeds the max value(%u)", - [ERR_INVALID_IPADDRESS_OR_DOMAIN_LENGTH] = "Invalid IP address or domain length: %u", - [ERR_IPADDRESS_OR_DOMAIN_NUM_EXCEED] = "Number of IP address or domain exceeds the maximum(%u)", - [ERR_TCP_INVALID_URLADDRESS] = "Invalid Ip address or domain: %s", // MES, range [2700, 2799] [ERR_MEC_INIT_FAIL ] = "MEC init failed, %s.", diff --git a/src/cm_defines/cm_error.h b/src/cm_defines/cm_error.h index 9959b6994d06386b07063c56966cd8f1c65ef67a..a5e29b92165beb81646b3103c7144ee0fb260bb9 100644 --- a/src/cm_defines/cm_error.h +++ b/src/cm_defines/cm_error.h @@ -104,12 +104,6 @@ typedef enum en_cm_errno { ERR_PASSWORD_IS_TOO_SIMPLE = 110, ERR_PASSWORD_FORMAT_ERROR = 111, ERR_INVALID_PARAM = 112, - ERR_PARAMETER_TOO_LARGE = 113, - ERR_PARAMETER_TOO_SMALL = 114, - ERR_OPERATIONS_NOT_SUPPORT = 115, - ERR_LINE_TOO_LONG = 116, - ERR_INVALID_PARAMETER_ENUM = 117, - ERR_PARAM_COUNT_OVERFLOW = 118, /* Error code for access interface of SCSI */ ERR_SCSI_LOCK_OCCUPIED = 136, ERR_SCSI_REG_CONFLICT = 137, @@ -161,9 +155,6 @@ typedef enum en_cm_errno { ERR_SSL_CONNECT_FAILED = 336, ERR_SSL_FILE_PERMISSION = 337, ERR_FULL_PACKET = 338, - ERR_INVALID_IPADDRESS_OR_DOMAIN_LENGTH = 339, - ERR_IPADDRESS_OR_DOMAIN_NUM_EXCEED = 340, - ERR_TCP_INVALID_URLADDRESS = 341, /* replication errors: 400 - 499 */ ERR_TERM_IS_NOT_MATCH = 400, ERR_TERM_IS_EXPIRED = 401, @@ -266,15 +257,6 @@ static inline void cm_panic(bool32 condition) } \ } while (0) -#define CM_SECUREC_CHECK(err) \ - { \ - if (SECUREC_UNLIKELY(EOK != (err))) { \ - LOG_RUN_ERR("Secure C lib has throw an error %d", (err)); \ - cm_fync_logfile(); \ - cm_panic(0); \ - } \ - } - #define CM_THROW_ERROR(error_no, ...) \ do { \ cm_set_error((char *)__FILE_NAME__, (uint32)__LINE__, (cm_errno_t)error_no, \ diff --git a/src/cm_mec_adapter/mec_adapter.c b/src/cm_mec_adapter/mec_adapter.c index c63acecc6cc1e4a240edecb5bf1eca5b1095fbea..84e9323438b6020c0591a2efb4d6ffbf217924b6 100644 --- a/src/cm_mec_adapter/mec_adapter.c +++ b/src/cm_mec_adapter/mec_adapter.c @@ -141,7 +141,8 @@ int mec_accept(cs_pipe_t *pipe) static int mec_get_message_buf(mes_message_t *msg, const mec_message_head_adapter_t *mec_head) { - uint64 stat_time = cm_get_time_usec(); + uint64 stat_time = 0; + mes_get_consume_time_start(&stat_time); char *msg_buf = NULL; mes_priority_t priority = MEC_PRIV_LOW_ADAPTER(mec_head->flags) ? MES_PRIORITY_ONE : MES_PRIORITY_ZERO; uint32 size = mec_head->size; @@ -219,11 +220,12 @@ static status_t mec_check_recv_head_info(const mec_message_head_adapter_t *mec_h int mec_process_event(mes_pipe_t *pipe) { LOG_DEBUG_INF("[mes_mec] mec_process_event start"); + uint64 stat_time = 0; mes_message_t msg; mec_message_head_adapter_t mec_head; mes_message_head_t mes_head; - uint64 stat_time = cm_get_time_usec(); + mes_get_consume_time_start(&stat_time); int ret = cs_read_fixed_size(&pipe->recv_pipe, (char *)&mec_head, MEC_MSG_HEAD_SIZE_ADAPTER); if (ret != CM_SUCCESS) { @@ -273,7 +275,7 @@ int mec_process_event(mes_pipe_t *pipe) return ERR_MES_SOCKET_FAIL; } - mes_consume_with_time(msg.head->app_cmd, MES_TIME_READ_SOCKET, stat_time); + mes_consume_with_time(msg.head->cmd, MES_TIME_READ_MES, stat_time); (void)cm_atomic_inc(&(pipe->recv_count)); diff --git a/src/cm_mes/mes_cb.c b/src/cm_mes/mes_cb.c index ee3ba409c90f02c5fb8c180d4e2e529c10fc888a..e3a15eb1c75d9eea623c2b0daab6ce66a3fe197f 100644 --- a/src/cm_mes/mes_cb.c +++ b/src/cm_mes/mes_cb.c @@ -30,7 +30,6 @@ extern "C" { static mes_thread_init_t g_cb_thread_init = NULL; static mes_thread_deinit_t g_cb_thread_deinit = NULL; -static mes_app_cmd_cb_t g_cb_app_cmd = NULL; mes_thread_init_t mes_get_worker_init_cb(void) { @@ -52,16 +51,6 @@ void mes_set_worker_deinit_cb(mes_thread_deinit_t callback) g_cb_thread_deinit = callback; } -void mes_set_app_cmd_cb(mes_app_cmd_cb_t callback) -{ - g_cb_app_cmd = callback; -} - -mes_app_cmd_cb_t mes_get_app_cmd_cb() -{ - return g_cb_app_cmd; -} - #ifdef __cplusplus } #endif diff --git a/src/cm_mes/mes_func.c b/src/cm_mes/mes_func.c index ccca15c1f6153a7d3dfa9cebff86bba82b1ed96f..0fe1c4759adf7d0bfe181f6cbc8c90ebcc72ab44 100644 --- a/src/cm_mes/mes_func.c +++ b/src/cm_mes/mes_func.c @@ -31,6 +31,7 @@ #include "mes_tcp.h" #include "cm_date_to_text.h" #include "mes_rpc_dl.h" +#include "mes_rpc_ulog4c.h" #include "cm_defs.h" #include "mes_metadata.h" #include "mes_interface.h" @@ -38,17 +39,16 @@ #include "mes_recv.h" #include "mes_stat.h" #include "mec_adapter.h" -#include "cm_system.h" mes_instance_t g_cbb_mes = {0}; mes_callback_t g_cbb_mes_callback; static spinlock_t g_profile_lock; static mes_global_ptr_t g_mes_ptr = { - .mes_ptr = &g_cbb_mes, - .cmd_count_stats_ptr = &g_mes_stat, - .cmd_time_stats_ptr = &g_mes_elapsed_stat, - .cmd_size_stats_ptr = &g_mes_msg_size_stat + .g_cbb_mes_ptr = &g_cbb_mes, + .g_mes_stat_ptr = &g_mes_stat, + .g_mes_elapsed_stat = &g_mes_elapsed_stat, + .g_mes_msg_size_stat_ptr = &g_mes_msg_size_stat }; #define MES_CONNECT(pipe) g_cbb_mes_callback.connect_func(pipe) @@ -946,6 +946,7 @@ static inline void mes_close_libdl(void) { if (MES_GLOBAL_INST_MSG.profile.pipe_type == MES_TYPE_RDMA) { FinishOckRpcDl(); + FinishUlogDl(); } } @@ -1018,9 +1019,6 @@ void mes_notify_msg_recv(mes_message_t *msg) } cm_spin_lock(&room->lock, NULL); - LOG_DEBUG_INF("[mes]mes_notify_msg_recv ruid=%llu(%llu-%llu), cmd=%d, room:%llu-%llu, rstatus:%d", - (uint64)msg->head->ruid, (uint64)MES_RUID_GET_RID(msg->head->ruid), (uint64)MES_RUID_GET_RSN(msg->head->ruid), - (int32)msg->head->cmd, (uint64)room->room_index, (uint64)room->rsn, (int32)room->room_status); mes_ensure_inst_broadcast_msg_exist(msg->head->src_inst); if (mes_check_msg_recv(msg, room)) { if (room->room_status == STATUS_PTP_SENT) { @@ -1062,7 +1060,8 @@ void mes_process_message(mes_msgqueue_t *my_queue, mes_message_t *msg) return; } - uint64 start_time = cm_get_time_usec(); + uint64 start_time = 0; + mes_get_consume_time_start(&start_time); mes_msgitem_t *msgitem = NULL; mes_recv_message_stat(msg); @@ -1082,7 +1081,7 @@ void mes_process_message(mes_msgqueue_t *my_queue, mes_message_t *msg) msgitem->msg.head = msg->head; msgitem->msg.buffer = msg->buffer; - msgitem->enqueue_time = cm_get_time_usec(); + msgitem->enqueue_time = g_timer()->monotonic_now; if (ENABLE_MES_TASK_THREADPOOL) { mes_put_msgitem_to_threadpool(msgitem); @@ -1091,7 +1090,7 @@ void mes_process_message(mes_msgqueue_t *my_queue, mes_message_t *msg) uint32 work_index = 0; mes_put_msgitem_enqueue(msgitem, CM_FALSE, &work_index); - mes_consume_with_time(msg->head->app_cmd, MES_TIME_PUT_QUEUE, start_time); + mes_consume_with_time(msg->head->cmd, MES_TIME_PUT_QUEUE, start_time); if (work_index == CM_INVALID_ID32 || work_index >= MES_MAX_TASK_NUM) { mes_release_message_buf(msg); LOG_RUN_ERR("[mes] mes_process_message, get work index failed."); @@ -1296,7 +1295,7 @@ static status_t mes_init_ssl(void) CM_RETURN_IFERR(cs_ssl_verify_file_stat(ssl_cfg.ca_file)); CM_RETURN_IFERR(cs_ssl_verify_file_stat(ssl_cfg.key_file)); CM_RETURN_IFERR(cs_ssl_verify_file_stat(ssl_cfg.cert_file)); - CM_RETURN_IFERR(cs_ssl_verify_file_stat(ssl_cfg.crl_file)); + // create fd if (mes_create_ssl_fd(&ssl_cfg) != CM_SUCCESS) { return CM_ERROR; @@ -1354,7 +1353,6 @@ static void mes_heartbeat_entry(thread_t *thread) char thread_name[CM_MAX_THREAD_NAME_LEN]; PRTS_RETVOID_IFERR(sprintf_s(thread_name, CM_MAX_THREAD_NAME_LEN, "mes_heartbeat_%u", inst_id)); cm_set_thread_name(thread_name); - cm_block_sighup_signal(); mes_context_t *mes_ctx = &MES_GLOBAL_INST_MSG.mes_ctx; uint64 periods = 0; @@ -1484,6 +1482,7 @@ int mes_init(mes_profile_t *profile) mes_init_stat(profile); MES_GLOBAL_INST_MSG.mes_ctx.phase = SHUTDOWN_PHASE_NOT_BEGIN; + MES_WAITS_INTERRUPTED = CM_FALSE; do { ret = cm_start_timer(g_timer()); if (ret != CM_SUCCESS) { @@ -2130,6 +2129,16 @@ void mes_discard_response(ruid_type ruid) cm_spin_unlock(&room->lock); } +void mes_interrupt_get_response(void) +{ + MES_WAITS_INTERRUPTED = CM_TRUE; +} + +void mes_resume_get_response(void) +{ + MES_WAITS_INTERRUPTED = CM_FALSE; +} + int mes_is_different_endian(inst_type dst_inst) { if (SECUREC_UNLIKELY(dst_inst >= MES_MAX_INSTANCES)) { diff --git a/src/cm_mes/mes_func.h b/src/cm_mes/mes_func.h index 36e26d487df05d154fda798c4dfb8feacd165069..34ed4be1ceb895ffa6ea7ac5b9bd115933f80d35 100644 --- a/src/cm_mes/mes_func.h +++ b/src/cm_mes/mes_func.h @@ -42,7 +42,6 @@ #include "mes_type.h" #include "mes_stat.h" #include "mes_task_threadpool_interface.h" -#include "cm_system.h" #ifdef __cplusplus extern "C" { @@ -65,6 +64,7 @@ extern "C" { #define MES_RUID_GET_RID(ruid) (((ruid_t *)&(ruid))->room_id) #define MES_RUID_IS_INVALID(ruid) ((ruid) == MES_INVLD_RUID) #define MES_RUID_IS_ILLEGAL(ruid) (MES_RUID_GET_RID(ruid) >= CM_MAX_MES_ROOMS) +#define MES_WAITS_INTERRUPTED MES_GLOBAL_INST_MSG.mes_ctx.waits_interrupted #define MES_LOG_WAR_HEAD_EX(head, message, room) \ do { \ @@ -259,6 +259,7 @@ typedef struct st_mes_context { receiver_t sender_monitor; shutdown_phase_t phase; + bool8 waits_interrupted; uint32 startLsnr : 1; uint32 startChannelsTh : 1; uint32 creatWaitRoom : 1; @@ -276,13 +277,6 @@ typedef struct st_mes_instance { mes_task_threadpool_t task_tpool; } mes_instance_t; -typedef struct st_mes_global_ptr { - mes_instance_t* mes_ptr; - mes_stat_t* cmd_count_stats_ptr; - mes_elapsed_stat_t* cmd_time_stats_ptr; - mes_msg_size_stats_t* cmd_size_stats_ptr; -} mes_global_ptr_t; - #define CHANNEL_ID_BITS (8) #define CHANNEL_ID_MASK (((unsigned)1 << CHANNEL_ID_BITS) - 1) // for ssl @@ -328,8 +322,132 @@ extern mes_callback_t g_cbb_mes_callback; bool32 mes_connection_ready(uint32 inst_id); int mes_send_bufflist(mes_bufflist_t *buff_list); + void mes_process_message(mes_msgqueue_t *my_queue, mes_message_t *msg); +typedef struct st_mes_command_stat { + union { + struct { + uint32 cmd; + int64 send_count; + int64 recv_count; + int64 local_count; + atomic32_t occupy_buf; + spinlock_t lock; + }; + char padding[CM_CACHE_LINE_SIZE]; + }; +} mes_command_stat_t; + +typedef struct st_mes_command_time_stat { + union { + struct { + uint64 time; + int64 count; + spinlock_t lock; + }; + char padding[CM_CACHE_LINE_SIZE]; + }; +}mes_command_time_stat_t; + +typedef struct st_mes_time_consume { + mes_command_time_stat_t cmd_time_stats[MES_TIME_CEIL]; + union { + uint32 cmd; + char aligned1[CM_CACHE_LINE_SIZE]; + }; +} mes_time_consume_t; + +typedef struct st_mes_elapsed_stat { + char aligned1[CM_CACHE_LINE_SIZE]; + union { + bool8 mes_elapsed_switch; + char aligned2[CM_CACHE_LINE_SIZE]; + }; + mes_time_consume_t time_consume_stat[CM_MAX_MES_MSG_CMD]; +} mes_elapsed_stat_t; + +typedef struct st_mes_stat { + char aligned1[CM_CACHE_LINE_SIZE]; + union { + bool8 mes_elapsed_switch; + char aligned2[CM_CACHE_LINE_SIZE]; + }; + mes_command_stat_t mes_command_stat[CM_MAX_MES_MSG_CMD]; +} mes_stat_t; + +#define CMD_SIZE_HISTOGRAM_COUNT 10 +#define CMD_SIZE_2_MIN_POWER 7 +#define CMD_SIZE_2_MAX_POWER 15 + +typedef struct st_size_histogram { + spinlock_t lock; + uint64 min_size; + uint64 max_size; + uint64 avg_size; + uint64 count; + char reserved[CM_CACHE_LINE_SIZE - sizeof(spinlock_t) - 4 * sizeof(uint64)]; +} size_histogram_t; + +typedef struct st_mes_msg_size_stats { + bool32 enable; + /* + * 0 -- 128B + * 1 -- 256B + * 2 -- 512B + * 3 -- 1KB + * 4 -- 2KB + * 5 -- 4KB + * 6 -- 8KB + * 7 -- 16KB + * 8 -- 32KB + * 9 -- > 32KB + */ + size_histogram_t histograms[CMD_SIZE_HISTOGRAM_COUNT]; +} mes_msg_size_stats_t; + +extern mes_elapsed_stat_t g_mes_elapsed_stat; +extern mes_stat_t g_mes_stat; +extern mes_msg_size_stats_t g_mes_msg_size_stat; + +typedef struct st_mes_global_ptr { + mes_instance_t* g_cbb_mes_ptr; + mes_stat_t* g_mes_stat_ptr; + mes_elapsed_stat_t* g_mes_elapsed_stat; + mes_msg_size_stats_t* g_mes_msg_size_stat_ptr; +} mes_global_ptr_t; + +status_t mes_verify_ssl_key_pwd(ssl_config_t *ssl_cfg, char *plain, uint32 size); + +static inline void mes_get_consume_time_start(uint64 *stat_time) +{ + if (g_mes_elapsed_stat.mes_elapsed_switch) { + *stat_time = cm_get_time_usec(); + } + return; +} + +static inline void mes_consume_with_time(uint32 cmd, mes_time_stat_t type, uint64 start_time) +{ + if (g_mes_elapsed_stat.mes_elapsed_switch) { + uint64 elapsed_time = cm_get_time_usec() - start_time; + cm_spin_lock(&(g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type].lock), NULL); + g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type].time += elapsed_time; + g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type].count++; + cm_spin_unlock(&(g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type].lock)); + cm_atomic_inc(&(g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type].count)); + } + return; +} + +static inline void mes_elapsed_stat(uint32 cmd, mes_time_stat_t type) +{ + if (g_mes_elapsed_stat.mes_elapsed_switch) { + cm_atomic_inc(&(g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type].count)); + } + return; +} + void mes_mutex_destroy(mes_mutex_t *mutex); int mes_mutex_create(mes_mutex_t *mutex); #ifndef WIN32 @@ -362,8 +480,6 @@ mes_channel_t *mes_get_active_send_channel(uint32 dest_id, uint32 caller_tid, ui void mes_destroy_all_broadcast_msg(); int mes_init_single_inst_broadcast_msg(unsigned int inst_id); int mes_ensure_inst_channel_exist(unsigned int inst_id); -status_t mes_verify_ssl_key_pwd(ssl_config_t *ssl_cfg, char *plain, uint32 size); - #ifdef __cplusplus } #endif diff --git a/src/cm_mes/mes_interface.h b/src/cm_mes/mes_interface.h index 281712f6c2c0077c6d87140a7fbb5d74defe6d15..270a2b5642fce2893da146c71bcf62fd04f40acd 100644 --- a/src/cm_mes/mes_interface.h +++ b/src/cm_mes/mes_interface.h @@ -94,15 +94,19 @@ typedef enum en_mes_priority_t { } mes_priority_t; typedef enum en_mes_time_stat { - MES_TIME_MSG_SEND = 0, // time of `send request message` - MES_TIME_MSG_RECV, // time of `recv response message`, it's not accurate - MES_TIME_WRITE_SOCKET, // time of `write message to socket`, similar to `MSG_SEND` - MES_TIME_GET_BUF, // time of `get appropriate buffer from free list` for receiving message - MES_TIME_READ_SOCKET, // time of `read message from socket`, it contains `GET_BUF` - MES_TIME_PUT_QUEUE, // time of `put message to queue` - MES_TIME_GET_QUEUE, // time of `get message from queue` - MES_TIME_QUEUE_PROC, // time of `process message` - MES_TIME_PUT_BUF, // time of `put buffer to free list` after message processed + MES_TIME_TEST_SEND = 0, + MES_TIME_SEND_IO, + MES_TIME_TEST_RECV, + MES_TIME_TEST_MULTICAST, + MES_TIME_TEST_MULTICAST_AND_WAIT, + MES_TIME_TEST_WAIT_AND_RECV, + MES_TIME_GET_BUF, + MES_TIME_READ_MES, + MES_TIME_PROC_FUN, + MES_TIME_PUT_QUEUE, + MES_TIME_GET_QUEUE, + MES_TIME_QUEUE_PROC, + MES_TIME_PUT_BUF, MES_TIME_CEIL } mes_time_stat_t; @@ -279,7 +283,6 @@ typedef struct st_mes_msg_pool_minimum_info { typedef void (*mes_thread_init_t)(unsigned char need_startup, char **reg_data); typedef void (*mes_thread_deinit_t)(); -typedef unsigned short (*mes_app_cmd_cb_t)(char *msg_buf); /* * @brief mes init @@ -416,13 +419,16 @@ int mes_send_response_x(inst_type dest_inst, flag_type flag, ruid_type ruid, uns * @return CM_SUCCESS - success;otherwise: failed */ int mes_get_response(ruid_type ruid, mes_msg_t* response, int timeout_ms); -int mes_get_response_ex(ruid_type ruid, mes_msg_t *response, int timeout_ms, void *arg); - -typedef int (*mes_interrupt_func)(void *arg, int wait_time); -void mes_register_interrupt(mes_interrupt_func func); void mes_release_msg(mes_msg_t* msg); +/* + * @brief mes_interrupt_get_response cancels all response waits, + * until mes_resume_get_response restores them + */ +void mes_interrupt_get_response(void); +void mes_resume_get_response(void); + /* * @brief Broadcast Message * @return @@ -443,7 +449,6 @@ int mes_broadcast_request_sp(inst_type* inst_list, unsigned int inst_count, int mes_broadcast_request_spx(inst_type* inst_list, unsigned int inst_count, flag_type flag, ruid_type* ruid, unsigned int count, ...); int mes_broadcast_get_response(ruid_type ruid, mes_msg_list_t* responses, int timeout_ms); -int mes_broadcast_get_response_ex(ruid_type ruid, mes_msg_list_t *responses, int timeout_ms, void *arg); void mes_release_msg_list(mes_msg_list_t* message_list); /* @@ -606,9 +611,6 @@ void mes_set_worker_init_cb(mes_thread_init_t callback); */ void mes_set_worker_deinit_cb(mes_thread_deinit_t callback); -void mes_set_app_cmd_cb(mes_app_cmd_cb_t callback); -mes_app_cmd_cb_t mes_get_app_cmd_cb(); - /* * @brief estimated total memory consumed by mes_init * @param profile - config value @@ -658,13 +660,6 @@ void mes_get_mem_usage_stat_row(mes_mem_stat_t mem_id, mes_mem_info_stat_t *mes_ int mes_get_message_pool_minimum_info(mes_profile_t *profile, unsigned char is_send, mes_msg_pool_minimum_info_t *minimum_info); - -/* - * @brief thread mask sighup signal. - * @return - */ -void mes_block_sighup_signal(); - #ifdef __cplusplus } #endif diff --git a/src/cm_mes/mes_interface_impl.c b/src/cm_mes/mes_interface_impl.c index 564c330d977611946ad4679e43a314b9e525b944..6a51fdb1a5652b1ee9eff4be50858f65b2b5752f 100644 --- a/src/cm_mes/mes_interface_impl.c +++ b/src/cm_mes/mes_interface_impl.c @@ -26,15 +26,6 @@ #define MES_ALLOC_ROOM_SLEEP_TIME 1000 -static uint16 mes_get_app_cmd(char *buff, uint8 cmd) -{ - mes_app_cmd_cb_t cb = mes_get_app_cmd_cb(); - if (cb == NULL) { - return (uint16)cmd; - } - return cb(buff); -} - static inline void mes_clean_broadcast_msg_ptr(mes_waiting_room_t *room) { for (uint32 inst_id = 0; inst_id < MES_MAX_INSTANCES; ++inst_id) { @@ -125,7 +116,7 @@ static inline unsigned long long mes_room_get_ruid(mes_waiting_room_t *room) static int mes_send_data_x_inner(mes_message_head_t *head, unsigned int count, va_list args) { - uint64 start_stat_time; + uint64 start_stat_time = 0; mes_bufflist_t buff_list; va_list apcopy; va_copy(apcopy, args); @@ -172,22 +163,13 @@ static int mes_send_data_x_inner(mes_message_head_t *head, unsigned int count, v return CM_ERROR; } - mes_app_cmd_cb_t cb = mes_get_app_cmd_cb(); - if (cb != NULL) { - if (buff_list.cnt > 1) { - head->app_cmd = mes_get_app_cmd(buff_list.buffers[1].buf, head->cmd); - } else { - head->app_cmd = CM_MAX_MES_MSG_CMD; - } - } - bool32 is_send = head->dst_inst == MES_MY_ID ? CM_FALSE : CM_TRUE; - start_stat_time = cm_get_time_usec(); + mes_get_consume_time_start(&start_stat_time); MES_RESET_COMPRESS_ALGORITHM_FLAG(head->flags); int ret = mes_put_buffer_list_queue(&buff_list, is_send); if (ret == CM_SUCCESS) { - mes_send_stat(head->app_cmd, head->size); - mes_consume_with_time(head->app_cmd, MES_TIME_MSG_SEND, start_stat_time); + mes_send_stat(head->cmd); + mes_consume_with_time(head->cmd, MES_TIME_TEST_SEND, start_stat_time); } return ret; } @@ -315,22 +297,7 @@ int mes_send_response_x(inst_type dest_inst, flag_type flag, ruid_type ruid, uns return ret; } -mes_interrupt_func g_mes_interrupt_func = NULL; - -void mes_register_interrupt(mes_interrupt_func func) -{ - g_mes_interrupt_func = func; -} - -int mes_interrupt(void *arg, int wait_time) -{ - if (g_mes_interrupt_func == NULL) { - return CM_FALSE; - } - return g_mes_interrupt_func(arg, wait_time); -} - -int mes_get_response_ex(ruid_type ruid, mes_msg_t* response, int timeout_ms, void *arg) +int mes_get_response(ruid_type ruid, mes_msg_t* response, int timeout_ms) { if (SECUREC_UNLIKELY(MES_GLOBAL_INST_MSG.profile.disable_request)) { LOG_RUN_ERR("[mes]disable_request = 1, no support send request and get response, func:mes_get_response"); @@ -339,7 +306,6 @@ int mes_get_response_ex(ruid_type ruid, mes_msg_t* response, int timeout_ms, voi MES_RETURN_IF_BAD_RUID(ruid); uint64 start_stat_time = cm_get_time_usec(); int32 wait_time = 0; - int interrupt = CM_FALSE; mes_message_t msg; mes_waiting_room_t *room = mes_ruid_get_room(ruid); CM_ASSERT(room != NULL); @@ -362,11 +328,11 @@ int mes_get_response_ex(ruid_type ruid, mes_msg_t* response, int timeout_ms, voi for (;;) { if (!mes_mutex_timed_lock(&room->mutex, MES_WAIT_TIMEOUT)) { wait_time += MES_WAIT_TIMEOUT; - interrupt = mes_interrupt(arg, wait_time); - if (wait_time >= timeout_ms || interrupt) { + if (wait_time >= timeout_ms || MES_WAITS_INTERRUPTED) { // when timeout the ack msg may reach, so need do some check and protect. mes_protect_when_timeout(room); - LOG_DYN_TRC_WAR("[MES][%llu][%d-%llu]RWT, INT=%d", ruid, room->room_index, room->rsn, interrupt); + LOG_DYN_TRC_WAR("[MES][%llu][%llu-%llu]RWT, INT=%u", + (uint64)ruid, (uint64)room->room_index, room->rsn, MES_WAITS_INTERRUPTED); mes_free_room(room); return ERR_MES_WAIT_OVERTIME; } @@ -395,16 +361,11 @@ int mes_get_response_ex(ruid_type ruid, mes_msg_t* response, int timeout_ms, voi } mes_free_room(room); - mes_consume_with_time((&msg)->head->app_cmd, MES_TIME_MSG_RECV, start_stat_time); + mes_consume_with_time((&msg)->head->cmd, MES_TIME_TEST_RECV, start_stat_time); return CM_SUCCESS; } -int mes_get_response(ruid_type ruid, mes_msg_t *response, int timeout_ms) -{ - return mes_get_response_ex(ruid, response, timeout_ms, NULL); -} - int mes_broadcast_x(flag_type flag, unsigned int count, ...) { MES_RETURN_IF_BAD_MSG_COUNT(count); @@ -536,7 +497,7 @@ int mes_broadcast_request_sp(inst_type* inst_list, unsigned int inst_count, return mes_broadcast_request_spx(inst_list, inst_count, flag, ruid, 1, msg_data, size); } -int mes_broadcast_get_response_ex(ruid_type ruid, mes_msg_list_t* responses, int timeout_ms, void *arg) +int mes_broadcast_get_response(ruid_type ruid, mes_msg_list_t* responses, int timeout_ms) { if (SECUREC_UNLIKELY(MES_GLOBAL_INST_MSG.profile.disable_request)) { LOG_RUN_ERR( @@ -545,7 +506,6 @@ int mes_broadcast_get_response_ex(ruid_type ruid, mes_msg_list_t* responses, int } MES_RETURN_IF_BAD_RUID(ruid); int32 wait_time = 0; - int interrupt = CM_FALSE; mes_waiting_room_t *room = mes_ruid_get_room(ruid); CM_ASSERT(room != NULL); @@ -555,12 +515,12 @@ int mes_broadcast_get_response_ex(ruid_type ruid, mes_msg_list_t* responses, int } if (!mes_mutex_timed_lock(&room->broadcast_mutex, MES_WAIT_TIMEOUT)) { wait_time += MES_WAIT_TIMEOUT; - interrupt = mes_interrupt(arg, wait_time); - if (wait_time >= timeout_ms || interrupt) { + if (wait_time >= timeout_ms || MES_WAITS_INTERRUPTED) { room->ack_count = 0; // invalid broadcast ack // when timeout the ack msg may reach, so need do some check and protect. mes_protect_when_brcast_timeout(room); - LOG_DYN_TRC_WAR("[MES][%llu][%d-%llu]RWT, INT=%d", ruid, room->room_index, room->rsn, interrupt); + LOG_DYN_TRC_WAR("[mes]room %hhu with rsn=%llu has timed out on brcast, INT=%u", + room->room_index, room->rsn - 1, MES_WAITS_INTERRUPTED); mes_free_room(room); return ERR_MES_WAIT_OVERTIME; } @@ -576,13 +536,3 @@ int mes_broadcast_get_response_ex(ruid_type ruid, mes_msg_list_t* responses, int return CM_SUCCESS; } - -int mes_broadcast_get_response(ruid_type ruid, mes_msg_list_t *responses, int timeout_ms) -{ - return mes_broadcast_get_response_ex(ruid, responses, timeout_ms, NULL); -} - -void mes_block_sighup_signal() -{ - cm_block_sighup_signal(); -} \ No newline at end of file diff --git a/src/cm_mes/mes_msg_pool.c b/src/cm_mes/mes_msg_pool.c index 56bf98edab5183732260f319249cac8da1f5f456..cb3e4b3cf036a337ef7a9c8b344b910a0e49649a 100644 --- a/src/cm_mes/mes_msg_pool.c +++ b/src/cm_mes/mes_msg_pool.c @@ -1113,6 +1113,15 @@ char *mes_alloc_buf_item_fc(uint32 len, bool32 is_send, uint32 dst_inst, mes_pri return mes_alloc_buf_item_inner(len, is_send, dst_inst, priority, CM_TRUE); } +static void mes_release_buf_stat(uint32 cmd) +{ + if (g_mes_stat.mes_elapsed_switch) { + cm_atomic32_dec(&(g_mes_stat.mes_command_stat[cmd].occupy_buf)); + mes_elapsed_stat(cmd, MES_TIME_PUT_BUF); + } + return; +} + void mes_free_buf_item(char *buffer) { if (buffer == NULL) { @@ -1145,7 +1154,7 @@ void mes_free_buf_item(char *buffer) queue = &priority_pool->queues[push % priority_pool->queue_num]; } - uint16 cmd = ((mes_message_head_t *)buffer)->app_cmd; + uint32 cmd = ((mes_message_head_t *)buffer)->cmd; uint32 buf_count = 0; mes_put_buf_item_to_queue(buf_item, queue, &buf_count); diff --git a/src/cm_mes/mes_queue.c b/src/cm_mes/mes_queue.c index f11aee1e59b0df8fbb90e862d6aa12352c1de09a..b5e455ffb7d87daf1e477444719b28ea3015a1f1 100644 --- a/src/cm_mes/mes_queue.c +++ b/src/cm_mes/mes_queue.c @@ -28,7 +28,6 @@ #include "mes_interface.h" #include "mec_adapter.h" #include "cm_hash.h" -#include "cm_system.h" typedef struct st_mes_compress_ctx_t { compress_t *compress_ctx[COMPRESS_CEIL]; @@ -721,10 +720,10 @@ int mes_put_msg_queue(mes_message_t *msg, bool32 is_send) return ERR_MES_ALLOC_MSGITEM_FAIL; } - mes_local_stat(msg->head->app_cmd); + mes_local_stat(msg->head->cmd); msgitem->msg.head = msg->head; msgitem->msg.buffer = msg->buffer; - msgitem->enqueue_time = cm_get_time_usec(); + msgitem->enqueue_time = g_timer()->monotonic_now; if (!is_send && ENABLE_MES_TASK_THREADPOOL) { mes_put_msgitem_to_threadpool(msgitem); @@ -821,18 +820,19 @@ void mes_send_proc(mes_msgitem_t *msgitem, uint32 work_idx) void mes_work_proc(mes_msgitem_t *msgitem, uint32 work_idx) { mes_msg_t app_msg; - uint64 start_stat_time; + uint64 start_stat_time = 0; + mes_get_consume_time_start(&start_stat_time); if (msgitem->msg.head->cmd == MES_CMD_SYNCH_ACK) { mes_notify_msg_recv(&msgitem->msg); } else { - mes_consume_with_time(msgitem->msg.head->app_cmd, MES_TIME_GET_QUEUE, msgitem->enqueue_time); - start_stat_time = cm_get_time_usec(); + mes_consume_with_time(msgitem->msg.head->cmd, MES_TIME_GET_QUEUE, start_stat_time); + mes_get_consume_time_start(&start_stat_time); app_msg.buffer = msgitem->msg.buffer + sizeof(mes_message_head_t); app_msg.size = msgitem->msg.head->size - (unsigned int)sizeof(mes_message_head_t); app_msg.src_inst = (unsigned int)msgitem->msg.head->src_inst; MES_GLOBAL_INST_MSG.proc(work_idx, msgitem->msg.head->ruid, &app_msg); - mes_consume_with_time(msgitem->msg.head->app_cmd, MES_TIME_QUEUE_PROC, start_stat_time); + mes_consume_with_time(msgitem->msg.head->cmd, MES_TIME_QUEUE_PROC, start_stat_time); mes_release_message_buf(&msgitem->msg); } } @@ -862,34 +862,6 @@ void mes_set_cur_msg_info(uint32 work_id, void *data, unsigned int size) memcpy_s(mq_ctx->work_thread_idx[work_id].data, sizeof(mq_ctx->work_thread_idx[work_id].data), data, size)); } -// Helper function to get message item from multiple queues -mes_msgitem_t* mes_get_msgitem_from_multiple_queues(mq_context_t *mq_ctx, mes_task_priority_t *task_priority, uint32 queue_num, uint32 *queue_id) { - *queue_id = task_priority->pop_cursor % queue_num; - uint32 start_task_idx = task_priority->start_task_idx; - if (*queue_id + start_task_idx >= MES_MAX_TASK_NUM) { - return NULL; - } - mes_msgitem_t *msgitem = mes_get_msgitem(&mq_ctx->tasks[*queue_id + start_task_idx].queue); - for (uint32 loop = 0; msgitem == NULL && loop < queue_num; loop++) { - *queue_id = (*queue_id + 1) % queue_num; - msgitem = mes_get_msgitem(&mq_ctx->tasks[*queue_id + start_task_idx].queue); - } - - return msgitem; -} - -/* - * when enable statistics, enqueue_time is real-time, - * but monotonic_now in timer is updated every 0.0ms (MES_DEFAULT_SLLP_TIME), - * so monotonic_now may be less than enqueu_time. - */ -bool8 message_wait_timeout(mes_msgitem_t *msgitem) -{ - uint64 now = g_timer()->monotonic_now; - return (now > msgitem->enqueue_time && - ((now - msgitem->enqueue_time) / MICROSECS_PER_MILLISEC >= MES_GLOBAL_INST_MSG.profile.max_wait_time)); -} - void mes_task_proc_inner(thread_t *thread) { task_arg_t *arg = (task_arg_t *)thread->argument; @@ -903,34 +875,46 @@ void mes_task_proc_inner(thread_t *thread) uint64 *get_msgitem_time = &arg->get_msgitem_time; uint64 *msg_ruid = &arg->msg_ruid; uint32 *src_inst = &arg->msg_src_inst; + mes_msgitem_t *msgitem; mes_msgqueue_t *my_queue = &mq_ctx->tasks[my_task_index].queue; mes_context_t *mes_ctx = (mes_context_t *)mq_ctx->mes_ctx; mes_msgqueue_t finished_msgitem_queue; mes_init_msgqueue(&finished_msgitem_queue); + mes_task_priority_t *task_priority = mes_get_task_priority(my_task_index, is_send); - if (task_priority == NULL) - return; - *priority_temp = task_priority->priority; + mes_priority_t priority = task_priority->priority; + *priority_temp = priority; *tid = cm_get_current_thread_id(); bool32 need_serial = MES_GLOBAL_INST_MSG.profile.need_serial; mes_pipe_type_t pipe_type = MES_GLOBAL_INST_MSG.profile.pipe_type; uint32 start_task_idx = task_priority->start_task_idx; uint32 task_num = task_priority->task_num; + uint32 loop = 0; uint32 queue_id = 0; bool32 is_empty = CM_FALSE; uint32 queue_num = task_num > MES_PRIORITY_TASK_QUEUE_NUM ? MES_PRIORITY_TASK_QUEUE_NUM : task_num; while (!thread->closed && mes_ctx->phase == SHUTDOWN_PHASE_NOT_BEGIN) { if (pipe_type != MES_TYPE_RDMA) { - is_empty = mes_is_empty_queue_count(mq_ctx, task_priority->priority); - if (is_empty && cm_event_timedwait(event, CM_SLEEP_1_FIXED) != CM_SUCCESS) { - continue; + is_empty = mes_is_empty_queue_count(mq_ctx, priority); + if (is_empty) { + if (cm_event_timedwait(event, CM_SLEEP_1_FIXED) != CM_SUCCESS) { + continue; + } } } - mes_msgitem_t *msgitem = need_serial ? - mes_get_msgitem(my_queue) : mes_get_msgitem_from_multiple_queues(mq_ctx, task_priority, queue_num, &queue_id); + if (!need_serial) { + queue_id = task_priority->pop_cursor % queue_num; + msgitem = mes_get_msgitem(&mq_ctx->tasks[queue_id + start_task_idx].queue); + for (loop = 0; msgitem == NULL && loop < queue_num; loop++) { + queue_id = (queue_id + 1) % queue_num; + msgitem = mes_get_msgitem(&mq_ctx->tasks[queue_id + start_task_idx].queue); + } + } else { + msgitem = mes_get_msgitem(my_queue); + } if (msgitem == NULL) { if (pipe_type == MES_TYPE_RDMA) { @@ -946,10 +930,13 @@ void mes_task_proc_inner(thread_t *thread) (head)->cmd, is_send, (uint64)head->ruid, (uint64)MES_RUID_GET_RID((head)->ruid), (uint64)MES_RUID_GET_RSN((head)->ruid), (head)->src_inst, (head)->dst_inst, (head)->size, (head)->flags, my_task_index, mq_ctx->tasks[queue_id + start_task_idx].queue.count, is_empty); - if (MES_GLOBAL_INST_MSG.profile.max_wait_time != CM_INVALID_INT32 && message_wait_timeout(msgitem)) { - LOG_DEBUG_WAR("[mes]proc wait timeout, message is discarded"); - mes_release_message_buf(&msgitem->msg); - continue; + if (MES_GLOBAL_INST_MSG.profile.max_wait_time != CM_INVALID_INT32) { + if ((g_timer()->monotonic_now - msgitem->enqueue_time) / MICROSECS_PER_MILLISEC >= + MES_GLOBAL_INST_MSG.profile.max_wait_time) { + LOG_DEBUG_WAR("[mes]proc wait timeout, message is discarded "); + mes_release_message_buf(&msgitem->msg); + continue; + } } *is_active = CM_TRUE; @@ -991,7 +978,6 @@ void mes_task_proc(thread_t *thread) PRTS_RETVOID_IFERR(sprintf_s(thread_name, CM_MAX_THREAD_NAME_LEN, "mes_worker_%u", my_task_index)); } cm_set_thread_name(thread_name); - cm_block_sighup_signal(); mes_thread_init_t cb_thread_init = mes_get_worker_init_cb(); if (!is_send && cb_thread_init != NULL) { diff --git a/src/cm_mes/mes_rdma_rpc.c b/src/cm_mes/mes_rdma_rpc.c index 0162c07d28b1762adaf208fa59da11b0fe9409ce..1abdcd6f2601129f007137eb042181f38e5a56d3 100644 --- a/src/cm_mes/mes_rdma_rpc.c +++ b/src/cm_mes/mes_rdma_rpc.c @@ -39,6 +39,8 @@ #include "mes_msg_pool.h" #include "mes_interface.h" #include "mes_metadata.h" +#include "mes_rpc_ulog4c.h" +#include "mes_rpc_openssl_dl.h" #include "mes_rpc_dl.h" #include "openssl/x509.h" #include "openssl/x509v3.h" @@ -66,7 +68,15 @@ typedef enum { #define PATH_LENGTH PATH_MAX #define OCK_RPC_ENV_PATH "OCK_RPC_LIB_PATH" -#define OCK_RPC_SO_NAME "libhcom4db.so" +#define ULOG_SO_NAME "libulog.so" +#define OCK_RPC_SO_NAME "librpc_ucx.so" + +// Ulog input param +#define ULOG_FILE_OUTPUT 1 +#define ULOG_ERR_LOG_LEVEL 4 +#define ULOG_DEFAULT_FILE_NAME "ockrpc.log" +#define ULOG_FILE_SIZE (1024 * 1024 * 10ULL) +#define ULOG_FILE_CNT 10 #define ERASE_FULL_1_NUM (0xff) #define ERASE_KEY_PASS_COUNT 30 @@ -136,6 +146,35 @@ static int mes_get_lib_path(char* rpcPath) return CM_SUCCESS; } +static int mes_init_ulog(void) +{ + char logPath[PATH_MAX] = {0}; + char *logPathPtr = logPath; + char path[PATH_MAX] = {0}; +#ifdef WIN32 + if (!_fullpath(path, MES_GLOBAL_INST_MSG.profile.ock_log_path, MES_MAX_LOG_PATH - 1)) { + LOG_RUN_ERR("_fullpath ock_log_path failed"); + return CM_ERROR; + } +#else + if (realpath(MES_GLOBAL_INST_MSG.profile.ock_log_path, path) == NULL) { + LOG_RUN_ERR("realpath ock_log_path failed"); + return CM_ERROR; + } +#endif + if (cm_access_file(path, F_OK | R_OK | W_OK) != CM_SUCCESS) { + LOG_RUN_ERR("access log path(%s) failed.", path); + return CM_ERROR; + } + int ret = snprintf_s(logPath, PATH_MAX, PATH_MAX - 1, "%s/%s", path, ULOG_DEFAULT_FILE_NAME); + if (ret < 0) { + LOG_RUN_ERR("snprintf path(%s) + filename(%s) failed", path, ULOG_DEFAULT_FILE_NAME); + return CM_ERROR; + } + + return ULOG_Init(ULOG_FILE_OUTPUT, ULOG_ERR_LOG_LEVEL, logPathPtr, ULOG_FILE_SIZE, ULOG_FILE_CNT); +} + static int mes_init_rdma_dlopen_so(void) { char rpcPath[PATH_LENGTH] = {0}; @@ -144,6 +183,19 @@ static int mes_init_rdma_dlopen_so(void) return CM_ERROR; } + // init ulog dlopen + char ockUlogDlPath[PATH_LENGTH] = {0}; + ret = snprintf_s(ockUlogDlPath, PATH_LENGTH, PATH_LENGTH - 1, "%s/%s", rpcPath, ULOG_SO_NAME); + if (ret < 0) { + LOG_RUN_ERR("construct ulog dl path failed, ret %d.", ret); + return CM_ERROR; + } + ret = InitUlogDl(ockUlogDlPath, PATH_LENGTH); + if (ret != CM_SUCCESS) { + LOG_RUN_ERR("mes init UlogDl failed."); + return CM_ERROR; + } + // init ockrpc dlopen char ockRpcDlPath[PATH_LENGTH] = {0}; ret = snprintf_s(ockRpcDlPath, PATH_LENGTH, PATH_LENGTH - 1, "%s/%s", rpcPath, OCK_RPC_SO_NAME); @@ -153,10 +205,28 @@ static int mes_init_rdma_dlopen_so(void) } ret = InitOckRpcDl(ockRpcDlPath, PATH_LENGTH); if (ret != CM_SUCCESS) { + FinishUlogDl(); LOG_RUN_ERR("mes init OckRpcDl failed."); return CM_ERROR; } + static bool32 ulog_init = CM_FALSE; + if (!ulog_init) { + ret = mes_init_ulog(); + if (ret != 0) { + LOG_RUN_ERR("ULog_Init failed, ret %d", ret); + FinishOckRpcDl(); + FinishUlogDl(); + return CM_ERROR; + } + ulog_init = CM_TRUE; + } + + if (OpensslDlopenAndSet((const char*)rpcPath) != DL_OPENSSL_OK) { + LOG_RUN_ERR("mes set ock openssl libpath failed."); + return CM_ERROR; + } + return CM_SUCCESS; } @@ -303,6 +373,7 @@ int mes_init_rdma_rpc_resource(void) mes_free_channel_msg_queue(CM_FALSE); mes_free_channels(); FinishOckRpcDl(); + FinishUlogDl(); LOG_RUN_ERR("mes init rdma rpc server failed."); return ret; } @@ -314,6 +385,7 @@ int mes_init_rdma_rpc_resource(void) mes_clear_rdma_rpc_server(); mes_free_channels(); FinishOckRpcDl(); + FinishUlogDl(); LOG_RUN_ERR("[mes]: reg rdma rpc proc func failed."); return ret; } @@ -588,10 +660,7 @@ static int mes_rdma_send_connect_protocode(uint32 inst_id, uint32_t channel_id) head.flags = 0; head.version = 0; - version_proto_code_t version_proto_code = { - .version = CS_LOCAL_VERSION, - .proto_code = CM_PROTO_CODE - }; + version_proto_code_t version_proto_code = {.version = CS_LOCAL_VERSION, .proto_code = CM_PROTO_CODE}; if (!IS_BIG_ENDIAN) { // Unified big-endian mode for VERSION version_proto_code.version = cs_reverse_uint32(version_proto_code.version); @@ -604,16 +673,13 @@ static int mes_rdma_send_connect_protocode(uint32 inst_id, uint32_t channel_id) } (void)memcpy_s(data, data_len, &head, sizeof(mes_message_head_t)); (void)memcpy_s(data + sizeof(mes_message_head_t), data_len, &version_proto_code, sizeof(version_proto_code_t)); - OckRpcMessage request = { - .data = (void*)data, - .len = data_len - }; - OckRpcMessage response = { 0 }; + OckRpcMessage request = {.data = (void*)data, .len = data_len}; + OckRpcMessage response = {0}; int ret = OckRpcClientCall(pipe->rdma_client.client_handle, RPC_CONNECTION_REQ, &request, &response, NULL); if (ret != OCK_RPC_OK) { LOG_RUN_ERR("RpcClientCall failed, RPC_CONNECTION_REQ message, inst_id(%u), channel_id(%u)", - inst_id, channel_id); + inst_id, channel_id); return CM_ERROR; } @@ -623,16 +689,9 @@ static int mes_rdma_send_connect_protocode(uint32 inst_id, uint32_t channel_id) free(response.data); } LOG_RUN_ERR("send connect protocode failed, recv ack size(%lu) != expect(%lu), inst_id(%u), channel_id(%u)", - response.len, sizeof(link_ready_ack_t), inst_id, channel_id); + response.len, sizeof(link_ready_ack_t), inst_id, channel_id); return CM_ERROR; } - - if (response.data == NULL) { - LOG_RUN_ERR("response data is null, recv ack size(%lu) != expect(%lu), inst_id(%u), channel_id(%u)", - response.len, sizeof(link_ready_ack_t), inst_id, channel_id); - return CM_ERROR; - } - link_ready_ack_t* ack = response.data; mes_set_pipe_ack(ack, &pipe->send_pipe); @@ -802,8 +861,6 @@ int mes_rdma_rpc_send_data(const void* msg_data) return ERR_MES_SENDPIPE_NO_READY; } - head->app_cmd = 0; - head->unused = 0; OckRpcClient client = pipe->rdma_client.client_handle; OckRpcMessage request = {.data = (void*)msg_data, .len = head->size}; @@ -864,8 +921,6 @@ int mes_rdma_rpc_send_bufflist(mes_bufflist_t *buff_list) return ERR_MES_SENDPIPE_NO_READY; } - head->app_cmd = 0; - head->unused = 0; OckRpcClientCallParams param; OckRpcMessage msgs[MES_MAX_BUFFERLIST]; init_ockrpc_client_iov_param(¶m, buff_list, msgs, pipe->rdma_client.client_handle); @@ -974,7 +1029,7 @@ void mes_ockrpc_tls_get_private_key(const char** privateKeyPath, char** keypass, // verify ssl key password and KMC module if (mes_verify_ssl_key_pwd(&ssl_cfg, passwd_plain, CM_PASSWD_MAX_LEN) != CM_SUCCESS) { LOG_RUN_ERR("CBB verify ssl key password failed"); - (void)memset_s(passwd_plain, max_passwd_size, 0, max_passwd_size); + (void)memset_s(passwd_plain, sizeof(passwd_plain), 0, sizeof(passwd_plain)); free(passwd_plain); *privateKeyPath = NULL; *keypass = NULL; diff --git a/src/cm_mes/mes_recv.c b/src/cm_mes/mes_recv.c index 17069262464cf1e3e6ba3cd17b78e7df31f0cc37..53d97a0ea4f36d3b91ce1c353f3ca504c014d6e4 100644 --- a/src/cm_mes/mes_recv.c +++ b/src/cm_mes/mes_recv.c @@ -28,7 +28,6 @@ #include "mes_recv.h" #include "mes_interface.h" #include "mes_func.h" -#include "cm_system.h" typedef union un_ev_data { struct { @@ -234,7 +233,6 @@ static void mes_recv_proc(thread_t *thread) struct epoll_event events[CM_MES_MAX_CHANNEL_NUM]; ev_data_t ev_data; char thread_name[CM_MAX_THREAD_NAME_LEN]; - cm_block_sighup_signal(); PRTS_RETVOID_IFERR( sprintf_s(thread_name, CM_MAX_THREAD_NAME_LEN, "mes_recv_%u_%u", receiver->priority, receiver->id)); diff --git a/src/cm_mes/mes_rpc_openssl_dl.c b/src/cm_mes/mes_rpc_openssl_dl.c new file mode 100644 index 0000000000000000000000000000000000000000..349439ee26a1eed37cd5e04b2cf530ce4c8a6e08 --- /dev/null +++ b/src/cm_mes/mes_rpc_openssl_dl.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 Huawei Technologies Co.,Ltd. + * + * CBB is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * ------------------------------------------------------------------------- + * + * mes_rpc_openssl_dl.c + * + * + * IDENTIFICATION + * src/cm_mes/mes_rpc_openssl_dl.c + * + * ------------------------------------------------------------------------- + */ +#include "cm_log.h" +#include "cm_utils.h" +#include "cm_file.h" +#include "mes_rpc_openssl_dl.h" + +typedef int (*SetOpensslLibPath)(const char *ssl, const char *crypto); + +#define SSL_SO_NAME "libssl.so" +#define CRYPTO_SO_NAME "libcrypto.so" +#define OPENSSL_DL_SO_NAME "libopenssl_dl.so" +#define PATH_LENGTH PATH_MAX + + +int OpensslDlopenAndSet(const char* path) +{ + char opensslPath[PATH_LENGTH] = {0}; + char* opensslPathPtr = opensslPath; + int ret = snprintf_s(opensslPath, PATH_LENGTH, PATH_LENGTH - 1, "%s/%s", path, OPENSSL_DL_SO_NAME); + if (ret < 0) { + LOG_RUN_ERR("construct opensslPath failed, ret %d.", ret); + return DL_OPENSSL_ERROR; + } + char ockSslPath[PATH_LENGTH] = {0}; + ret = snprintf_s(ockSslPath, PATH_LENGTH, PATH_LENGTH - 1, "%s/%s", path, SSL_SO_NAME); + if (ret < 0) { + LOG_RUN_ERR("construct ockSslPath failed, ret %d.", ret); + return DL_OPENSSL_ERROR; + } + char ockCryptoPath[PATH_LENGTH] = {0}; + ret = snprintf_s(ockCryptoPath, PATH_LENGTH, PATH_LENGTH - 1, "%s/%s", path, CRYPTO_SO_NAME); + if (ret < 0) { + LOG_RUN_ERR("construct ockCryptoPath failed, ret %d.", ret); + return DL_OPENSSL_ERROR; + } + + void* opensslDl; + ret = cm_open_dl(&opensslDl, opensslPathPtr); + if (ret != CM_SUCCESS) { + LOG_RUN_ERR("dlopen openssl_dl error, path(%s)", opensslPathPtr); + return DL_OPENSSL_ERROR; + } + + SetOpensslLibPath setPath; + ret = cm_load_symbol(opensslDl, "SetOpensslDLopenLibPath", (void**)&setPath); + if (ret != CM_SUCCESS) { + cm_close_dl(opensslDl); + LOG_RUN_ERR("dlsym SetOpensslDLopenLibPath error"); + return DL_OPENSSL_ERROR; + } + + ret = setPath(ockSslPath, ockCryptoPath); + if (ret != DL_OPENSSL_OK) { + cm_close_dl(opensslDl); + LOG_RUN_ERR("call SetOpensslDLopenLibPath error"); + return DL_OPENSSL_ERROR; + } + + cm_close_dl(opensslDl); + return DL_OPENSSL_OK; +} \ No newline at end of file diff --git a/src/cm_mes/mes_rpc_openssl_dl.h b/src/cm_mes/mes_rpc_openssl_dl.h new file mode 100644 index 0000000000000000000000000000000000000000..aec9e6bf2f30125d97a5402f4c51b00b34790ee6 --- /dev/null +++ b/src/cm_mes/mes_rpc_openssl_dl.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 Huawei Technologies Co.,Ltd. + * + * CBB is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * ------------------------------------------------------------------------- + * + * mes_rpc_openssl_dl.h + * + * + * IDENTIFICATION + * src/cm_mes/mes_rpc_openssl_dl.h + * + * ------------------------------------------------------------------------- + */ +#ifndef OCK_OPENSSL_DL_H +#define OCK_OPENSSL_DL_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +static const int DL_OPENSSL_ERROR = -1; +static const int DL_OPENSSL_OK = 1; + +/** + * @brief get the path of libssl.so and libctypto.so of special version of OPENSSL (1.1.1k) + * + * @param path the folder path where libopenssl.so is located + * + * @return DL_OPENSSL_OK for success, DL_OPENSSL_ERROR for failed. + */ +int OpensslDlopenAndSet(const char* path); + +/** + * @brief get the path of libssl.so and libctypto.so of special version of OPENSSL (1.1.1k) + * + * @param ssl the path of libssl.so + * @param crypto the path of libcrypto.so + * + * @return DL_OPENSSL_OK for success, DL_OPENSSL_ERROR for failed. + */ +int SetOpensslDLopenLibPath(const char *ssl, const char *crypto); + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/cm_mes/mes_rpc_ulog4c.h b/src/cm_mes/mes_rpc_ulog4c.h new file mode 100644 index 0000000000000000000000000000000000000000..2607f053f0a2dcd6e9ece3eb641d6adf3f1b19ac --- /dev/null +++ b/src/cm_mes/mes_rpc_ulog4c.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Huawei Technologies Co.,Ltd. + * + * CBB is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * ------------------------------------------------------------------------- + * + * mes_rpc_ulog4c.h + * + * + * IDENTIFICATION + * src/cm_mes/mes_rpc_ulog4c.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PLATFORM_UTILITIES_REMOTE_ULOG_H +#define PLATFORM_UTILITIES_REMOTE_ULOG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief initialize the normal ulog + * + * @param logType - [IN] type of the ulog, could 0 or 1; 0: stdout, 1: file + * @param minLogLevel - [IN] min level of message, 0:trace, 1:debug, 2:info, 3:warn, 4:error, 5:critical + * @param path - [IN] full path of ulog file name + * @param rotationFileSize - [IN] the max file size of a single rotation file + * @param rotationFileSize - [IN] the max count of total rotated file + * + * @return 0 for success, non zero for failure + */ +int ULOG_Init(int logType, int minLogLevel, const char *path, int rotationFileSize, int rotationFileCount); + +int InitUlogDl(char* path, unsigned int len); +void FinishUlogDl(void); + +#if defined(__cplusplus) +} +#endif + +#endif // PLATFORM_UTILITIES_REMOTE_ULOG_H diff --git a/src/cm_mes/mes_rpc_ulog4c_dl.c b/src/cm_mes/mes_rpc_ulog4c_dl.c new file mode 100644 index 0000000000000000000000000000000000000000..cb62bccc8558d6bcde968d050c6b2133bb7ddbbe --- /dev/null +++ b/src/cm_mes/mes_rpc_ulog4c_dl.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022 Huawei Technologies Co.,Ltd. + * + * CBB is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * ------------------------------------------------------------------------- + * + * mes_rpc_ulog4c_dl.c + * + * + * IDENTIFICATION + * src/cm_mes/mes_rpc_ulog4c_dl.c + * + * ------------------------------------------------------------------------- + */ +#include "cm_defs.h" +#include "cm_log.h" +#include "cm_utils.h" + +typedef int (*ULOGDL_Init)(int logType, int minLogLevel, const char *path, int rotationFileSize, int rotationFileCount); + +typedef struct UlogFunc { + ULOGDL_Init init; +} UlogFuncPtr; + +void* g_ulogDl = NULL; +UlogFuncPtr g_ulogFunc; + +#define RETURN_OK 0 +#define RETURN_ERR (-1) + +int InitUlogDl(char* path, unsigned int len) +{ + if (path == NULL || len == 0) { + LOG_RUN_ERR("ulog path is nullptr"); + return RETURN_ERR; + } + + int ret = RETURN_OK; + if (g_ulogDl != NULL) { + return RETURN_OK; + } + + ret = cm_open_dl(&g_ulogDl, path); + if (ret != CM_SUCCESS) { + LOG_RUN_ERR("dlopen ulog error"); + return RETURN_ERR; + } + + ret = cm_load_symbol(g_ulogDl, "ULOG_Init", (void**)&g_ulogFunc.init); + if (ret != CM_SUCCESS) { + return RETURN_ERR; + } + + return ret; +} + +void FinishUlogDl(void) +{ + if (g_ulogDl != NULL) { + cm_close_dl(g_ulogDl); + g_ulogDl = NULL; + } + + if (memset_sp(&g_ulogFunc, sizeof(g_ulogFunc), 0, sizeof(g_ulogFunc)) != EOK) { + LOG_RUN_ERR("memset_sp failed"); + } +} + +int ULOG_Init(int logType, int minLogLevel, const char *path, int rotationFileSize, int rotationFileCount) +{ + int ret; + if (g_ulogFunc.init != NULL) { + ret = g_ulogFunc.init(logType, minLogLevel, path, rotationFileSize, rotationFileCount); + } else { + ret = RETURN_ERR; + } + return ret; +} \ No newline at end of file diff --git a/src/cm_mes/mes_stat.c b/src/cm_mes/mes_stat.c index fed555394285a3ecff8c3c5f9a0d6dfbac8ffd94..ec3ca34bf0fc9151b3407937e10ac855b4b0dc7e 100644 --- a/src/cm_mes/mes_stat.c +++ b/src/cm_mes/mes_stat.c @@ -21,8 +21,6 @@ * * ------------------------------------------------------------------------- */ -#include "cm_atomic.h" -#include "cm_spinlock.h" #include "mes_func.h" #include "mes_stat.h" @@ -113,28 +111,17 @@ void mes_init_stat(const mes_profile_t *profile) return; } -void mes_send_stat(uint16 cmd, uint32 size) +void mes_send_stat(uint32 cmd) { - if (g_mes_stat.mes_elapsed_switch && cmd < CM_MAX_MES_MSG_CMD) { - mes_command_stat_t *stats = &g_mes_stat.mes_command_stat[cmd]; - cm_spin_lock(&stats->lock, NULL); - uint64 avg = stats->avg_size; - if (avg == 0 || avg == size) { - stats->avg_size = size; - } else { - double f1 = 1.0 / (stats->send_count + 1); - double f2 = (stats->send_count) * f1; - stats->avg_size = (uint64)(avg * f2 + size * f1); - } - (void)cm_atomic_inc(&(stats->send_count)); - cm_spin_unlock(&stats->lock); + if (g_mes_stat.mes_elapsed_switch) { + (void)cm_atomic_inc(&(g_mes_stat.mes_command_stat[cmd].send_count)); } return; } -void mes_local_stat(uint16 cmd) +void mes_local_stat(uint32 cmd) { - if (g_mes_stat.mes_elapsed_switch && cmd < CM_MAX_MES_MSG_CMD) { + if (g_mes_stat.mes_elapsed_switch) { (void)cm_atomic_inc(&(g_mes_stat.mes_command_stat[cmd].local_count)); (void)cm_atomic32_inc(&(g_mes_stat.mes_command_stat[cmd].occupy_buf)); } @@ -143,32 +130,48 @@ void mes_local_stat(uint16 cmd) void mes_recv_message_stat(const mes_message_t *msg) { - if (g_mes_stat.mes_elapsed_switch && msg->head->app_cmd < CM_MAX_MES_MSG_CMD) { - (void)cm_atomic_inc(&(g_mes_stat.mes_command_stat[msg->head->app_cmd].recv_count)); - (void)cm_atomic32_inc(&(g_mes_stat.mes_command_stat[msg->head->app_cmd].occupy_buf)); + if (g_mes_stat.mes_elapsed_switch) { + (void)cm_atomic_inc(&(g_mes_stat.mes_command_stat[msg->head->cmd].recv_count)); + (void)cm_atomic32_inc(&(g_mes_stat.mes_command_stat[msg->head->cmd].occupy_buf)); } return; } -uint64 cm_get_time_usec() +static void cm_get_time_of_day(cm_timeval *tv) +{ + (void)cm_gettimeofday(tv); +} + +uint64 cm_get_time_usec(void) { if (g_mes_elapsed_stat.mes_elapsed_switch) { - return cm_clock_monotonic_now(); + cm_timeval now; + uint64 now_usec; + cm_get_time_of_day(&now); + now_usec = (uint64)now.tv_sec * MICROSECS_PER_SECOND + (uint64)now.tv_usec; + return now_usec; } - return g_timer()->monotonic_now; + return 0; } -void mes_consume_with_time(uint16 cmd, mes_time_stat_t type, uint64 start_time) +uint64 mes_get_stat_send_count(unsigned int cmd) { - if (g_mes_elapsed_stat.mes_elapsed_switch && cmd < CM_MAX_MES_MSG_CMD) { - uint64 elapsed_time = cm_get_time_usec() - start_time; - mes_command_time_stat_t *stats = &g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type]; - cm_spin_lock(&stats->lock, NULL); - stats->time += elapsed_time; - stats->count++; - cm_spin_unlock(&stats->lock); - } - return; + return (uint64)g_mes_stat.mes_command_stat[cmd].send_count; +} + +uint64 mes_get_stat_recv_count(unsigned int cmd) +{ + return (uint64)g_mes_stat.mes_command_stat[cmd].recv_count; +} + +volatile long mes_get_stat_occupy_buf(unsigned int cmd) +{ + return g_mes_stat.mes_command_stat[cmd].occupy_buf; +} + +unsigned char mes_get_elapsed_switch(void) +{ + return (bool8)g_mes_elapsed_stat.mes_elapsed_switch; } void mes_set_elapsed_switch(unsigned char elapsed_switch) @@ -177,6 +180,32 @@ void mes_set_elapsed_switch(unsigned char elapsed_switch) g_mes_stat.mes_elapsed_switch = elapsed_switch; } +uint64 mes_get_elapsed_time(unsigned int cmd, mes_time_stat_t type) +{ + return g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type].time; +} + +uint64 mes_get_elapsed_count(unsigned int cmd, mes_time_stat_t type) +{ + return (uint64)g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type].count; +} + +void mes_get_wait_event(unsigned int cmd, unsigned long long *event_cnt, unsigned long long *event_time) +{ + unsigned long long cnt = 0; + unsigned long long time = 0; + for (int type = 0; type < MES_TIME_CEIL; ++type) { + cnt += g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type].count; + time += g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type].time; + } + if (event_cnt != NULL) { + *event_cnt = cnt; + } + if (event_time != NULL) { + *event_time = time; + } +} + #ifdef WIN32 static uint32 cmd_size_to_histogram_index(uint32 size) { @@ -227,37 +256,4 @@ void mes_msg_size_stats(uint32 size) hist->count++; cm_spin_unlock(&hist->lock); } -} - -void mes_elapsed_stat(uint16 cmd, mes_time_stat_t type) -{ - if (g_mes_elapsed_stat.mes_elapsed_switch && cmd < CM_MAX_MES_MSG_CMD) { - cm_atomic_inc(&(g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type].count)); - } - return; -} - -void mes_release_buf_stat(uint16 cmd) -{ - if (g_mes_stat.mes_elapsed_switch && cmd < CM_MAX_MES_MSG_CMD) { - cm_atomic32_dec(&(g_mes_stat.mes_command_stat[cmd].occupy_buf)); - mes_elapsed_stat(cmd, MES_TIME_PUT_BUF); - } - return; -} - -void mes_get_wait_event(unsigned int cmd, unsigned long long *event_cnt, unsigned long long *event_time) -{ - unsigned long long cnt = 0; - unsigned long long time = 0; - for (int type = 0; type < MES_TIME_CEIL; ++type) { - cnt += g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type].count; - time += g_mes_elapsed_stat.time_consume_stat[cmd].cmd_time_stats[type].time; - } - if (event_cnt != NULL) { - *event_cnt = cnt; - } - if (event_time != NULL) { - *event_time = time; - } } \ No newline at end of file diff --git a/src/cm_mes/mes_stat.h b/src/cm_mes/mes_stat.h index 9469332e96ca6e8a3fe832ba27df62112cc4e998..739552e20dca0559088330abf5086772eee91c80 100644 --- a/src/cm_mes/mes_stat.h +++ b/src/cm_mes/mes_stat.h @@ -32,102 +32,14 @@ extern "C" { #endif -typedef struct st_mes_command_stat { - union { - struct { - uint32 cmd; - int64 send_count; - int64 recv_count; - int64 local_count; - atomic32_t occupy_buf; - uint64 avg_size; - spinlock_t lock; - }; - char padding[CM_CACHE_LINE_SIZE]; - }; -} mes_command_stat_t; - -typedef struct st_mes_command_time_stat { - union { - struct { - uint64 time; - int64 count; - spinlock_t lock; - }; - char padding[CM_CACHE_LINE_SIZE]; - }; -}mes_command_time_stat_t; - -typedef struct st_mes_time_consume { - mes_command_time_stat_t cmd_time_stats[MES_TIME_CEIL]; - union { - uint32 cmd; - char aligned1[CM_CACHE_LINE_SIZE]; - }; -} mes_time_consume_t; - -typedef struct st_mes_elapsed_stat { - char aligned1[CM_CACHE_LINE_SIZE]; - union { - bool8 mes_elapsed_switch; - char aligned2[CM_CACHE_LINE_SIZE]; - }; - mes_time_consume_t time_consume_stat[CM_MAX_MES_MSG_CMD]; -} mes_elapsed_stat_t; - -typedef struct st_mes_stat { - char aligned1[CM_CACHE_LINE_SIZE]; - union { - bool8 mes_elapsed_switch; - char aligned2[CM_CACHE_LINE_SIZE]; - }; - mes_command_stat_t mes_command_stat[CM_MAX_MES_MSG_CMD]; -} mes_stat_t; - -#define CMD_SIZE_HISTOGRAM_COUNT 10 -#define CMD_SIZE_2_MIN_POWER 7 -#define CMD_SIZE_2_MAX_POWER 15 - -typedef struct st_size_histogram { - spinlock_t lock; - uint64 min_size; - uint64 max_size; - uint64 avg_size; - uint64 count; - char reserved[CM_CACHE_LINE_SIZE - sizeof(spinlock_t) - 4 * sizeof(uint64)]; -} size_histogram_t; - -typedef struct st_mes_msg_size_stats { - bool32 enable; - /* - * 0 -- 128B - * 1 -- 256B - * 2 -- 512B - * 3 -- 1KB - * 4 -- 2KB - * 5 -- 4KB - * 6 -- 8KB - * 7 -- 16KB - * 8 -- 32KB - * 9 -- > 32KB - */ - size_histogram_t histograms[CMD_SIZE_HISTOGRAM_COUNT]; -} mes_msg_size_stats_t; - -extern mes_elapsed_stat_t g_mes_elapsed_stat; -extern mes_stat_t g_mes_stat; -extern mes_msg_size_stats_t g_mes_msg_size_stat; - void mes_init_stat(const mes_profile_t *profile); -void mes_send_stat(uint16 cmd, uint32 size); +void mes_send_stat(uint32 cmd); void mes_recv_message_stat(const mes_message_t *msg); -void mes_local_stat(uint16 cmd); -void mes_elapsed_stat(uint16 cmd, mes_time_stat_t type); -void mes_release_buf_stat(uint16 cmd); -uint64 cm_get_time_usec(); -void mes_consume_with_time(uint16 cmd, mes_time_stat_t type, uint64 start_time); -void mes_msg_size_stats(uint32 size); + +uint64 cm_get_time_usec(void); +void mes_local_stat(uint32 cmd); void mes_get_wait_event(unsigned int cmd, unsigned long long *event_cnt, unsigned long long *event_time); +void mes_msg_size_stats(uint32 size); #ifdef __cplusplus } diff --git a/src/cm_mes/mes_tcp.c b/src/cm_mes/mes_tcp.c index 6b0cde9cfe95b70c9dda285f1e2c6e7d7a4d1430..154a8ae2291f314271d584b371a5f65520392ada 100644 --- a/src/cm_mes/mes_tcp.c +++ b/src/cm_mes/mes_tcp.c @@ -96,7 +96,8 @@ static int mes_read_message_head(cs_pipe_t *pipe, mes_message_head_t *head) static int mes_get_message_buf(mes_message_t *msg, const mes_message_head_t *head) { - uint64 stat_time = cm_get_time_usec(); + uint64 stat_time = 0; + mes_get_consume_time_start(&stat_time); char *msg_buf; uint32 size = head->size; if (MES_COMPRESS_ALGORITHM(head->flags)) { @@ -111,7 +112,7 @@ static int mes_get_message_buf(mes_message_t *msg, const mes_message_head_t *hea return ERR_MES_ALLOC_MSGITEM_FAIL; } MES_MESSAGE_ATTACH(msg, msg_buf); - mes_consume_with_time(head->app_cmd, MES_TIME_GET_BUF, stat_time); + mes_consume_with_time(head->cmd, MES_TIME_GET_BUF, stat_time); return CM_SUCCESS; } @@ -155,7 +156,7 @@ static status_t check_recv_head_info(const mes_message_head_t *head, mes_priorit // receive static int mes_process_event(mes_pipe_t *pipe) { - uint64 stat_time; + uint64 stat_time = 0; mes_message_t msg; mes_message_head_t head; @@ -175,7 +176,7 @@ static int mes_process_event(mes_pipe_t *pipe) return mec_process_event(pipe); } - stat_time = cm_get_time_usec(); + mes_get_consume_time_start(&stat_time); int ret = mes_read_message_head(&pipe->recv_pipe, &head); if (ret != CM_SUCCESS) { @@ -217,7 +218,7 @@ static int mes_process_event(mes_pipe_t *pipe) return ERR_MES_SOCKET_FAIL; } - mes_consume_with_time(msg.head->app_cmd, MES_TIME_READ_SOCKET, stat_time); + mes_consume_with_time(msg.head->cmd, MES_TIME_READ_MES, stat_time); (void)cm_atomic_inc(&(pipe->recv_count)); @@ -304,8 +305,6 @@ void mes_tcp_try_connect(uintptr_t pipePtr) char buf[sizeof(mes_message_head_t)]; mes_message_head_t *head = (mes_message_head_t *)buf; head->cmd = MES_CMD_CONNECT; - head->app_cmd = 0; - head->unused = 0; head->dst_inst = MES_INSTANCE_ID(pipe->channel->id); head->src_inst = MES_GLOBAL_INST_MSG.profile.inst_id; head->caller_tid = MES_CHANNEL_ID(pipe->channel->id); // use caller_tid to represent channel id @@ -873,11 +872,6 @@ int mes_init_tcp_resource(void) return CM_SUCCESS; } -static bool32 is_old_mes_cmd(int32 version) -{ - return version < CS_VERSION_6; -} - // send int mes_tcp_send_data(const void *msg_data) { @@ -910,7 +904,7 @@ int mes_tcp_send_data(const void *msg_data) return ERR_MES_SENDPIPE_NO_READY; } - stat_time = cm_get_time_usec(); + mes_get_consume_time_start(&stat_time); if (head->cmd == MES_CMD_SYNCH_ACK) { CM_ASSERT(MES_RUID_GET_RSN((head)->ruid) != 0); } @@ -928,10 +922,6 @@ int mes_tcp_send_data(const void *msg_data) } if (!is_old_mec_version(version)) { - if (is_old_mes_cmd(version)) { - head->app_cmd = 0; - head->unused = 0; - } ret = cs_send_fixed_size(&pipe->send_pipe, (char *)msg_data, (int32)head->size); } else { mec_message_head_adapter_t *mec_head = @@ -951,7 +941,7 @@ int mes_tcp_send_data(const void *msg_data) } pipe->last_send_time = g_timer()->monotonic_now; - mes_consume_with_time(head->app_cmd, MES_TIME_WRITE_SOCKET, stat_time); + mes_consume_with_time(head->cmd, MES_TIME_SEND_IO, stat_time); cm_rwlock_unlock(&pipe->send_lock); (void)cm_atomic_inc(&(pipe->send_count)); @@ -993,8 +983,7 @@ int mes_tcp_send_bufflist(mes_bufflist_t *buff_list) head->dst_inst, priority); return ERR_MES_SENDPIPE_NO_READY; } - - stat_time = cm_get_time_usec(); + mes_get_consume_time_start(&stat_time); if (head->cmd == MES_CMD_SYNCH_ACK) { CM_ASSERT(MES_RUID_GET_RSN((head)->ruid) != 0); @@ -1015,11 +1004,6 @@ int mes_tcp_send_bufflist(mes_bufflist_t *buff_list) buff_list->buffers[0].buf = buff_list->buffers[0].buf + sizeof(mes_message_head_t); buff_list->buffers[0].len = buff_list->buffers[0].len - (unsigned int)sizeof(mes_message_head_t); } - - if (is_old_mes_cmd(version)) { - head->app_cmd = 0; - head->unused = 0; - } if (pipe->msgbuf == NULL) { pipe->msgbuf = (char *)cm_malloc_prot(totalsz); @@ -1065,7 +1049,7 @@ int mes_tcp_send_bufflist(mes_bufflist_t *buff_list) } pipe->last_send_time = g_timer()->monotonic_now; - mes_consume_with_time(head->app_cmd, MES_TIME_WRITE_SOCKET, stat_time); + mes_consume_with_time(head->cmd, MES_TIME_SEND_IO, stat_time); cm_rwlock_unlock(&pipe->send_lock); (void)cm_atomic_inc(&(pipe->send_count)); diff --git a/src/cm_mes/mes_type.h b/src/cm_mes/mes_type.h index 01c62b777c00a7948a3ebfb0157e2e548274b2e4..9cb8cfd01f83449fae7a4f73e57c8bceafdef4bb 100644 --- a/src/cm_mes/mes_type.h +++ b/src/cm_mes/mes_type.h @@ -45,9 +45,7 @@ typedef unsigned long long uint64; typedef struct st_mes_message_head { unsigned int version; - unsigned int cmd : 8; // mes command - unsigned int app_cmd : 16; // upper application command - unsigned int unused : 8; + unsigned int cmd; unsigned int flags; unsigned int caller_tid; unsigned long long ruid; @@ -106,9 +104,7 @@ typedef struct st_mes_bufflist { #define MES_INIT_MESSAGE_HEAD(head, v_version, v_cmd, v_flags, v_src_inst, v_dst_inst, v_ruid, v_size) \ do { \ - (head)->cmd = (uint32)(v_cmd); \ - (head)->app_cmd = 0; \ - (head)->unused = 0; \ + (head)->cmd = (uint32)(v_cmd); \ (head)->version = (uint32)(v_version); \ (head)->flags = (uint32)(v_flags); \ (head)->src_inst = (uint32)(v_src_inst); \ diff --git a/src/cm_network/cm_ip.c b/src/cm_network/cm_ip.c index 11a22cc8ae25371a44d7b0b808337a1dda0b3d4d..4ddbc4f4346e37273502cc94c3a8da195f0b2ded 100644 --- a/src/cm_network/cm_ip.c +++ b/src/cm_network/cm_ip.c @@ -185,43 +185,6 @@ bool32 cm_check_ip_valid(const char *ip) return CM_TRUE; } -status_t cm_get_host_type(const char *host, host_type_t *type) -{ - if (CM_IS_DIGIT(host[0])) { - int ip_type = cm_get_ip_version(host); - CM_RETVALUE_IFTRUE(ip_type == -1, CM_ERROR); - *type = (ip_type == AF_INET ? HOST_TYPE_IP_V4 : HOST_TYPE_IP_V6); - } else { - if (strchr(host, ':') != NULL) { - CM_RETVALUE_IFTRUE(cm_get_ip_version(host) != AF_INET6, CM_ERROR); - *type = HOST_TYPE_IP_V6; - } else { - // domain string -#define DOMAIN_CHARS "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-" - CM_RETVALUE_IFTRUE(strspn(host, DOMAIN_CHARS) != strlen(host), CM_ERROR); - *type = HOST_TYPE_DOMAIN; - } - } - return CM_SUCCESS; -} - -static bool32 cm_check_ss_ip(text_t *ip, char *ip_str) -{ - host_type_t type; - if (ip->len == 0 || ip->len >= CM_MAX_IP_LEN) { - CM_THROW_ERROR(ERR_INVALID_IPADDRESS_OR_DOMAIN_LENGTH, ip->len); - return CM_FALSE; - } - if (cm_get_host_type(ip_str, &type) != CM_SUCCESS) { - return CM_FALSE; - } - if (type != HOST_TYPE_IP_V4 && type != HOST_TYPE_IP_V6) { - CM_THROW_ERROR(ERR_TCP_INVALID_URLADDRESS, "ip type"); - return CM_FALSE; - } - return CM_TRUE; -} - static status_t cm_split_mes_single_url(char nodes[][CM_MAX_IP_LEN], uint16 ports[], char *single_url) { char *urlstr = single_url; @@ -231,7 +194,6 @@ static status_t cm_split_mes_single_url(char nodes[][CM_MAX_IP_LEN], uint16 port text_t text; uint32 len = (uint32)strlen(urlstr); if (len == 0) { - CM_THROW_ERROR(ERR_INVALID_PARAM, "mes single url"); return CM_ERROR; } @@ -246,14 +208,12 @@ static status_t cm_split_mes_single_url(char nodes[][CM_MAX_IP_LEN], uint16 port if (status == 0) { CM_RETURN_IFERR(cm_str2uint32(urlstr, &node_id)); if (node_id >= CM_MAX_INSTANCES) { - CM_THROW_ERROR(ERR_PARAMETER_TOO_LARGE, "node_id", CM_MAX_INSTANCES); return CM_ERROR; } status++; } else if (status == 1) { cm_str2text(urlstr, &text); cm_trim_text(&text); - CM_RETURN_IF_FALSE(cm_check_ss_ip(&text, urlstr)); MEMS_RETURN_IFERR(strncpy_s(nodes[node_id], CM_MAX_IP_LEN, text.str, text.len)); status++; } else { @@ -269,7 +229,6 @@ static status_t cm_split_mes_single_url(char nodes[][CM_MAX_IP_LEN], uint16 port if (url_len > 0) { CM_RETURN_IFERR(cm_str2uint16(urlstr, &ports[node_id])); if (ports[node_id] < CM_MIN_PORT) { - CM_THROW_ERROR(ERR_PARAMETER_TOO_SMALL, "node port", CM_MIN_PORT); return CM_ERROR; } } else { @@ -293,7 +252,8 @@ status_t cm_split_mes_urls(char nodes[][CM_MAX_IP_LEN], uint16 ports[], char *ur uint32 url_num = 0; char *urlstr = str_tmp; - for (pos = urlstr; len > 0 && url_num < CM_MAX_INSTANCES; len--) { + pos = urlstr; + for (; len > 0 && url_num < CM_MAX_INSTANCES; len--) { if (*pos != ',') { url_len++; pos++; @@ -309,10 +269,10 @@ status_t cm_split_mes_urls(char nodes[][CM_MAX_IP_LEN], uint16 ports[], char *ur urlstr += (url_len + 1); url_len = 0; pos = urlstr; + url_num++; } if (url_num >= CM_MAX_INSTANCES) { - CM_THROW_ERROR(ERR_IPADDRESS_OR_DOMAIN_NUM_EXCEED, (uint32)CM_MAX_INSTANCES); return CM_ERROR; } diff --git a/src/cm_network/cm_ip.h b/src/cm_network/cm_ip.h index c4412432e3056fe479b3ffb598972f52951e605d..d6fb5b8c5bfb50203e767e016f20531dbbe19554 100644 --- a/src/cm_network/cm_ip.h +++ b/src/cm_network/cm_ip.h @@ -54,7 +54,7 @@ typedef struct st_sock_addr { #define SOCKADDR_FAMILY(sa) (SOCKADDR(sa)->sa_family) #define SOCKADDR_PORT(sa) (SOCKADDR_FAMILY(sa) == AF_INET ? SOCKADDR_IN4(sa)->sin_port : SOCKADDR_IN6(sa)->sin6_port) -typedef enum { HOST_TYPE_IP_V4, HOST_TYPE_IP_V6, HOST_TYPE_DOMAIN } host_type_t; + static inline const char *cm_inet_ntop(struct sockaddr *addr, char *buffer, int size) { errno_t errcode = 0; diff --git a/src/cm_protocol/cs_listener.c b/src/cm_protocol/cs_listener.c index 756eeef73e29aa4f9793fefaf56e400da70fc16f..d5179cbe91adceea616d5b8639fb7f622cd3477e 100644 --- a/src/cm_protocol/cs_listener.c +++ b/src/cm_protocol/cs_listener.c @@ -26,7 +26,6 @@ #include "cm_epoll.h" #include "cm_file.h" #include "mes_interface.h" -#include "cm_system.h" #ifdef __cplusplus extern "C" { @@ -36,19 +35,11 @@ static bool32 cs_create_tcp_link(socket_t sock_ready, cs_pipe_t *pipe) { pipe->type = CS_TYPE_TCP; tcp_link_t *link = &pipe->link.tcp; + link->sock = sock_ready; link->local.salen = (socklen_t)sizeof(link->local.addr); - (void)getsockname(sock_ready, (struct sockaddr *)&link->local.addr, (socklen_t *)&link->local.salen); - link->remote.salen = (socklen_t)sizeof(link->remote.addr); -#ifdef WIN32 - link->sock = (socket_t)accept(sock_ready, SOCKADDR(&link->remote), &link->remote.salen); -#else - link->sock = (socket_t)accept4(sock_ready, SOCKADDR(&link->remote), &link->remote.salen, SOCK_CLOEXEC); -#endif - - if (link->sock == CS_INVALID_SOCKET) { - return CM_FALSE; - } + (void)getsockname(sock_ready, (struct sockaddr *)&link->local.addr, (socklen_t *)&link->local.salen); + (void)getpeername(sock_ready, SOCKADDR(&link->remote), (socklen_t *)&link->remote.salen); /* set default options of sock */ cs_set_io_mode(link->sock, CM_TRUE, CM_TRUE); @@ -59,11 +50,24 @@ static bool32 cs_create_tcp_link(socket_t sock_ready, cs_pipe_t *pipe) return CM_TRUE; } +static bool32 cs_is_listen_sock(tcp_lsnr *lsnr, socket_t sock) +{ + for ( int 64 i=0; i< lsnr->sock_count; i++) { + if(lsnr->sock[i] == sock) { + return CM_TRUE; + } + } + + return CM_FALSE; +} + void cs_try_tcp_accept(tcp_lsnr_t *lsnr, cs_pipe_t *pipe) { socket_t sock_ready; - int32 loop; - int32 ret; + int32 loop, ret; + struct epoll_event ev; + ev.events = (EPOLLIN | EPOLLRDHUP | EPOLLERR); + struct epoll_event evnts[CM_MAX_LSNR_HOST_COUNT]; ret = epoll_wait(lsnr->epoll_fd, evnts, (int)lsnr->sock_count, CM_POLL_WAIT); @@ -74,18 +78,54 @@ void cs_try_tcp_accept(tcp_lsnr_t *lsnr, cs_pipe_t *pipe) return; } - for (loop = 0; loop < ret && (uint32)loop < CM_MAX_LSNR_HOST_COUNT; ++loop) { + for (loop = 0; loop < ret && (uint32)loop < CM_MAX_POLL_COUNT; ++loop) { sock_ready = evnts[loop].data.fd; - if (!cs_create_tcp_link(sock_ready, pipe)) { - continue; - } - if (lsnr->status != LSNR_STATUS_RUNNING) { - cs_tcp_disconnect(&pipe->link.tcp); - continue; - } - if (lsnr->action(lsnr, pipe) != CM_SUCCESS) { - cs_tcp_disconnect(&pipe->link.tcp); - continue; + if(cs_is_listen_sock(lsnr, sock_ready)) { +#ifdef WIN32 + sock_t sock_accept = (socket_t)accept(sock_ready, NULL, NULL); +#else + sock_t sock_accept = (socket_t)accept4(sock_ready, NULL, NULL, SOCK_CLOEXEC); +#endif + if (sock_accept == CS_INVALID_SOCKET) { + continue; + } + + ev.data.fd = sock_accept; + if(epoll_ctl(lsnr->epoll_fd, EPOLL_CTL_ADD, sock_accept, &ev) != 0) { + cm_close_file(sock_accept); + LOG_DEBUG_ERR( + "[mes] add accepted sock to epoll fd failed:sock:%d,errno%d", sock_ready,cm_get_os_error()); + continue; + } + } else { + if ((events[loop].events & EPOLLRDHUP) || (events[loop].events & EPOLLERR)) { + (void)epoll_ctl(lsnr->epoll_fd, EPOLL_CTL_DEL,sock_ready, &ev); + cm_close_file(sock_ready); + LOG_DEBUG_ERR("[mes] listner received a abnormal event, close the sock:%d,event:%d", + sock_ready, + events[loop].events); + continue; + } else if (events[loop].events & EPOLLIN) { + (void)epoll_ctl(lsnr->epoll_fd, EPOLL_CTL_DEL,sock_ready, &ev); + if(!cs_create_tcp_link(sock_ready, pipe)) { + cm_close_file(sock_ready); + LOG_DEBUG_ERR("[mes] listner cs_create_tcp_link failed:%d", sock_ready); + continue; + } + + if (lsnr->status != LSNR_STATUS_RUNNING) { + cs_tcp_disconnect(&pipe->link.tcp); + LOG_DEBUG_ERR("[mes] listener status is abnorma:%d", sock_ready); + continue; + } + if (lsnr->action(lsnr, pipe) != CM_SUCCESS) { + cs_tcp_disconnect(&pipe->link.tcp); + LOG_DEBUG_ERR("[mes] connect action failed:%d", sock_ready); + continue; + } + } else { + LOG_DEBUG_ERR("[mes] listener get unknown event on sock:%d, evnet:%d", sock_ready, events[loop].events); + } } } } @@ -103,7 +143,6 @@ static void srv_tcp_lsnr_proc(thread_t *thread) pipe.type = CS_TYPE_TCP; cm_set_thread_name("tcp_lsnr"); - cm_block_sighup_signal(); mes_thread_init_t cb_thread_init = mes_get_worker_init_cb(); if (cb_thread_init != NULL) { diff --git a/src/cm_protocol/cs_listener.h b/src/cm_protocol/cs_listener.h index 51e4e03d6207104b61f905f70733ff4671073677..c8725ddc0771dbe4b95377cda87a037813b428f6 100644 --- a/src/cm_protocol/cs_listener.h +++ b/src/cm_protocol/cs_listener.h @@ -35,6 +35,8 @@ extern "C" { #endif +#define CM_MAX_POLL_COUNT (100) + #define CS_SOCKET_SLOT_USED (CS_INVALID_SOCKET - 1) typedef enum en_lsnr_type { diff --git a/src/cm_protocol/cs_packet.h b/src/cm_protocol/cs_packet.h index 33c48240244d0d76e7774566a8d4aae33adb9ad6..648632e2dbbf437a188eccf749d21c11c0ab60f9 100644 --- a/src/cm_protocol/cs_packet.h +++ b/src/cm_protocol/cs_packet.h @@ -43,7 +43,6 @@ typedef enum en_cs_minor_version { MIN_VERSION_3 = 3, MIN_VERSION_4 = 4, MIN_VERSION_5 = 5, /* send version and proto_code when tcp connect */ - MIN_VERSION_6 = 6, /* add app_cmd in mes message head */ } cs_minor_version_t; typedef enum en_cs_major_version { @@ -64,10 +63,7 @@ typedef enum en_cs_major_version { /* send version and proto_code when tcp connect */ #define CS_VERSION_5 (uint32) CS_PROTOCOL(MJR_VERSION_0, MIN_VERSION_5) - -/* add app_cmd in mes message head */ -#define CS_VERSION_6 (uint32) CS_PROTOCOL(MJR_VERSION_0, MIN_VERSION_6) -#define CS_LOCAL_VERSION CS_VERSION_6 +#define CS_LOCAL_VERSION CS_VERSION_5 #define CS_CMD_UNKONOW (uint8)0 #define CS_CMD_HANDSHAKE (uint8)1 /* process before login, added since v2.0; for SSL only since v9.0 */ diff --git a/src/cm_time/cm_date.c b/src/cm_time/cm_date.c index 29e1aed171974e73ab296f01ab40b3664bf93f6d..4401145cba2b33f135e10d3a7a8bb52a1cf9d8e0 100644 --- a/src/cm_time/cm_date.c +++ b/src/cm_time/cm_date.c @@ -895,71 +895,6 @@ status_t cm_date2text_ex(date_t date, const text_t *fmt, uint32 precision, text_ return cm_detail2text(&detail, &format_text, precision, text, max_len); } -void cm_decode_time(time_t time, date_detail_t *detail) -{ - struct tm now_time; - (void)cm_localtime(&time, &now_time); - detail->year = (uint16)now_time.tm_year + CM_BASE_YEAR; - detail->mon = (uint8)now_time.tm_mon + 1; - detail->day = (uint8)now_time.tm_mday; - detail->hour = (uint8)now_time.tm_hour; - detail->min = (uint8)now_time.tm_min; - detail->sec = (uint8)now_time.tm_sec; - detail->millisec = 0; - detail->microsec = 0; - detail->nanosec = 0; -} - -time_t cm_encode_time(date_detail_t *detail) -{ - struct tm now_time; - - now_time.tm_year = (int)detail->year - CM_BASE_YEAR; - now_time.tm_mon = (int)detail->mon - 1; - now_time.tm_mday = (int)detail->day; - now_time.tm_hour = (int)detail->hour; - now_time.tm_min = (int)detail->min; - now_time.tm_sec = (int)detail->sec; - now_time.tm_isdst = 0; - - return mktime(&now_time); -} - -time_t cm_date2time(date_t date) -{ - date_detail_t detail; - - cm_decode_date(date, &detail); - return cm_encode_time(&detail); -} - -static status_t cm_time2text(time_t time, text_t *fmt, text_t *text, uint32 text_str_max_size) -{ - date_detail_t detail; - text_t format_text; - - CM_ASSERT(fmt != NULL); - CM_ASSERT(text != NULL); - cm_decode_time(time, &detail); - - if (fmt == NULL || fmt->str == NULL) { - return CM_ERROR; - } else { - format_text = *fmt; - } - - return cm_detail2text(&detail, &format_text, CM_MAX_DATETIME_PRECISION, text, text_str_max_size); -} - -status_t cm_time2str(time_t time, const char *fmt, char *str, uint32 str_max_size) -{ - text_t fmt_text, time_text; - cm_str2text((char *)fmt, &fmt_text); - time_text.str = str; - time_text.len = 0; - - return cm_time2text(time, &fmt_text, &time_text, str_max_size); -} #ifdef __cplusplus } diff --git a/src/cm_time/cm_date.h b/src/cm_time/cm_date.h index fed7c2d48744885396e44478fe853f1effbbd10f..3d9f577c91ab108622d1f732ee09ee3c4cbd2112 100644 --- a/src/cm_time/cm_date.h +++ b/src/cm_time/cm_date.h @@ -65,13 +65,10 @@ int cm_gettimeofday(struct timeval *tv); /* the minimal units of a day == SECONDS_PER_DAY * MILLISECS_PER_SECOND * MICROSECS_PER_MILLISEC */ #define UNITS_PER_DAY 86400000000LL -#define MICROSECS_PER_MIN 60000000U - /* the difference between 1970.01.01-2000.01.01 in microseconds */ /* FILETIME of Jan 1 1970 00:00:00 GMT, the Zenith epoch */ #define CM_UNIX_EPOCH (-946684800000000LL) -#define CM_BASE_YEAR 1900 #define CM_MIN_YEAR 1 #define CM_MAX_YEAR 9999 @@ -107,46 +104,6 @@ static inline status_t cm_date2str(date_t date, const char *fmt, char *str, uint status_t cm_detail2text(const date_detail_t *detail, text_t *fmt, uint32 precision, text_t *text, uint32 max_len); -static inline struct tm *cm_localtime(const time_t *timep, struct tm *result) -{ -#ifdef WIN32 - errno_t err = localtime_s(result, timep); - if (err != EOK) { - CM_ASSERT(0); - } - return NULL; -#else - return localtime_r(timep, result); -#endif -} - -static inline uint64 cm_day_usec(void) -{ -#ifdef WIN32 - uint64 usec; - SYSTEMTIME sys_time; - GetLocalTime(&sys_time); - - usec = sys_time.wHour * SECONDS_PER_HOUR * MICROSECS_PER_SECOND; - usec += sys_time.wMinute * MICROSECS_PER_MIN; - usec += sys_time.wSecond * MICROSECS_PER_SECOND; - usec += sys_time.wMilliseconds * MICROSECS_PER_MILLISEC; -#else - uint64 usec; - struct timeval tv; - (void)gettimeofday(&tv, NULL); - usec = (uint64)(tv.tv_sec * MICROSECS_PER_SECOND); - usec += (uint64)tv.tv_usec; -#endif - - return usec; -} - -time_t cm_encode_time(date_detail_t *detail); -void cm_decode_time(time_t time, date_detail_t *detail); -time_t cm_date2time(date_t date); -status_t cm_time2str(time_t time, const char *fmt, char *str, uint32 str_max_size); - #ifdef __cplusplus } #endif diff --git a/src/cm_time/cm_timer.c b/src/cm_time/cm_timer.c index 581ee6a781e60515131466b3c996f22a97bc7b40..7dcdddb66f6de792d18b53f0da456478cbd45e06 100644 --- a/src/cm_time/cm_timer.c +++ b/src/cm_time/cm_timer.c @@ -24,7 +24,6 @@ #include "cm_timer.h" #include "cm_log.h" -#include "cm_system.h" #define DAY_USECS (uint64)86400000000 #define MES_DEFAULT_SLEEP_TIME 100000 // 0.1ms @@ -60,7 +59,6 @@ static void timer_proc(thread_t *thread) start_time = cm_now(); cm_set_thread_name("timer"); - cm_block_sighup_signal(); #ifndef _WIN32 struct timespec tq, tr; diff --git a/src/cm_utils/cm_disklock.c b/src/cm_utils/cm_disklock.c index 309393e4f0e70e74dbb5d8c66494f1d5e17d4d16..d2dfe5f6fa7f121e73721f0f1cd67fd1b2b4eaae 100644 --- a/src/cm_utils/cm_disklock.c +++ b/src/cm_utils/cm_disklock.c @@ -524,6 +524,29 @@ unsigned int cm_dl_alloc_lease( return lock_id; } +int cm_dl_modify_lease(unsigned int lock_id, unsigned int lease_sec) +{ + if (lock_id >= CM_MAX_DISKLOCK_COUNT) { + LOG_RUN_ERR("DL:invalid lock_id:%u.", lock_id); + return CM_DL_ERR_INVALID_LOCK_ID; + } + + cm_dl_t *lock_info = &g_dl_ctx.lock_info[lock_id]; + if (lock_info->fd <= 0) { + LOG_RUN_ERR("DL:invalid lock not ready,lock_id:%u.", lock_id); + return CM_DL_ERR_INVALID_LOCK_ID; + } + + if(lock_info->type != LT_LEASE) { + LOG_RUN_ERR("DL:lock is not lease lock,lock_id:%u.", lock_id); + return CM_DL_ERR_INVALID_PARAM; + } + + lock_info->lease_sec = lease_sec; + + return CM_SUCCESS; +} + int cm_dl_check_lock_remain(unsigned int lock_id, unsigned long long inst_id, unsigned int *is_remain) { *is_remain = CM_FALSE; @@ -531,6 +554,7 @@ int cm_dl_check_lock_remain(unsigned int lock_id, unsigned long long inst_id, un LOG_RUN_ERR("DL:invalid lock_id:%u.", lock_id); return CM_DL_ERR_INVALID_LOCK_ID; } + cm_dl_t *lock_info = &g_dl_ctx.lock_info[lock_id]; dl_stat_t *lock_stat = &lock_info->lock_stat[inst_id + 1]; if (lock_info->fd <= 0) { diff --git a/src/cm_utils/cm_disklock.h b/src/cm_utils/cm_disklock.h index b01c5e49a8b3d137f99da7e66af51d337d41d80b..92fcfd8b76cc9522ec8e5bed9d5b6006725a64bf 100644 --- a/src/cm_utils/cm_disklock.h +++ b/src/cm_utils/cm_disklock.h @@ -117,15 +117,16 @@ int cm_dl_getowner(unsigned int lock_id, unsigned long long *inst_id); * @return != 0 fail */ int cm_dl_getlocktime(unsigned int lock_id, unsigned long long *locktime); + /** - * Check whether the lock remains. + * modify the lease lock's lease duration. * @param [in] lock_id: lock_id - * @param [in] inst_id: inst_id - * @param [out] is_remain: lock remain result. + * @param [in] lease_sec: lease duration,unit second. * @return 0 success * @return != 0 fail */ -int cm_dl_check_lock_remain(unsigned int lock_id, unsigned long long inst_id, unsigned int *is_remain); +int cm_dl_modify_lease(unsigned int lock_id, unsigned int lease_sec); + #ifdef __cplusplus } diff --git a/src/cm_utils/cm_dlock.c b/src/cm_utils/cm_dlock.c index 4789ac411d9b8bc8ceab172f5a786fd7eeb3431f..458960639a0fd710f716e2c09bddbde805362fe3 100644 --- a/src/cm_utils/cm_dlock.c +++ b/src/cm_utils/cm_dlock.c @@ -613,26 +613,3 @@ status_t cm_get_dlock_info(dlock_t *lock, int32 fd) #endif return CM_SUCCESS; } -status_t cm_check_dlock_remain(dlock_t *lock, int32 fd, bool32 *is_remain) -{ - *is_remain = CM_FALSE; -#ifdef WIN32 -#else - status_t status = cm_get_dlock_info(lock, fd); - if (status != CM_SUCCESS) { - return CM_ERROR; - } - if (LOCKR_INST_ID(*lock) == 0) { - LOG_DEBUG_INF("there is no lock on disk."); - return CM_SUCCESS; - } - - if (LOCKR_INST_ID(*lock) != LOCKW_INST_ID(*lock)) { - LOG_DEBUG_INF( - "another inst_id(disk) %lld, curr inst_id(lock) %lld.", LOCKR_INST_ID(*lock), LOCKW_INST_ID(*lock)); - return CM_SUCCESS; - } - *is_remain = CM_TRUE; -#endif - return CM_SUCCESS; -} diff --git a/src/cm_utils/cm_dlock.h b/src/cm_utils/cm_dlock.h index 6c172dd447c3fddc3b95468dc6738d83e4621f97..bd1a732658f1c9d205da05acbece43ac112e32cd 100644 --- a/src/cm_utils/cm_dlock.h +++ b/src/cm_utils/cm_dlock.h @@ -121,7 +121,7 @@ status_t cm_disk_unlockf(dlock_t *lock, int32 fd, int64 old_inst_id); int32 cm_preempt_dlock(dlock_t *lock, const char *scsi_dev); status_t cm_erase_dlock(dlock_t *lock, int32 fd); status_t cm_get_dlock_info(dlock_t *lock, int32 fd); -status_t cm_check_dlock_remain(dlock_t *lock, int32 fd, bool32 *is_remain); + #ifdef __cplusplus } #endif diff --git a/src/cm_utils/cm_epoll.h b/src/cm_utils/cm_epoll.h index 2e7fe51944abdbf0dfd4d649c75b141857dee056..64da90046f895f1c3ff3d59a561d0c5590b990cd 100644 --- a/src/cm_utils/cm_epoll.h +++ b/src/cm_utils/cm_epoll.h @@ -40,6 +40,7 @@ extern "C" { #define EPOLLHUP 0x002 #define EPOLLRDHUP 0x004 #define EPOLLONESHOT 0x008 +#define EPOLLERR 0x010 #define EPOLL_CTL_ADD 0 #define EPOLL_CTL_MOD 1 diff --git a/src/cm_utils/cm_file.c b/src/cm_utils/cm_file.c index fbe44d22b442213252a25f963bd6a9b92a0d8156..3c226757c0627c74d27e8ede288a7641eaaec6a0 100644 --- a/src/cm_utils/cm_file.c +++ b/src/cm_utils/cm_file.c @@ -752,7 +752,7 @@ status_t cm_create_dir_ex(const char *dir_name) char dir[CM_MAX_PATH_LEN + 1]; size_t dir_len = strlen(dir_name); uint32 i; - if (dir_len >= CM_MAX_PATH_LEN) { + if (dir_len > CM_MAX_PATH_LEN) { LOG_DEBUG_ERR("the dir name's len is too big."); return CM_ERROR; } @@ -763,16 +763,9 @@ status_t cm_create_dir_ex(const char *dir_name) return CM_ERROR; } if (dir[dir_len - 1] != '\\' && dir[dir_len - 1] != '/') { - // Check if there is enough space to add '/' and '\0' - if (dir_len < (CM_MAX_PATH_LEN - 1)) { - dir[dir_len] = '/'; - dir_len++; - dir[dir_len] = '\0'; - } else { - LOG_DEBUG_ERR("the dir name's len is too big."); - return CM_ERROR; - } - + dir[dir_len] = '/'; + dir_len++; + dir[dir_len] = '\0'; } for (i = 0; i < dir_len; i++) { diff --git a/src/cm_utils/cm_log.c b/src/cm_utils/cm_log.c index 9ef8aa0bd47bd4bf4ba5a13353b505f35e825179..ff1938866138e2b7450de13e6c7738906c00450b 100644 --- a/src/cm_utils/cm_log.c +++ b/src/cm_utils/cm_log.c @@ -43,7 +43,7 @@ extern "C" { #define CM_INVALID_FD (-1) -bool32 g_high_frequency_restart_process = CM_FALSE; +bool32 g_high_frequency_restrt_process = CM_FALSE; static log_file_handle_t g_logger[LOG_COUNT] = { [LOG_RUN] = { @@ -208,7 +208,7 @@ static status_t cm_log_create_directory(const char *log_dir) size_t lastPos = 0; for (size_t i = 1; i < len; i++) { if (tmp[i] == '/') { - count = i - lastPos; + count = i - lastPos + 1; MEMS_RETURN_IFERR(strncat_s(path_name, CM_MAX_PATH_LEN, &tmp[lastPos], (size_t)count)); lastPos = i; if (make_dir(path_name, g_log_param.log_path_permissions) != 0 && errno != EEXIST && errno != EACCES) { @@ -811,8 +811,6 @@ static status_t compress_file_to_gzip(const char *infilename, const char *outfil } } if (feof(infile) == 0) { - (void)fclose(infile); - (void)gzclose(outfile); return CM_ERROR; } @@ -899,7 +897,7 @@ static void cm_stat_and_write_log(log_file_handle_t *log_file_handle, char *buf, cm_compress_log_file(log_file_handle, new_bak_file_name, CM_FILE_NAME_BUFFER_SIZE); cm_write_rmv_and_bak_file_log(bak_file_name, remove_file_count, new_bak_file_name); if (handle_before_log == CM_INVALID_FD && log_file_handle->file_handle != CM_INVALID_FD && - !g_high_frequency_restart_process) { + !g_high_frequency_restrt_process) { LOG_RUN_FILE_INF(CM_FALSE, "[LOG] file '%s' is added", log_file_handle->file_name); } } else { @@ -1164,43 +1162,29 @@ char *g_warning_desc[] = { "SSLDisabled", }; -void cm_write_alarm_log_core(uint32 warn_id, uint32 *warn_id_set, char **warn_desc_set, const char *format, - va_list args) +void cm_write_alarm_log(uint32 warn_id, const char *format, ...) { char buf[CM_MAX_LOG_CONTENT_LENGTH + 2] = {0}; text_t buf_text; log_file_handle_t *log_file_handle = &g_logger[LOG_ALARM]; char date[CM_MAX_TIME_STRLEN] = {0}; errno_t errcode; - + (void)cm_date2str(g_timer()->now, "yyyy-mm-dd hh24:mi:ss", date, CM_MAX_TIME_STRLEN); // Format: Date | Warn_Id | Warn_Desc | Components | Instance_name | parameters errcode = snprintf_s(buf, sizeof(buf), CM_MAX_LOG_CONTENT_LENGTH + 1, "%s|%u|%s|%s|%s|{'component-name':'%s','instance-name':'%s',", date, - warn_id_set[warn_id], warn_desc_set[warn_id], LOG_MODULE_NAME, + g_warn_id[warn_id], g_warning_desc[warn_id], LOG_MODULE_NAME, g_log_param.instance_name, LOG_MODULE_NAME, g_log_param.instance_name); if (errcode < 0) { return; } - - buf_text.str = buf; - buf_text.len = (uint32)strlen(buf); - cm_log_fulfil_write_buf(log_file_handle, &buf_text, sizeof(buf), CM_TRUE, format, args); -} - -void cm_write_alarm_log(uint32 warn_id, const char *format, ...) -{ - va_list args; - va_start(args, format); - cm_write_alarm_log_core(warn_id, g_warn_id, g_warning_desc, format, args); - va_end(args); -} -void cm_write_alarm_log_ex(uint32 warn_id, uint32 *warn_id_set, char **warn_desc_set, const char *format, ...) -{ va_list args; va_start(args, format); - cm_write_alarm_log_core(warn_id, warn_id_set, warn_desc_set, format, args); + buf_text.str = buf; + buf_text.len = (uint32)strlen(buf); + cm_log_fulfil_write_buf(log_file_handle, &buf_text, sizeof(buf), CM_TRUE, format, args); va_end(args); } diff --git a/src/cm_utils/cm_log.h b/src/cm_utils/cm_log.h index b6b5a06e9c18b4fc17de04e57e7ad7db3bda0633..cc2a8dab2be84aec92e381752db0a75990bf9c02 100644 --- a/src/cm_utils/cm_log.h +++ b/src/cm_utils/cm_log.h @@ -34,7 +34,7 @@ extern "C" { #endif -extern bool32 g_high_frequency_restart_process; +extern bool32 g_high_frequency_restrt_process; typedef enum en_log_level { LEVEL_ERROR = 0, // error conditions LEVEL_WARN, // warning conditions @@ -141,8 +141,6 @@ log_param_t *cm_log_param_instance(void); #define CM_DYNAMIC_TRACE_ENABLED (cm_log_param_instance()->dyn_trc_cbs.dyn_trc != NULL) #define CM_DYN_TRC_TRACE_LOGS (cm_log_param_instance()->dyn_trc_cbs.dyn_trc_trace_logs()) -#define CBB_SS_LOG_ALARM_ON (cm_log_param_instance()->log_level > 0) - static inline void cm_register_dyn_trc_cbs(usr_cb_log_trace_t cb_trc, usr_cb_dyn_trc_set_flag_t cb_setflag, usr_cb_dyn_trc_log_t cb_trclogs) { @@ -189,8 +187,6 @@ void cm_log_open_file(log_file_handle_t *log_file_handle); void cm_dump_mem_in_blackbox(void *dump_addr, uint32 dump_len); void cm_write_audit_log(const char *format, ...) CM_CHECK_FMT(1, 2); void cm_write_alarm_log(uint32 warn_id, const char *format, ...) CM_CHECK_FMT(2, 3); -void cm_write_alarm_log_ex(uint32 warn_id, uint32 *warn_id_set, char **warn_desc_set, const char *format, - ...) CM_CHECK_FMT(4, 5); void cm_write_normal_log(log_type_t log_type, log_level_t log_level, const char *code_file_name, uint32 code_line_num, const char *module_name, bool32 need_rec_filelog, const char *format, ...) CM_CHECK_FMT(7, 8); @@ -205,27 +201,56 @@ void cm_write_blackbox_log(const char *format, ...) CM_CHECK_FMT(1, 2); status_t cm_recovery_log_file(log_type_t log_type); #define LOG_DYN_TRC_CB (cm_log_param_instance()->dyn_trc_cbs.dyn_trc) +#define LOG_DYN_TRC_INF(format, ...) \ + do { \ + if (CM_DYNAMIC_TRACE_ENABLED) { \ + LOG_DYN_TRC_CB(LOG_DEBUG, LEVEL_INFO, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_MODULE_NAME, format, ##__VA_ARGS__); \ + }; \ + if (LOG_DEBUG_INF_ON) { \ + if (LOG_REG_CB) { \ + cm_log_param_instance()->log_write(LOG_DEBUG, LEVEL_INFO, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_MODULE_NAME, format, ##__VA_ARGS__); \ + } else if (LOG_INITED) { \ + cm_write_normal_log(LOG_DEBUG, LEVEL_INFO, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_MODULE_NAME, CM_TRUE, format, ##__VA_ARGS__); \ + } \ + } \ + } while (0) -#define LOG_DYN_TRC(level, level_str, format, ...) \ +#define LOG_DYN_TRC_WAR(format, ...) \ do { \ if (CM_DYNAMIC_TRACE_ENABLED) { \ - LOG_DYN_TRC_CB(LOG_DEBUG, level, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_DYN_TRC_CB(LOG_DEBUG, LEVEL_WARN, (char *)__FILE_NAME__, (uint32)__LINE__, \ LOG_MODULE_NAME, format, ##__VA_ARGS__); \ }; \ - if (LOG_DEBUG_##level_str##_ON) { \ + if (LOG_DEBUG_WAR_ON) { \ if (LOG_REG_CB) { \ - cm_log_param_instance()->log_write(LOG_DEBUG, level, (char *)__FILE_NAME__, (uint32)__LINE__, \ + cm_log_param_instance()->log_write(LOG_DEBUG, LEVEL_WARN, (char *)__FILE_NAME__, (uint32)__LINE__, \ LOG_MODULE_NAME, format, ##__VA_ARGS__); \ } else if (LOG_INITED) { \ - cm_write_normal_log(LOG_DEBUG, level, (char *)__FILE_NAME__, (uint32)__LINE__, \ + cm_write_normal_log(LOG_DEBUG, LEVEL_WARN, (char *)__FILE_NAME__, (uint32)__LINE__, \ LOG_MODULE_NAME, CM_TRUE, format, ##__VA_ARGS__); \ } \ } \ } while (0) -#define LOG_DYN_TRC_INF(format, ...) LOG_DYN_TRC(LEVEL_INFO, INF, format, ##__VA_ARGS__) -#define LOG_DYN_TRC_WAR(format, ...) LOG_DYN_TRC(LEVEL_WARN, WAR, format, ##__VA_ARGS__) -#define LOG_DYN_TRC_ERR(format, ...) LOG_DYN_TRC(LEVEL_ERROR, ERR, format, ##__VA_ARGS__) +#define LOG_DYN_TRC_ERR(format, ...) \ + do { \ + if (CM_DYNAMIC_TRACE_ENABLED) { \ + LOG_DYN_TRC_CB(LOG_DEBUG, LEVEL_ERROR, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_MODULE_NAME, format, ##__VA_ARGS__); \ + }; \ + if (LOG_DEBUG_ERR_ON) { \ + if (LOG_REG_CB) { \ + cm_log_param_instance()->log_write(LOG_DEBUG, LEVEL_ERROR, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_MODULE_NAME, format, ##__VA_ARGS__); \ + } else if (LOG_INITED) { \ + cm_write_normal_log(LOG_DEBUG, LEVEL_ERROR, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_MODULE_NAME, CM_TRUE, format, ##__VA_ARGS__); \ + } \ + } \ + } while (0) #define CM_SS_DYN_TRC_SET_TRACE_FLAG(val) \ do { \ @@ -241,26 +266,55 @@ status_t cm_recovery_log_file(log_type_t log_type); } \ } while (0) -#define DEBUG_LOG(level, level_str, format, ...) \ +#define LOG_DEBUG_INF(format, ...) \ do { \ if (CM_DYNAMIC_TRACE_ENABLED && CM_DYN_TRC_TRACE_LOGS) { \ - LOG_DYN_TRC_CB(LOG_DEBUG, level, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_DYN_TRC_CB(LOG_DEBUG, LEVEL_INFO, (char *)__FILE_NAME__, (uint32)__LINE__, \ LOG_MODULE_NAME, format, ##__VA_ARGS__); \ }; \ - if (LOG_DEBUG_##level_str##_ON) { \ + if (LOG_DEBUG_INF_ON) { \ if (LOG_REG_CB) { \ - cm_log_param_instance()->log_write(LOG_DEBUG, level, (char *)__FILE_NAME__, (uint32)__LINE__, \ + cm_log_param_instance()->log_write(LOG_DEBUG, LEVEL_INFO, (char *)__FILE_NAME__, (uint32)__LINE__, \ LOG_MODULE_NAME, format, ##__VA_ARGS__); \ } else if (LOG_INITED) { \ - cm_write_normal_log(LOG_DEBUG, level, (char *)__FILE_NAME__, (uint32)__LINE__, \ + cm_write_normal_log(LOG_DEBUG, LEVEL_INFO, (char *)__FILE_NAME__, (uint32)__LINE__, \ LOG_MODULE_NAME, CM_TRUE, format, ##__VA_ARGS__); \ } \ } \ } while (0) -#define LOG_DEBUG_INF(format, ...) DEBUG_LOG(LEVEL_INFO, INF, format, ##__VA_ARGS__) -#define LOG_DEBUG_WAR(format, ...) DEBUG_LOG(LEVEL_WARN, WAR, format, ##__VA_ARGS__) -#define LOG_DEBUG_ERR(format, ...) DEBUG_LOG(LEVEL_ERROR, ERR, format, ##__VA_ARGS__) +#define LOG_DEBUG_WAR(format, ...) \ + do { \ + if (CM_DYNAMIC_TRACE_ENABLED && CM_DYN_TRC_TRACE_LOGS) { \ + LOG_DYN_TRC_CB(LOG_DEBUG, LEVEL_WARN, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_MODULE_NAME, format, ##__VA_ARGS__); \ + }; \ + if (LOG_DEBUG_WAR_ON) { \ + if (LOG_REG_CB) { \ + cm_log_param_instance()->log_write(LOG_DEBUG, LEVEL_WARN, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_MODULE_NAME, format, ##__VA_ARGS__); \ + } else if (LOG_INITED) { \ + cm_write_normal_log(LOG_DEBUG, LEVEL_WARN, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_MODULE_NAME, CM_TRUE, format, ##__VA_ARGS__); \ + } \ + } \ + } while (0) +#define LOG_DEBUG_ERR(format, ...) \ + do { \ + if (CM_DYNAMIC_TRACE_ENABLED && CM_DYN_TRC_TRACE_LOGS) { \ + LOG_DYN_TRC_CB(LOG_DEBUG, LEVEL_ERROR, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_MODULE_NAME, format, ##__VA_ARGS__); \ + }; \ + if (LOG_DEBUG_ERR_ON) { \ + if (LOG_REG_CB) { \ + cm_log_param_instance()->log_write(LOG_DEBUG, LEVEL_ERROR, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_MODULE_NAME, format, ##__VA_ARGS__); \ + } else if (LOG_INITED) { \ + cm_write_normal_log(LOG_DEBUG, LEVEL_ERROR, (char *)__FILE_NAME__, (uint32)__LINE__, \ + LOG_MODULE_NAME, CM_TRUE, format, ##__VA_ARGS__); \ + } \ + } \ + } while (0) // 10s print 5 times #define LOG_DEBUG_ERR_EX(format, ...) \ @@ -356,20 +410,6 @@ status_t cm_recovery_log_file(log_type_t log_type); } \ } while (0) -#define LOG_ALARM_EX(warn_id, warn_id_set, warn_desc_set, format, ...) \ - do { \ - if ((LOG_INITED) && (CBB_SS_LOG_ALARM_ON)) { \ - cm_write_alarm_log_ex(warn_id, warn_id_set, warn_desc_set, format"|1", ##__VA_ARGS__); \ - } \ - } while (0) \ - -#define LOG_ALARM_RECOVER_EX(warn_id, warn_id_set, warn_desc_set, format, ...) \ - do { \ - if ((LOG_INITED) && (CBB_SS_LOG_ALARM_ON)) { \ - cm_write_alarm_log_ex(warn_id, warn_id_set, warn_desc_set, format"|2", ##__VA_ARGS__); \ - } \ - } while (0) \ - /* no need to print error info in file add/remove log */ #define LOG_RUN_FILE_INF(need_record_file_log, format, ...) \ do { \ diff --git a/src/cm_utils/cm_memory.c b/src/cm_utils/cm_memory.c index 25307b900172b1ace91fb60e466b36dd1416d94e..d2baacfe264857b51fc6e59ef3772cd4f84f4c59 100644 --- a/src/cm_utils/cm_memory.c +++ b/src/cm_utils/cm_memory.c @@ -578,7 +578,7 @@ static bool8 memory_context_check_max_size(memory_context_t *context, int64 size { memory_context_t *temp_context = context; while (temp_context != NULL) { - if ((uint64)temp_context->used_size + size > temp_context->mem_max_size) { + if (temp_context->used_size + size > temp_context->mem_max_size) { return CM_FALSE; } temp_context = temp_context->parent; @@ -608,10 +608,10 @@ bool8 ddes_add_used_context_memory(memory_context_t *context, int64 size) } memory_context_t *temp_context = context; while (temp_context != NULL) { - if ((uint64)temp_context->used_size + size <= temp_context->mem_max_size) { + if (temp_context->used_size + size <= temp_context->mem_max_size) { cur_used = cm_atomic_add((atomic_t *)&temp_context->used_size, size); level++; - if ((uint64)cur_used > temp_context->mem_max_size) { + if (cur_used > temp_context->mem_max_size) { roll_back_add_used_context_memory(context, size, level); updated = CM_FALSE; break; @@ -651,12 +651,12 @@ memory_context_t* ddes_memory_context_create(memory_context_t *parent, uint64 ma } cm_spin_lock(&g_mem_context_lock, NULL); int32 ret; - int64 size = (int64)sizeof(memory_context_t); + uint64 size = sizeof(memory_context_t); memory_context_t *context = NULL; if (parent != NULL) { - context = (memory_context_t *)ddes_alloc(parent, (uint64)size); + context = (memory_context_t *)ddes_alloc(parent, size); } else { - context = (memory_context_t *)mem_allocator->malloc_proc((uint64)size); + context = (memory_context_t *)mem_allocator->malloc_proc(size); } if (context == NULL) { LOG_RUN_ERR("cm_memory: mem_context create failed, malloc failed"); @@ -816,8 +816,7 @@ void *ddes_alloc_align(memory_context_t *context, uint32 alignment, uint64 size) return NULL; } cm_memory_allocator_t *mem_allocator = &context->mem_allocator; - uint64 alloc_size = - size + (alignment -1) + (uint64)sizeof(ddes_buffer_head_t) + (uint64)sizeof(mem_context_block_t); + uint64 alloc_size = size + (alignment -1) + sizeof(ddes_buffer_head_t) + sizeof(mem_context_block_t); mem_context_block_t *block = (mem_context_block_t *)mem_allocator->malloc_proc(alloc_size); if (block == NULL) { ddes_sub_used_context_memory(context, size); diff --git a/src/cm_utils/cm_memory.h b/src/cm_utils/cm_memory.h index eae36145a6291c4dd99ee82873c2b431fa2891ab..26015b701600dca68acc4cbf537ce7ec08ef224f 100644 --- a/src/cm_utils/cm_memory.h +++ b/src/cm_utils/cm_memory.h @@ -208,12 +208,6 @@ void *ddes_alloc(memory_context_t *context, uint64 size); void *ddes_alloc_align(memory_context_t *context, uint32 alignment, uint64 size); void ddes_free(void *ptr); -static inline void ddes_memory_stat(memory_context_t *context, uint64 *used, uint64 *total) -{ - *used = (uint64)context->used_size; - *total = context->mem_max_size; -} - static inline uint64 mem_used_size(const mem_pool_t *mem) { return mem->used_size; diff --git a/src/cm_utils/cm_profile_stat.c b/src/cm_utils/cm_profile_stat.c index c57d2f2db03a3fc98e3a5637ab66783fe35ebc0a..367d7271a1cb6c51b8fb6a94ce1b919d7f98816b 100644 --- a/src/cm_utils/cm_profile_stat.c +++ b/src/cm_utils/cm_profile_stat.c @@ -24,7 +24,6 @@ #include "cm_profile_stat.h" #include "cm_text.h" -#include "cm_system.h" #ifdef __cplusplus extern "C" { @@ -338,7 +337,6 @@ static void stat_free(void) static void cm_profile_stat_entry(thread_t *thread) { cm_set_thread_name("cm_profile_stat"); - cm_block_sighup_signal(); date_t last_check_time = g_timer()->monotonic_now; diff --git a/src/cm_utils/cm_system.c b/src/cm_utils/cm_system.c index d96575ed307b66a58496288988b0aa1e29d70a84..dca7c75adc8a91e3aae067efcf2bd7eaa1b40eb6 100644 --- a/src/cm_utils/cm_system.c +++ b/src/cm_utils/cm_system.c @@ -336,22 +336,6 @@ bool32 cm_sys_process_alived(uint64 pid, int64 start_time) #endif } -void cm_block_sighup_signal() -{ -#ifndef _WIN32 - sigset_t sigmask; - sigemptyset(&sigmask); - sigaddset(&sigmask, SIGHUP); - - int ret = pthread_sigmask(SIG_BLOCK, &sigmask, NULL); - if (ret == -1) { - LOG_RUN_ERR("pthread_sigmask fail"); - return; - } -#endif - return; -} - #ifdef __cplusplus } #endif diff --git a/src/cm_utils/cm_system.h b/src/cm_utils/cm_system.h index ec3f0239c2de46b91fb544ddf9729aa0b5c7e25a..8310d80e03b8f9255143bd63006511c0d277a335 100644 --- a/src/cm_utils/cm_system.h +++ b/src/cm_utils/cm_system.h @@ -43,7 +43,6 @@ char *cm_sys_platform_name(void); int64 cm_sys_ticks(void); status_t cm_sys_process_start_time(uint64 pid, int64 *process_time); bool32 cm_sys_process_alived(uint64 pid, int64 start_time); -void cm_block_sighup_signal(); #ifdef __cplusplus } diff --git a/src/cm_utils/cm_utils.c b/src/cm_utils/cm_utils.c index b228c9ef069933dbbfeeee2b0d844adb81db134a..79ce170bf8b2bb7792a87bb8f55a60b0fa770da9 100644 --- a/src/cm_utils/cm_utils.c +++ b/src/cm_utils/cm_utils.c @@ -43,7 +43,6 @@ #define CM_UPPER_LETTER_TYPE 1 #define CM_LOWER_LETTER_TYPE 2 #define CM_SPECIAL_CHAR_TYPE 3 -#define CM_VERSION_MAX_LEN 256 static status_t cm_get_character_type_count(const char *pText, uint32 i, uint32 *types) { @@ -380,9 +379,3 @@ void cm_usleep(uint32 us) (void)usleep(us); #endif } - -void cm_show_version(char *version) -{ - int ret = strcpy_s(version, CM_VERSION_MAX_LEN, (char *)DEF_CBB_VERSION); - CM_SECUREC_CHECK(ret); -} diff --git a/src/cm_utils/cm_utils.h b/src/cm_utils/cm_utils.h index 071df7cdc358fd0169c4401ae8fff3aca8913991..5db67a63a8fde9bd538d0635a172aaa29de22f77 100644 --- a/src/cm_utils/cm_utils.h +++ b/src/cm_utils/cm_utils.h @@ -28,9 +28,6 @@ #include "cm_log.h" #ifndef WIN32 #include "dlfcn.h" -#include "cm_version.h" -#else -#define DEF_CBB_VERSION "cbb.lib develop for windows" #endif #ifdef WIN32 @@ -85,7 +82,6 @@ void cm_usleep(uint32 us); status_t cm_verify_password_str(const char *name, const char *passwd, uint32 pwd_min_len); uint32 cm_rand_int32(int64 *seed, uint32 range); uint32 cm_rand_next(int64 *seed, uint32 bits); -void cm_show_version(char *version); #ifdef __cplusplus } #endif diff --git a/src/ddes_json/ddes_json.c b/src/ddes_json/ddes_json.c index 0ead9ddbd162e765d5d1f98bb3a46d2243de7c98..b1cad7a71888c14686f72432e748e54b71c05cde 100644 --- a/src/ddes_json/ddes_json.c +++ b/src/ddes_json/ddes_json.c @@ -907,9 +907,6 @@ bool32 json_is_null(json_t *json, text_t *key) } json_val_t *jval; jval = (json_val_t *)cm_hmap_find(&json->props, &g_json_hfs2, key); - if (jval == NULL) { - return CM_FALSE; - } char *val = JSON_OFFSET_VAL(jval) + sizeof(jstr_len_t); char *compareUpper = "NULL"; char *compareLower = "null"; @@ -935,16 +932,16 @@ status_t json_get_obj(json_t *json, json_t **obj, text_t *key) status_t json_add_str(json_t *json, const char * const key, const char * const val) { - if ((json == NULL) || (key == NULL)) { - return CM_ERROR; - } - json_val_t *jval; uint32 key_size; uint32 val_size; uint32 key_len = (uint32)strlen(key); uint32 val_len = (uint32)strlen(val); + if ((json == NULL) || (key == NULL)) { + return CM_ERROR; + } + key_size = (uint32)(sizeof(json_val_t) + sizeof(uint16) + key_len + 1); val_size = (uint32)sizeof(jstr_len_t) + val_len + 1; CM_RETURN_IFERR(json->allocator.f_alloc(json->allocator.mem_ctx, key_size + val_size, (void **)&jval)); diff --git a/src/ddes_perctrl/interface/ddes_perctrl_api.c b/src/ddes_perctrl/interface/ddes_perctrl_api.c index 844d50dedba9973a796924179a5abd48c8a9445f..50113ec98cb944b1bcf8fb7f1193157d52e768f4 100644 --- a/src/ddes_perctrl/interface/ddes_perctrl_api.c +++ b/src/ddes_perctrl/interface/ddes_perctrl_api.c @@ -243,8 +243,8 @@ int32 exec_perctrl_init_logger() req.head->cmd = PERCTRL_CMD_INIT_LOG; char buf[MAX_PACKET_LEN]; PRTS_RETURN_IFERR(snprintf_s(buf, MAX_PACKET_LEN, MAX_PACKET_LEN - 1, - "log_home=%s|log_level=%u|log_backup_file_count=%u|max_log_file_size=%llu|" - "log_file_permissions=%u|log_path_permissions=%u|log_bak_file_permissions=%u|log_compressed=%hu", + "log_home=%s|log_level=%u|log_backup_file_count=%u|max_log_file_size=%llu|log_file_permissions=%u|log_path_permissions=%u|" + "log_bak_file_permissions=%u|log_compressed=%hu", parent_log_param->log_home, parent_log_param->log_level, parent_log_param->log_backup_file_count, parent_log_param->max_log_file_size, parent_log_param->log_file_permissions, parent_log_param->log_path_permissions, @@ -256,7 +256,7 @@ int32 exec_perctrl_init_logger() (void)ddes_get_int32(&ack, &errcode); (void)ddes_get_str(&ack, &errmsg); CM_THROW_ERROR_EX(errcode, "%s", errmsg); - LOG_DEBUG_ERR("[PERCTRL]init loggers failed, result:%d, %s.", ack.head->result, errmsg); + LOG_RUN_ERR("[PERCTRL]init loggers failed, result:%d, %s.", ack.head->result, errmsg); return ack.head->result; } diff --git a/src/ddes_perctrl/service/ddes_perctrl_server.c b/src/ddes_perctrl/service/ddes_perctrl_server.c index a221e4a8214c884e3674d0cb155db0c91f688d6e..398b56b2eb4b9a436209200a0b5bb68c80b11506 100644 --- a/src/ddes_perctrl/service/ddes_perctrl_server.c +++ b/src/ddes_perctrl/service/ddes_perctrl_server.c @@ -161,8 +161,8 @@ int32 exec_scsi3_clear(perctrl_packet_t *req, perctrl_packet_t *ack) CM_RETURN_IFERR(ddes_get_int64(req, &rk)); CM_RETURN_IFERR(ddes_open_iof_dev(iof_dev, &fd)); status_t ret = cm_scsi3_clear(fd, rk); - LOG_RUN_INF("Exec clear ret %d, iof_dev: %s, rk: %lld, fd: %d.", ret, iof_dev, rk, fd); (void)close(fd); + LOG_RUN_INF("Exec clear ret %d.", ret); return ret; } @@ -688,7 +688,7 @@ status_t perctrl_init_loggers(cm_log_def_t *log_def, uint32 log_def_count, char uint32 len = CM_MAX_PATH_LEN; int32 ret; status_t status; - g_high_frequency_restart_process = CM_TRUE; + g_high_frequency_restrt_process = CM_TRUE; for (size_t i = 0; i < log_def_count; i++) { ret = snprintf_s(file_name, len, (len - 1), "%s/%s", log_param->log_home, log_def[i].log_filename); if (ret == -1) { @@ -719,7 +719,7 @@ status_t perctrl_init_loggers(cm_log_def_t *log_def, uint32 log_def_count, char return CM_SUCCESS; } -status_t perctrl_parse_log_param_inner(perctrl_log_param_id_t id, char *buf) +status_t perctrl_parse_param_inner(perctrl_log_param_id_t id, char *buf) { log_param_t *log_param = cm_log_param_instance(); status_t status = CM_SUCCESS; @@ -761,14 +761,14 @@ status_t perctrl_parse_log_param_inner(perctrl_log_param_id_t id, char *buf) CM_RETURN_IFERR_EX(status, (void)printf("The value of log_compressed is invalid.\n")); break; default: - (void)printf("Invalid perctrl log param id %u.\n", id); + (void)printf("Invalid perctrl id %u.\n", id); status = CM_ERROR; break; } return status; } -status_t perctrl_parse_log_args(char *buf) +status_t perctrl_parse_args(char *buf) { char *next_info = NULL; char *key = strtok_s(buf, "=", &next_info); @@ -782,7 +782,7 @@ status_t perctrl_parse_log_args(char *buf) } for (uint32 i = 0; i < sizeof(g_perctrl_log_param) / sizeof(perctrl_log_param_set_t); i++) { if (strcmp(g_perctrl_log_param[i].name, key) == 0) { - return perctrl_parse_log_param_inner(g_perctrl_log_param[i].id, value); + return perctrl_parse_param_inner(g_perctrl_log_param[i].id, value); } } (void)printf("Invalid perctrl argument %s.\n", key); @@ -800,20 +800,19 @@ int32 exec_init_logger(perctrl_packet_t *req, perctrl_packet_t *ack) uint32 i = 0; char *temp = strtok_s(buf, "|", &next_info); while (temp != NULL) { - CM_RETURN_IFERR(perctrl_parse_log_args(temp)); + CM_RETURN_IFERR(perctrl_parse_args(temp)); temp = strtok_s(NULL, "|", &next_info); i++; } if (i != PERCTRL_PARAM_LOG_TOTAL_CNT) { (void)printf("Invalid split parameters count:%u.\n", i); - (void)printf("except \n"); + (void)printf("except \n"); return CM_ERROR; } status = perctrl_init_loggers(g_perctrl_log, sizeof(g_perctrl_log) / sizeof(cm_log_def_t), "perctrl"); CM_RETURN_IFERR_EX(status, (void)printf("Failed to init loggers.\n")); - return status; + return status; } static perctrl_cmd_hdl_t g_perctrl_cmd_handle[] = {