/*check replica basic info*/ EC_BOOL test_case_84_check_replica(const char *home, const UINT32 cdfs_md_id, const UINT32 replica_num, const void *tcid_vec, UINT32 *counter) { void *cdfsnpp_mod_mgr; void *task_mgr; UINT32 index; CSTRING *path[CDFS_TEST_READ_MAX_FILES]; EC_BOOL ret[CDFS_TEST_READ_MAX_FILES]; EC_BOOL continue_flag; for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++) { path[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } cdfsnpp_mod_mgr = cdfs_get_npp_mod_mgr(cdfs_md_id); dbg_log(SEC_0137_DEMO, 5)(LOGSTDOUT, "test_case_84_check_replica: cdfsnpp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, cdfsnpp_mod_mgr); task_mgr = task_new(cdfsnpp_mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++, (*counter) ++) { path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); ret[ index ] = EC_FALSE; task_inc(task_mgr, &(ret[ index ]), FI_cdfs_check_replicas, ERR_MODULE_ID, path[ index ], replica_num, tcid_vec); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++) { if(EC_TRUE == ret[ index ]) { dbg_log(SEC_0137_DEMO, 5)(LOGSTDOUT, "[SUCC] path: %s\n", (char *)cstring_get_str(path[ index ])); } else { continue_flag = EC_FALSE; dbg_log(SEC_0137_DEMO, 0)(LOGCONSOLE, "[FAIL] path: %s\n", (char *)cstring_get_str(path[ index ])); } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } } return (continue_flag); }
void taskc_node_sprint(CSTRING *cstring, const TASKC_NODE *taskc_node) { cstring_format(cstring, "tcid %s, comm %ld, size %ld\n", TASKC_NODE_TCID_STR(taskc_node), TASKC_NODE_COMM(taskc_node), TASKC_NODE_SIZE(taskc_node)); return; }
void cstring_construct_static(cstring* str,unsigned char* Begin,unsigned char* End){ /*DEBUG*/if(cstring_is_construct(str)){++_cstring_debug_ErrorPre;return;} if(Begin==0){ cstring_format(str); return; } str->Begin=Begin; str->End=End; str->DynamicFlag=hmLib_false; /*DEBUG*/++_cstring_debug_StaticCnt; /*DEBUG*/if(!cstring_is_construct(str))++_cstring_debug_ErrorStatic; }
void cstring_construct_dynamic(cstring* str,cstring_size_t size){ /*DEBUG*/if(cstring_is_construct(str)){++_cstring_debug_ErrorPre;return;} if(size==0){ cstring_format(str); return; } str->Begin=(unsigned char*)malloc(size); /*DEBUG*/if(str->Begin==0){++_cstring_debug_ErrorDynamic;return;} str->End=str->Begin+size; str->DynamicFlag=hmLib_true; /*DEBUG*/++_cstring_debug_DynamicCnt; }
void crouter_node_sprint_in_plain(CSTRING *cstring, const CROUTER_NODE *crouter_node, UINT32 *index) { UINT32 pos; CVECTOR_LOCK(CROUTER_NODE_NEXT_HOPS(crouter_node), LOC_CROUTER_0005); for(pos = 0; pos < cvector_size(CROUTER_NODE_NEXT_HOPS(crouter_node)); pos ++) { TASKS_NODE *tasks_node; tasks_node = (TASKS_NODE *)cvector_get_no_lock(CROUTER_NODE_NEXT_HOPS(crouter_node), pos); if(NULL_PTR == tasks_node) { cstring_format(cstring, "Route No. %ld: des tcid %s, next hop [%ld]: (null)\n", (*index) ++, CROUTER_NODE_DES_TCID_STR(crouter_node), pos); continue; } cstring_format(cstring, "Route No. %ld: des tcid %s, next hop [%ld]: ", (*index) ++, CROUTER_NODE_DES_TCID_STR(crouter_node), pos); tasks_node_sprint(cstring, tasks_node); } CVECTOR_UNLOCK(CROUTER_NODE_NEXT_HOPS(crouter_node), LOC_CROUTER_0006); return; }
/*check replica files*/ EC_BOOL test_case_85_crfs_check_file_content(const char *home, const UINT32 crfs_tcid, const UINT32 crfs_rank, const UINT32 crfs_modi, const UINT32 max_test_data_files, UINT32 *counter) { MOD_MGR *mod_mgr; TASK_MGR *task_mgr; UINT32 index; CSTRING *path[CRFS_TEST_READ_MAX_FILES]; EC_BOOL ret[CRFS_TEST_READ_MAX_FILES]; EC_BOOL continue_flag; for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++) { path[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } mod_mgr = mod_mgr_new(CMPI_ERROR_MODI, LOAD_BALANCING_LOOP); mod_mgr_incl(crfs_tcid, CMPI_ANY_COMM, crfs_rank, crfs_modi, mod_mgr); sys_log(LOGSTDOUT, "test_case_85_crfs_check_file_content: npp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_npp_mod_mgr(crfs_modi)); sys_log(LOGSTDOUT, "test_case_85_crfs_check_file_content: dn mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_dn_mod_mgr(crfs_modi)); task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++, (*counter) ++) { CBYTES *cbytes_des; cbytes_des = __test_crfs_fetch_g_cbytes(max_test_data_files, ((*counter) % max_test_data_files)); path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); ret[ index ] = EC_FALSE; task_inc(task_mgr, &(ret[ index ]), FI_crfs_check_file_is, ERR_MODULE_ID, path[ index ], cbytes_des); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++) { if(EC_TRUE == ret[ index ]) { sys_log(LOGSTDOUT, "[SUCC] path: %s\n", (char *)cstring_get_str(path[ index ])); } else { continue_flag = EC_FALSE; sys_log(LOGCONSOLE, "[FAIL] path: %s\n", (char *)cstring_get_str(path[ index ])); } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } } mod_mgr_free(mod_mgr); return (continue_flag); }
EC_BOOL test_case_83_crfs_write(const char *home, const UINT32 crfs_tcid, const UINT32 crfs_rank, const UINT32 crfs_modi, const UINT32 max_test_data_files, UINT32 *counter) { void *mod_mgr; void *task_mgr; UINT32 index; EC_BOOL continue_flag; CSTRING *path[CRFS_TEST_WRITE_MAX_FILES]; EC_BOOL ret[CRFS_TEST_WRITE_MAX_FILES]; for(index = 0; index < CRFS_TEST_WRITE_MAX_FILES; index ++) { path[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } mod_mgr = mod_mgr_new(CMPI_ERROR_MODI, LOAD_BALANCING_LOOP); mod_mgr_incl(crfs_tcid, CMPI_ANY_COMM, crfs_rank, crfs_modi, mod_mgr); #if 0 sys_log(LOGSTDOUT, "test_case_83_crfs_write: npp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_npp_mod_mgr(crfs_modi)); sys_log(LOGSTDOUT, "test_case_83_crfs_write: dn mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_dn_mod_mgr(crfs_modi)); #endif task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CRFS_TEST_WRITE_MAX_FILES; index ++, (*counter) ++) { void *cbytes; path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); ret[ index ] = EC_FALSE; cbytes = __test_crfs_fetch_g_cbytes(max_test_data_files, ((*counter) % max_test_data_files)); if(NULL_PTR == cbytes) { sys_log(LOGSTDOUT, "error:test_case_83_crfs_write: crfs buff is null where index = %ld, max_test_data_files = %ld\n", index, max_test_data_files); cstring_free(path[ index ]); path[ index ] = NULL_PTR; break; } task_inc(task_mgr, &(ret[ index ]), FI_crfs_write, ERR_MODULE_ID, path[ index ], cbytes); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NOT_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CRFS_TEST_WRITE_MAX_FILES; index ++) { if(EC_FALSE == ret[ index ] && NULL_PTR != path[ index ]) { continue_flag = EC_FALSE; sys_log(LOGCONSOLE, "test_case_83_crfs_write: [FAIL] %s\n", (char *)cstring_get_str(path[ index ])); } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } } mod_mgr_free(mod_mgr); return (continue_flag); }
EC_BOOL test_case_82_crfs_read(const char *home, const UINT32 crfs_tcid, const UINT32 crfs_rank, const UINT32 crfs_modi, const UINT32 max_test_data_files, UINT32 *counter) { void *mod_mgr; void *task_mgr; UINT32 index; CSTRING *path[CRFS_TEST_READ_MAX_FILES]; CBYTES *cbytes[CRFS_TEST_READ_MAX_FILES];/*read from dn*/ CBYTES *cbytes_des[CRFS_TEST_READ_MAX_FILES];/*benchmark*/ EC_BOOL ret[CRFS_TEST_READ_MAX_FILES]; EC_BOOL continue_flag; for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++) { path[ index ] = NULL_PTR; cbytes[ index ] = NULL_PTR; cbytes_des[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } mod_mgr = mod_mgr_new(CMPI_ERROR_MODI, LOAD_BALANCING_LOOP); mod_mgr_incl(crfs_tcid, CMPI_ANY_COMM, crfs_rank, crfs_modi, mod_mgr); #if 0 sys_log(LOGSTDOUT, "test_case_82_crfs_read: npp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_npp_mod_mgr(crfs_modi)); sys_log(LOGSTDOUT, "test_case_82_crfs_read: dn mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_dn_mod_mgr(crfs_modi)); #endif task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++, (*counter) ++) { path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); cbytes[ index ] = cbytes_new(0); cbytes_des[ index ] = __test_crfs_fetch_g_cbytes(max_test_data_files, ((*counter) % max_test_data_files)); ret[ index ] = EC_FALSE; task_inc(task_mgr, &(ret[ index ]), FI_crfs_read, ERR_MODULE_ID, path[ index ], cbytes[ index ]); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++) { if(NULL_PTR != cbytes[ index ]) { if(EC_TRUE == cbytes_ncmp(cbytes[ index ], cbytes_des[ index ], 16)) { sys_log(LOGSTDOUT, "[SUCC] path: %s, len = %ld ", (char *)cstring_get_str(path[ index ]), cbytes_len(cbytes[ index ])); sys_print(LOGSTDOUT, "text = %.*s\n", cbytes_len(cbytes[ index ]) > 16 ? 16 : cbytes_len(cbytes[ index ]), /*output up to 16 chars*/ (char *)cbytes_buf(cbytes[ index ])); } else { continue_flag = EC_FALSE; sys_log(LOGCONSOLE, "[FAIL] path: %s, read len = %ld ", (char *)cstring_get_str(path[ index ]), cbytes_len(cbytes[ index ])); sys_print(LOGCONSOLE, "text = %.*s <--> ", cbytes_len(cbytes[ index ]) > 16 ? 16 : cbytes_len(cbytes[ index ]), /*output up to 16 chars*/ (char *)cbytes_buf(cbytes[ index ])); sys_print(LOGCONSOLE, "expect len = %ld ", cbytes_len(cbytes_des[ index ])); sys_print(LOGCONSOLE, "text = %.*s\n", cbytes_len(cbytes_des[ index ]) > 16 ? 16 : cbytes_len(cbytes_des[ index ]), (char *)cbytes_buf(cbytes_des[ index ])); } } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } if(NULL_PTR != cbytes[ index ]) { cbytes_free(cbytes[ index ], 0); cbytes[ index ] = NULL_PTR; } if(NULL_PTR != cbytes_des[ index ]) { cbytes_des[ index ] = NULL_PTR; } } mod_mgr_free(mod_mgr); return (continue_flag); }
UINT32 cnetcard_collect(CSET *cnetcard_set, const UINT32 max_cnetcard_num) { int fd; struct ifreq *ifreq_tbl; struct ifconf ifc; struct sockaddr_in *in; UINT32 cnetcard_pos; UINT32 cnetcard_num; fd = csocket_open(AF_INET, SOCK_DGRAM, 0); if(0 > fd) { dbg_log(SEC_0011_CDEVICE, 0)(LOGSTDOUT, "error:cnetcard_collect: failed to create a socket\n"); return ((UINT32)-1); } ifreq_tbl = (struct ifreq *)SAFE_MALLOC(sizeof(struct ifreq) * max_cnetcard_num, LOC_CDEVICE_0003); if(NULL_PTR == ifreq_tbl) { dbg_log(SEC_0011_CDEVICE, 0)(LOGSTDOUT, "error:cnetcard_collect: failed to malloc %ld struct ifreq\n", max_cnetcard_num); csocket_close_force(fd); return ((UINT32)-1); } ifc.ifc_len = sizeof(struct ifreq) * max_cnetcard_num; ifc.ifc_buf = (caddr_t) ifreq_tbl; if (0 != ioctl(fd, SIOCGIFCONF, (char *) &ifc)) { dbg_log(SEC_0011_CDEVICE, 0)(LOGSTDOUT, "error:cnetcard_collect: failed to fetch %ld IF CONFIG\n", max_cnetcard_num); csocket_close_force(fd); SAFE_FREE(ifreq_tbl, LOC_CDEVICE_0004); return ((UINT32)-1); } cnetcard_num = ifc.ifc_len / sizeof(struct ifreq);/*actual device number*/ //dbg_log(SEC_0011_CDEVICE, 5)(LOGSTDOUT, "cnetcard_num = %ld\n", cnetcard_num); for(cnetcard_pos = 0; cnetcard_pos < cnetcard_num; cnetcard_pos ++) { CNETCARD *cnetcard; struct ifreq *ifreq_item; ifreq_item = (ifreq_tbl + cnetcard_pos); //dbg_log(SEC_0011_CDEVICE, 5)(LOGSTDOUT, "ifreq_tbl %lx, cnetcard_pos %lx => ifreq_item %lx\n", ifreq_tbl, cnetcard_pos, ifreq_item); cnetcard = cnetcard_new(); if(NULL_PTR == cnetcard) { dbg_log(SEC_0011_CDEVICE, 0)(LOGSTDOUT, "error:cnetcard_collect: failed to new CNETCARD when handle # %ld device\n", cnetcard_pos); csocket_close_force(fd); SAFE_FREE(ifreq_tbl, LOC_CDEVICE_0005); return ((UINT32)-1); } /*get device name*/ cstring_format(CNETCARD_NAME(cnetcard), "%s", ifreq_item->ifr_name); /*judge whether the net card status is up */ if(0 != ioctl(fd, SIOCGIFFLAGS, (char *)ifreq_item)) { dbg_log(SEC_0011_CDEVICE, 0)(LOGSTDOUT, "error:cnetcard_collect: failed to fetch # %ld device IF FLAGS\n", cnetcard_pos); cnetcard_free(cnetcard); continue; } if(ifreq_item->ifr_flags & IFF_UP) { CNETCARD_STATE(cnetcard) = CNETCARD_UP_STATE; } else { CNETCARD_STATE(cnetcard) = CNETCARD_DOWN_STATE; } /*get IP of the net card */ if (0 != ioctl(fd, SIOCGIFADDR, (char *)ifreq_item)) { dbg_log(SEC_0011_CDEVICE, 0)(LOGSTDOUT, "error:cnetcard_collect: failed to fetch # %ld device IF ADDR\n", cnetcard_pos); cnetcard_free(cnetcard); continue; } in = (struct sockaddr_in*) (&(ifreq_item->ifr_addr)); cstring_format(CNETCARD_IPV4STR(cnetcard), "%s", c_inet_ntos(&(in->sin_addr))); CNETCARD_IPV4VAL(cnetcard) = c_ipv4_to_word((char *)cstring_get_str(CNETCARD_IPV4STR(cnetcard))); /*get HW ADDRESS of the net card */ if(0 != ioctl(fd, SIOCGIFHWADDR, (char *)ifreq_item)) { dbg_log(SEC_0011_CDEVICE, 0)(LOGSTDOUT, "error:cnetcard_collect: failed to fetch # %ld device IF HW ADDR\n", cnetcard_pos); cnetcard_free(cnetcard); continue; } BCOPY(ifreq_item->ifr_hwaddr.sa_data, CNETCARD_MACADDR(cnetcard), 6); cstring_format(CNETCARD_MACSTR(cnetcard), "%02x:%02x:%02x:%02x:%02x:%02x", (UINT8) ifreq_item->ifr_hwaddr.sa_data[0], (UINT8) ifreq_item->ifr_hwaddr.sa_data[1], (UINT8) ifreq_item->ifr_hwaddr.sa_data[2], (UINT8) ifreq_item->ifr_hwaddr.sa_data[3], (UINT8) ifreq_item->ifr_hwaddr.sa_data[4], (UINT8) ifreq_item->ifr_hwaddr.sa_data[5] ); /*add to set*/ if(EC_FALSE == cset_add(cnetcard_set, (void *)cnetcard, (CSET_DATA_CMP)cnetcard_cmp)) { cnetcard_free(cnetcard); } } csocket_close_force(fd); SAFE_FREE(ifreq_tbl, LOC_CDEVICE_0006); //dbg_log(SEC_0011_CDEVICE, 3)(LOGSTDOUT, "info:cnetcard_collect: device list:\n"); //cset_print(LOGSTDOUT, cnetcard_set, (CSET_DATA_PRINT)cnetcard_print); return (0); }
void cstring_move(cstring* from, cstring* to){ to->DynamicFlag=from->DynamicFlag; to->Begin=from->Begin; to->End=from->End; cstring_format(from); }
/*check replica files*/ EC_BOOL test_case_85_cdfs_check_file_content(const char *home, const UINT32 cdfs_md_id, const UINT32 max_test_data_files, UINT32 *counter) { void *cdfsnpp_mod_mgr; void *task_mgr; UINT32 index; CSTRING *path[CDFS_TEST_READ_MAX_FILES]; CSTRING *file_content_cstr[CDFS_TEST_READ_MAX_FILES]; EC_BOOL ret[CDFS_TEST_READ_MAX_FILES]; EC_BOOL continue_flag; for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++) { path[ index ] = NULL_PTR; file_content_cstr[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } cdfsnpp_mod_mgr = cdfs_get_npp_mod_mgr(cdfs_md_id); dbg_log(SEC_0137_DEMO, 5)(LOGSTDOUT, "test_case_85_cdfs_check_file_content: cdfsnpp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, cdfsnpp_mod_mgr); task_mgr = task_new(cdfsnpp_mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++, (*counter) ++) { CBYTES *cbytes_des; cbytes_des = fetch_g_cbytes(cdfs_md_id, max_test_data_files, ((*counter) % max_test_data_files)); path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); file_content_cstr[ index ] = cstring_new(NULL_PTR, 0); cstring_append_chars(file_content_cstr[ index ], 16, cbytes_buf(cbytes_des)); ret[ index ] = EC_FALSE; task_inc(task_mgr, &(ret[ index ]), FI_cdfs_check_replica_files_content, ERR_MODULE_ID, path[ index ], cbytes_len(cbytes_des), file_content_cstr[ index ]); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++) { if(EC_TRUE == ret[ index ]) { dbg_log(SEC_0137_DEMO, 5)(LOGSTDOUT, "[SUCC] path: %s\n", (char *)cstring_get_str(path[ index ])); } else { continue_flag = EC_FALSE; dbg_log(SEC_0137_DEMO, 0)(LOGCONSOLE, "[FAIL] path: %s\n", (char *)cstring_get_str(path[ index ])); } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } if(NULL_PTR != file_content_cstr[ index ]) { cstring_free(file_content_cstr[ index ]); file_content_cstr[ index ] = NULL_PTR; } } return (continue_flag); }