From 4a7d37d28cf6a4880f521bdc7dfcafbdc727f046 Mon Sep 17 00:00:00 2001 From: zhaodu <545211984@qq.com> Date: Thu, 8 Dec 2022 19:35:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9dsscmd=5Finq?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 8 ++++- src/cmd/CMakeLists.txt | 9 +++++ src/cmd/dsscmd_inq.c | 80 +++++++++++------------------------------- src/cmd/dsscmd_inq.h | 1 + 4 files changed, 37 insertions(+), 61 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ea40cc..c904d36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.12.1) +CMAKE_MINIMUM_REQUIRED(VERSION 3.12.1) PROJECT(dss) message(${CMAKE_BUILD_TYPE}) @@ -95,6 +95,12 @@ IF (ENABLE_EXPORT_API) add_compile_options(-fvisibility=hidden) ENDIF() +OPTION(ENABLE_DSSTEST "Enable dss test" OFF) +message(STATUS "(ENABLE_DSSTEST = ${(ENABLE_DSSTEST}") +IF (ENABLE_DSSTEST) + add_definitions(-DENABLE_DSSTEST) +ENDIF() + execute_process( COMMAND uname -m OUTPUT_VARIABLE OS_ARCH diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index 3a1dbc6..9134ce8 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -39,3 +39,12 @@ else() target_link_libraries(dsscmd dssapi pthread dl rt -Wl,--whole-archive ${vpp_libsecurec} ${3rd_libssl} ${3rd_libccb} ${vpp_libipsi_crypto} -Wl,--no-whole-archive) endif(ENABLE_FUZZASAN) +if (ENABLE_DSSTEST) + add_library(dsscmd_test SHARED ${COMMON_ALL_SRC}) + if (ENABLE_FUZZASAN) + target_link_libraries(dsscmd_dest dssapi pthread dl rt -Wl,--whole-archive ${vpp_libsecurec} ${3rd_libssl} ${3rd_libccb} ${vpp_libipsi_crypto} ${fuzz_lib} -Wl,--no-whole-archive) + else() + target_link_libraries(dsscmd_test dssapi pthread dl rt -Wl,--whole-archive ${vpp_libsecurec} ${3rd_libssl} ${3rd_libccb} ${vpp_libipsi_crypto} -Wl,--no-whole-archive) + endif(ENABLE_FUZZASAN) +endif(ENABLE_DSSTEST) + diff --git a/src/cmd/dsscmd_inq.c b/src/cmd/dsscmd_inq.c index 01730ec..b9cc9f3 100644 --- a/src/cmd/dsscmd_inq.c +++ b/src/cmd/dsscmd_inq.c @@ -37,24 +37,17 @@ static void print_dev_info(ptlist_t *devs) uint32 i; dev_info_t *dev_info = NULL; text_t text; - status_t ret; for (i = 0; i < devs->count; i++) { dev_info = (dev_info_t *)cm_ptlist_get(devs, i); if (dev_info != NULL) { // trim vendor cm_str2text(dev_info->data.vendor_info.vendor, &text); cm_trim_text(&text); - ret = cm_text2str(&text, dev_info->data.vendor_info.vendor, CM_MAX_VENDOR_LEN); - if (ret != CM_SUCCESS) { - return; - } + DSS_RETURN_DRIECT_IFERR(cm_text2str(&text, dev_info->data.vendor_info.vendor, CM_MAX_VENDOR_LEN)); // trim product cm_str2text(dev_info->data.vendor_info.product, &text); cm_trim_text(&text); - ret = cm_text2str(&text, dev_info->data.vendor_info.product, CM_MAX_PRODUCT_LEN); - if (ret != CM_SUCCESS) { - return; - } + DSS_RETURN_DRIECT_IFERR(cm_text2str(&text, dev_info->data.vendor_info.product, CM_MAX_PRODUCT_LEN)); printf("%-20s%-20s%-20s%-20s%-15d%-20s\n", dev_info->dev, dev_info->data.vendor_info.vendor, dev_info->data.vendor_info.product, dev_info->data.array_info.array_sn, dev_info->data.lun_info.lun_id, dev_info->data.lun_info.lun_wwn); @@ -145,7 +138,7 @@ status_t inq_regs(void) return CM_SUCCESS; } -static bool32 is_register(iof_reg_in_t *reg, int64 host_id, int64 *iofence_key) +bool32 is_register(iof_reg_in_t *reg, int64 host_id, int64 *iofence_key) { for (int32 i = 0; i < reg->key_count; i++) { iofence_key[reg->reg_keys[i] - 1]++; @@ -190,10 +183,10 @@ static status_t dss_init_vg_info(dss_vg_info_t *vg_info) { uint32 len = DSS_MAX_STACK_BUF_SIZE + DSS_MAX_STACK_BUF_SIZE + DSS_MAX_STACK_BUF_SIZE + sizeof(dss_ctrl_t); char *buf = (char *)cm_malloc_align(DSS_ALIGN_SIZE, vg_info->group_num * len); - if (buf == NULL) { - LOG_DEBUG_ERR("cm_malloc_align stack failed, align size:%u, size:%u.", DSS_ALIGN_SIZE, len); - return CM_ERROR; - } + bool32 result = (bool32)(buf != NULL); + DSS_RETURN_IF_FALSE2( + result, LOG_DEBUG_ERR("cm_malloc_align stack failed, align size:%u, size:%u.", DSS_ALIGN_SIZE, len)); + for (uint32 i = 0; i < vg_info->group_num; i++) { vg_info->volume_group[i].buffer_cache = (shm_hashmap_t *)(buf + i * len); vg_info->volume_group[i].vg_latch = (latch_t *)(buf + i * len + DSS_MAX_STACK_BUF_SIZE); @@ -213,16 +206,9 @@ static status_t dss_init_vg_info(dss_vg_info_t *vg_info) static status_t dss_get_vg_entry_info(const char *home, dss_config_t *inst_cfg, dss_vg_info_t *vg_info) { status_t status = dss_set_cfg_dir(home, inst_cfg); - if (status != CM_SUCCESS) { - LOG_DEBUG_ERR("Environment variant DSS_HOME not found."); - return status; - } + DSS_RETURN_IFERR2(status, LOG_DEBUG_ERR("Environment variant DSS_HOME not found.")); status = dss_load_vg_conf_inner(vg_info, inst_cfg); - if (status != CM_SUCCESS) { - LOG_DEBUG_ERR("Failed to load vg conf inner."); - return status; - } - + DSS_RETURN_IFERR2(status, LOG_DEBUG_ERR("Failed to load vg conf inner.")); return dss_init_vg_info(vg_info); } @@ -248,15 +234,11 @@ status_t dss_check_volume_register(char *entry_path, int64 host_id, bool32 *is_r static status_t dss_reghl_inner(dss_vg_info_item_t *item, int64 host_id) { - status_t status; for (uint32 j = 1; j < DSS_MAX_VOLUMES; j++) { if (item->dss_ctrl->core.volume_attrs[j].flag == VOLUME_FREE) { continue; } - status = dss_iof_register_single(host_id, item->dss_ctrl->volume.defs[j].name); - if (status != CM_SUCCESS) { - return status; - } + CM_RETURN_IFERR(dss_iof_register_single(host_id, item->dss_ctrl->volume.defs[j].name)); } return CM_SUCCESS; } @@ -295,10 +277,8 @@ status_t dss_reghl_core(const char *home, int64 host_id, dss_vg_info_t *vg_info) #ifndef WIN32 dss_config_t inst_cfg; status_t status = dss_get_vg_entry_info(home, &inst_cfg, vg_info); - if (status != CM_SUCCESS) { - DSS_PRINT_ERROR("Failed to get vg entry info when reghl, errcode is %d.\n", status); - return status; - } + DSS_RETURN_IFERR2(status, DSS_PRINT_ERROR("Failed to get vg entry info when reghl, errcode is %d.\n", status)); + for (uint32 i = 0; i < vg_info->group_num; i++) { status = dss_iof_register_single(host_id, vg_info->volume_group[i].entry_path); if (status != CM_SUCCESS) { @@ -326,22 +306,13 @@ status_t dss_reghl_core(const char *home, int64 host_id, dss_vg_info_t *vg_info) static status_t dss_unreghl_inner(dss_vg_info_item_t *item, int64 host_id) { - status_t status; for (uint32 j = 1; j < DSS_MAX_VOLUMES; j++) { if (item->dss_ctrl->core.volume_attrs[j].flag == VOLUME_FREE) { continue; } - status = dss_iof_unregister_single(host_id, item->dss_ctrl->volume.defs[j].name); - if (status != CM_SUCCESS) { - return status; - } - } - status = dss_iof_unregister_single(host_id, item->entry_path); - if (status != CM_SUCCESS) { - return status; + CM_RETURN_IFERR(dss_iof_unregister_single(host_id, item->dss_ctrl->volume.defs[j].name)); } - - return CM_SUCCESS; + return dss_iof_unregister_single(host_id, item->entry_path); } /* @@ -358,10 +329,8 @@ status_t dss_unreghl_core(const char *home, int64 host_id, dss_vg_info_t *vg_inf dss_config_t inst_cfg; int64 iofence_key[DSS_MAX_INSTANCES] = {0}; status_t status = dss_get_vg_entry_info(home, &inst_cfg, vg_info); - if (status != CM_SUCCESS) { - DSS_PRINT_ERROR("Failed to get vg entry info, errcode is %d.\n", status); - return status; - } + DSS_RETURN_IFERR2(status, DSS_PRINT_ERROR("Failed to get vg entry info, errcode is %d.\n", status)); + for (uint32 i = 0; i < vg_info->group_num; i++) { status = dss_check_volume_register(vg_info->volume_group[i].entry_path, host_id, &is_reg, iofence_key); if (status != CM_SUCCESS) { @@ -393,22 +362,15 @@ status_t dss_unreghl_core(const char *home, int64 host_id, dss_vg_info_t *vg_inf static status_t dss_inq_reg_inner(dss_vg_info_t *vg_info, dss_config_t *inst_cfg, int64 host_id, int64 *iofence_key) { bool32 is_reg; - status_t status; dss_vg_info_item_t *item = NULL; for (uint32 i = 0; i < vg_info->group_num; i++) { - status = dss_get_vg_non_entry_info(inst_cfg, &vg_info->volume_group[i]); - if (status != CM_SUCCESS) { - return status; - } + CM_RETURN_IFERR(dss_get_vg_non_entry_info(inst_cfg, &vg_info->volume_group[i])); item = &vg_info->volume_group[i]; for (uint32 j = 1; j < DSS_MAX_VOLUMES; j++) { if (item->dss_ctrl->core.volume_attrs[j].flag == VOLUME_FREE) { continue; } - status = dss_check_volume_register(item->dss_ctrl->volume.defs[j].name, host_id, &is_reg, iofence_key); - if (status != CM_SUCCESS) { - return CM_ERROR; - } + CM_RETURN_IFERR(dss_check_volume_register(item->dss_ctrl->volume.defs[j].name, host_id, &is_reg, iofence_key)); if (!is_reg) { DSS_PRINT_INF("The node %lld is registered partially, inq_result = 1.\n", host_id); return CM_TIMEDOUT; @@ -433,10 +395,8 @@ status_t dss_inq_reg_core(const char *home, int64 host_id, dss_vg_info_t *vg_inf dss_config_t inst_cfg; int64 iofence_key[DSS_MAX_INSTANCES] = {0}; status_t status = dss_get_vg_entry_info(home, &inst_cfg, vg_info); - if (status != CM_SUCCESS) { - DSS_PRINT_ERROR("Failed to get vg entry info when inq reg, errcode is %d.\n", status); - return status; - } + DSS_RETURN_IFERR2(status, DSS_PRINT_ERROR("Failed to get vg entry info when inq reg, errcode is %d.\n", status)); + for (uint32 i = 0; i < vg_info->group_num; i++) { status = dss_check_volume_register(vg_info->volume_group[i].entry_path, host_id, &is_reg, iofence_key); if (status != CM_SUCCESS) { diff --git a/src/cmd/dsscmd_inq.h b/src/cmd/dsscmd_inq.h index 01dcbd2..4cceb1a 100644 --- a/src/cmd/dsscmd_inq.h +++ b/src/cmd/dsscmd_inq.h @@ -37,6 +37,7 @@ status_t dss_check_volume_register(char *entry_path, int64 host_id, bool32 *is_r status_t dss_unreghl_core(const char *home, int64 host_id, dss_vg_info_t *vg_info); status_t dss_reghl_core(const char *home, int64 host_id, dss_vg_info_t *vg_info); status_t dss_inq_reg_core(const char *home, int64 host_id, dss_vg_info_t *vg_info); +bool32 is_register(iof_reg_in_t *reg, int64 host_id, int64 *iofence_key); #ifdef __cplusplus } -- Gitee