EC_BOOL chfsnp_mgr_read(CHFSNP_MGR *chfsnp_mgr, const CSTRING *file_path, CHFSNP_FNODE *chfsnp_fnode) { CHFSNP *chfsnp; uint32_t chfsnp_id; uint32_t node_pos; chfsnp = __chfsnp_mgr_get_np(chfsnp_mgr, (uint32_t)cstring_get_len(file_path), cstring_get_str(file_path), &chfsnp_id); if(NULL_PTR == chfsnp) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_read: no np for path %s\n", (char *)cstring_get_str(file_path)); return (EC_FALSE); } node_pos = chfsnp_search_no_lock(chfsnp, (uint32_t)cstring_get_len(file_path), cstring_get_str(file_path)); if(CHFSNPRB_ERR_POS != node_pos) { CHFSNP_ITEM *chfsnp_item; chfsnp_item = chfsnp_fetch(chfsnp, node_pos); return chfsnp_fnode_import(CHFSNP_ITEM_FNODE(chfsnp_item), chfsnp_fnode); } sys_log(LOGSTDOUT, "[DEBUG] chfsnp_mgr_read: search nothing for path '%s'\n", (char *)cstring_get_str(file_path)); return (EC_FALSE); }
EC_BOOL chfsnp_mgr_write(CHFSNP_MGR *chfsnp_mgr, const CSTRING *file_path, const CHFSNP_FNODE *chfsnp_fnode) { CHFSNP *chfsnp; CHFSNP_ITEM *chfsnp_item; uint32_t chfsnp_id; chfsnp = __chfsnp_mgr_get_np(chfsnp_mgr, (uint32_t)cstring_get_len(file_path), cstring_get_str(file_path), &chfsnp_id); if(NULL_PTR == chfsnp) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_write: no np for path %s\n", (char *)cstring_get_str(file_path)); return (EC_FALSE); } chfsnp_item = chfsnp_set(chfsnp, cstring_get_len(file_path), cstring_get_str(file_path)); if(NULL_PTR == chfsnp_item) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_write: set file %s to np %u failed\n", (char *)cstring_get_str(file_path), chfsnp_id); return (EC_FALSE); } if(EC_FALSE == chfsnp_fnode_import(chfsnp_fnode, CHFSNP_ITEM_FNODE(chfsnp_item))) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_write: import fnode to item failed where path %s\n", (char *)cstring_get_str(file_path)); return (EC_FALSE); } sys_log(LOGSTDOUT, "[DEBUG] chfsnp_mgr_write: import fnode to item successfully where path %s\n", (char *)cstring_get_str(file_path)); chfsnp_item_print(LOGSTDOUT, chfsnp_item); return (EC_TRUE); }
/*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); }
CHFSNP_MGR *chfsnp_mgr_create(const uint8_t chfsnp_model, const uint32_t chfsnp_max_num, const uint8_t chfsnp_1st_chash_algo_id, const uint8_t chfsnp_2nd_chash_algo_id, const uint32_t chfsnp_bucket_max_num, const CSTRING *chfsnp_db_root_dir) { CHFSNP_MGR *chfsnp_mgr; uint32_t chfsnp_item_max_num; uint32_t chfsnp_id; if(EC_FALSE == chfsnp_model_item_max_num(chfsnp_model , &chfsnp_item_max_num)) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_create: invalid chfsnp model %u\n", chfsnp_model); return (NULL_PTR); } chfsnp_mgr = chfsnp_mgr_new(); CHFSNP_MGR_NP_MODEL(chfsnp_mgr) = chfsnp_model; CHFSNP_MGR_NP_1ST_CHASH_ALGO_ID(chfsnp_mgr) = chfsnp_1st_chash_algo_id; CHFSNP_MGR_NP_2ND_CHASH_ALGO_ID(chfsnp_mgr) = chfsnp_2nd_chash_algo_id; CHFSNP_MGR_NP_ITEM_MAX_NUM(chfsnp_mgr) = chfsnp_item_max_num; CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr) = chfsnp_max_num; cstring_clone(chfsnp_db_root_dir, CHFSNP_MGR_DB_ROOT_DIR(chfsnp_mgr)); for(chfsnp_id = 0; chfsnp_id < chfsnp_max_num; chfsnp_id ++) { const char *np_root_dir; CHFSNP *chfsnp; np_root_dir = (const char *)cstring_get_str(chfsnp_db_root_dir);/*Oops! int the same dire*/ chfsnp = chfsnp_create(np_root_dir, chfsnp_id, chfsnp_model, chfsnp_1st_chash_algo_id, chfsnp_2nd_chash_algo_id, chfsnp_bucket_max_num); if(NULL_PTR == chfsnp) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_create: create np %u failed\n", chfsnp_id); return (NULL_PTR); } chfsnp_close(chfsnp); cvector_push_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), (void *)NULL_PTR); cvector_push_no_lock(CHFSNP_MGR_NP_VEC(chfsnp_mgr), (void *)NULL_PTR); } if(EC_FALSE == chfsnp_mgr_create_db(chfsnp_mgr, chfsnp_db_root_dir)) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_create: create cfg db failed in root dir %s\n", (char *)cstring_get_str(chfsnp_db_root_dir)); chfsnp_mgr_free(chfsnp_mgr); return (NULL_PTR); } //chfsnp_mgr_free(chfsnp_mgr); return (chfsnp_mgr); }
EC_BOOL chfsnp_mgr_delete(CHFSNP_MGR *chfsnp_mgr, const CSTRING *path, CVECTOR *chfsnp_fnode_vec) { CHFSNP *chfsnp; uint32_t chfsnp_id; chfsnp = __chfsnp_mgr_get_np(chfsnp_mgr, (uint32_t)cstring_get_len(path), cstring_get_str(path), &chfsnp_id); if(NULL_PTR == chfsnp) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_delete: no np for path %s\n", (char *)cstring_get_str(path)); return (EC_FALSE); } return chfsnp_delete(chfsnp, (uint32_t)cstring_get_len(path), cstring_get_str(path), chfsnp_fnode_vec); }
EC_BOOL chfsnp_mgr_show_np(LOG *log, CHFSNP_MGR *chfsnp_mgr, const uint32_t chfsnp_id) { CHFSNP *chfsnp; chfsnp = CHFSNP_MGR_NP_GET_NO_LOCK(chfsnp_mgr, chfsnp_id); if(NULL_PTR == chfsnp) { CSTRING *home_dir; /*try to open the np and print it*/ chfsnp = chfsnp_mgr_open_np(chfsnp_mgr, chfsnp_id); if(NULL_PTR == chfsnp) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_show_np: open np %u failed\n", chfsnp_id); return (EC_FALSE); } home_dir = CHFSNP_MGR_NP_HOME_DIR(chfsnp_mgr, chfsnp_id); if(NULL_PTR == home_dir) { sys_log(log, "home dir: (null)\n"); } else { sys_log(log, "home dir: %s\n", (char *)cstring_get_str(home_dir)); } chfsnp_print(log, chfsnp); chfsnp_mgr_close_np(chfsnp_mgr, chfsnp_id); } else { CSTRING *home_dir; home_dir = CHFSNP_MGR_NP_HOME_DIR(chfsnp_mgr, chfsnp_id); if(NULL_PTR == home_dir) { sys_log(log, "home dir: (null)\n"); } else { sys_log(log, "home dir: %s\n", (char *)cstring_get_str(home_dir)); } chfsnp_print(log, chfsnp); } return (EC_TRUE); }
EC_BOOL csem_named_clean(CSEM *csem, const UINT32 location) { uint8_t *sem_name; /*close*/ if(EC_FALSE == csem_named_close(csem, location)) { dbg_log(SEC_0029_CSEM, 0)(LOGSTDOUT, "error:csem_named_clean: close csem %p failed where errno = %d, errstr = %s at %s:%ld\n", csem, errno, strerror(errno), MM_LOC_FILE_NAME(location), MM_LOC_LINE_NO(location)); return (EC_FALSE); } if(NULL_PTR == CSEM_NAME_CSTR(csem)) { return (EC_TRUE); } /*unlink*/ sem_name = cstring_get_str(CSEM_NAME_CSTR(csem)); if(EC_FALSE == csem_named_unlink(sem_name, location)) { dbg_log(SEC_0029_CSEM, 0)(LOGSTDOUT, "error:csem_named_clean: unlink sem %s failed where errno = %d, errstr = %s at %s:%ld\n", sem_name, errno, strerror(errno), MM_LOC_FILE_NAME(location), MM_LOC_LINE_NO(location)); return (EC_FALSE); } cstring_free(CSEM_NAME_CSTR(csem)); CSEM_NAME_CSTR(csem) = NULL_PTR; return (EC_TRUE);
/*for named semaphore: creates a new POSIX semaphore or opens an existing semaphore.*/ EC_BOOL csem_named_open(CSEM *csem, const uint8_t *name, const int oflag, const mode_t mode, const uint32_t value, const UINT32 location) { sem_t *sem; if(NULL_PTR != CSEM_NAME_CSTR(csem)) { dbg_log(SEC_0029_CSEM, 0)(LOGSTDOUT, "error:csem_named_open: csem %p has already set name %s at %s:%ld\n", csem, cstring_get_str(CSEM_NAME_CSTR(csem)), MM_LOC_FILE_NAME(location), MM_LOC_LINE_NO(location)); return (EC_FALSE); } CSEM_NAME_CSTR(csem) = cstring_new(name, location); if(NULL_PTR == CSEM_NAME_CSTR(csem)) { dbg_log(SEC_0029_CSEM, 0)(LOGSTDOUT, "error:csem_named_open: new cstring for csem %p failed where name %s\n", csem, name); return (EC_FALSE); } sem = sem_open((const char *)name, oflag, mode, value); if(SEM_FAILED == sem) { dbg_log(SEC_0029_CSEM, 0)(LOGSTDOUT, "error:csem_named_open: open sem of %s oflag %d mode_t %o value %u failed where errno = %d, errstr = %s at %s:%ld\n", name, oflag, mode, value, errno, strerror(errno), MM_LOC_FILE_NAME(location), MM_LOC_LINE_NO(location)); return (EC_FALSE); } CSEM_SEM(csem) = sem; return (EC_TRUE);
EC_BOOL chfsnp_mgr_show_cached_np(LOG *log, const CHFSNP_MGR *chfsnp_mgr) { uint32_t chfsnp_num; uint32_t chfsnp_pos; chfsnp_num = cvector_size(CHFSNP_MGR_NP_VEC(chfsnp_mgr)); for(chfsnp_pos = 0; chfsnp_pos < chfsnp_num; chfsnp_pos ++) { CHFSNP *chfsnp; chfsnp = CHFSNP_MGR_NP(chfsnp_mgr, chfsnp_pos); if(NULL_PTR != chfsnp) { CSTRING *home_dir; home_dir = CHFSNP_MGR_NP_HOME_DIR(chfsnp_mgr, chfsnp_pos); if(NULL_PTR == home_dir) { sys_log(log, "home dir: (null)\n"); } else { sys_log(log, "home dir: %s\n", (char *)cstring_get_str(home_dir)); } chfsnp_print(log, chfsnp); } } return (EC_TRUE); }
EC_BOOL chfsnp_mgr_create_db(CHFSNP_MGR *chfsnp_mgr, const CSTRING *chfsnp_db_root_dir) { char *chfsnp_mgr_db_name; int chfsnp_mgr_fd; chfsnp_mgr_db_name = __chfsnp_mgr_gen_db_name((char *)cstring_get_str(chfsnp_db_root_dir)); if(NULL_PTR == chfsnp_mgr_db_name) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_create_db: new str %s/%s failed\n", (char *)cstring_get_str(chfsnp_db_root_dir), CHFSNP_DB_NAME); return (EC_FALSE); } if(EC_TRUE == c_file_access(chfsnp_mgr_db_name, F_OK)) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_create_db: chfsnp mgr db %s already exist\n", chfsnp_mgr_db_name); safe_free(chfsnp_mgr_db_name, LOC_CHFSNPMGR_0015); return (EC_FALSE); } chfsnp_mgr_fd = c_file_open(chfsnp_mgr_db_name, O_RDWR | O_CREAT, 0666); if(ERR_FD == chfsnp_mgr_fd) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_create_db: open chfsnp mgr db %s failed\n", chfsnp_mgr_db_name); safe_free(chfsnp_mgr_db_name, LOC_CHFSNPMGR_0016); return (EC_FALSE); } if(EC_FALSE == __chfsnp_mgr_flush_db(chfsnp_mgr, chfsnp_mgr_fd)) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_create_db: flush db to chfsnp mgr db %s\n", chfsnp_mgr_db_name); c_file_close(chfsnp_mgr_fd); chfsnp_mgr_fd = ERR_FD; safe_free(chfsnp_mgr_db_name, LOC_CHFSNPMGR_0017); return (EC_FALSE); } c_file_close(chfsnp_mgr_fd); chfsnp_mgr_fd = ERR_FD; safe_free(chfsnp_mgr_db_name, LOC_CHFSNPMGR_0018); return (EC_TRUE); }
void cnetcard_print(LOG *log, const CNETCARD *cnetcard) { sys_log(log, "device name : %s\n", (char *)cstring_get_str(CNETCARD_NAME(cnetcard))); sys_log(log, "device ip addr: %s (%lx)\n", (char *)cstring_get_str(CNETCARD_IPV4STR(cnetcard)), CNETCARD_IPV4VAL(cnetcard)); sys_log(log, "device mac addr: %s\n", (char *)cstring_get_str(CNETCARD_MACSTR(cnetcard))); if(CNETCARD_UP_STATE == CNETCARD_STATE(cnetcard)) { sys_log(log, "device state : UP\n"); } else if (CNETCARD_DOWN_STATE == CNETCARD_STATE(cnetcard)) { sys_log(log, "device state : DOWN\n"); } else { sys_log(log, "device state : UNKNOWN\n"); } }
EC_BOOL chfsnp_mgr_exist(const CSTRING *chfsnp_db_root_dir) { char *chfsnp_mgr_db_name; chfsnp_mgr_db_name = __chfsnp_mgr_gen_db_name((char *)cstring_get_str(chfsnp_db_root_dir)); if(NULL_PTR == chfsnp_mgr_db_name) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_exist: new str %s/%s failed\n", (char *)cstring_get_str(chfsnp_db_root_dir), CHFSNP_DB_NAME); return (EC_FALSE); } if(EC_FALSE == c_file_access(chfsnp_mgr_db_name, F_OK)) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_exist: chfsnp mgr db %s not exist\n", chfsnp_mgr_db_name); safe_free(chfsnp_mgr_db_name, LOC_CHFSNPMGR_0029); return (EC_FALSE); } safe_free(chfsnp_mgr_db_name, LOC_CHFSNPMGR_0030); return (EC_TRUE); }
/*bind home_dir and name node, i.e., one name node owns unique home dir*/ EC_BOOL chfsnp_mgr_bind(CHFSNP_MGR *chfsnp_mgr, const CSTRING *path, const UINT32 chfsnp_id) { CSTRING *home_dir; CSTRING *home_dir_old; uint32_t home_dir_pos; ASSERT(cvector_size(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr)) == CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr)); if(CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr) <= chfsnp_id) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: max np num %u but chfsnp id %u overflow\n", CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr), chfsnp_id); return (EC_FALSE); } home_dir_pos = __chfsnp_mgr_get_np_id_of_path(chfsnp_mgr, (uint32_t)cstring_get_len(path), cstring_get_str(path)); if(CHFSNP_ERR_ID != home_dir_pos) { home_dir = cvector_get_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), home_dir_pos); sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: some dir %s already bound to np %u, thus cannot accept binding %s\n", (char *)cstring_get_str(home_dir), home_dir_pos, (char *)cstring_get_str(path)); return (EC_FALSE); } home_dir = cstring_dup(path); if(NULL_PTR == home_dir) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: dup %s failed\n", (char *)cstring_get_str(path)); return (EC_FALSE); } home_dir_old = (CSTRING *)cvector_set(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), chfsnp_id, (void *)home_dir); if(NULL_PTR != home_dir_old) { cstring_free(home_dir_old); } return (EC_TRUE); }
void chfsnp_mgr_print_db(LOG *log, const CHFSNP_MGR *chfsnp_mgr) { uint32_t chfsnp_home_dir_num; uint32_t chfsnp_home_dir_pos; uint32_t chfsnp_num; uint32_t chfsnp_id; sys_log(log, "chfsnp mgr db root dir : %s\n", (char *)CHFSNP_MGR_DB_ROOT_DIR_STR(chfsnp_mgr)); sys_log(log, "chfsnp model : %u\n", CHFSNP_MGR_NP_MODEL(chfsnp_mgr)); sys_log(log, "chfsnp 1st hash algo id : %u\n", CHFSNP_MGR_NP_1ST_CHASH_ALGO_ID(chfsnp_mgr)); sys_log(log, "chfsnp 2nd hash algo id : %u\n", CHFSNP_MGR_NP_2ND_CHASH_ALGO_ID(chfsnp_mgr)); sys_log(log, "chfsnp item max num : %u\n", CHFSNP_MGR_NP_ITEM_MAX_NUM(chfsnp_mgr)); sys_log(log, "chfsnp max num : %u\n", CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr)); chfsnp_home_dir_num = (uint32_t)cvector_size(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr)); for(chfsnp_home_dir_pos = 0; chfsnp_home_dir_pos < chfsnp_home_dir_num; chfsnp_home_dir_pos ++) { CSTRING *chfsnp_home_dir_cstr; chfsnp_home_dir_cstr = cvector_get_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), chfsnp_home_dir_pos); if(NULL_PTR == chfsnp_home_dir_cstr || EC_TRUE == cstring_is_empty(chfsnp_home_dir_cstr)) { sys_log(log, "home dir %u #: (null)\n", chfsnp_home_dir_pos); } else { sys_log(log, "home dir %u #: %.*s\n", chfsnp_home_dir_pos, cstring_get_len(chfsnp_home_dir_cstr), (char *)cstring_get_str(chfsnp_home_dir_cstr)); } } chfsnp_num = (uint32_t)cvector_size(CHFSNP_MGR_NP_VEC(chfsnp_mgr)); for(chfsnp_id = 0; chfsnp_id < chfsnp_num; chfsnp_id ++) { CHFSNP *chfsnp; chfsnp = CHFSNP_MGR_NP(chfsnp_mgr, chfsnp_id); if(NULL_PTR == chfsnp) { sys_log(log, "np %u #: (null)\n", chfsnp_id); } else { chfsnp_print(log, chfsnp); } } return; }
static uint32_t __chfsnp_mgr_get_np_id_of_path(const CHFSNP_MGR *chfsnp_mgr, const uint32_t path_len, const uint8_t *path) { uint32_t chfsnp_num; uint32_t chfsnp_id; ASSERT(CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr) == cvector_size(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr))); CHFSNP_MGR_NP_HOME_DIR_VEC_LOCK(chfsnp_mgr, LOC_CHFSNPMGR_0023); chfsnp_num = CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr); for(chfsnp_id = 0; chfsnp_id < chfsnp_num; chfsnp_id ++) { CSTRING *chfsnp_home_dir_cstr; uint32_t chfsnp_home_dir_len; uint8_t *chfsnp_home_dir_str; chfsnp_home_dir_cstr = CHFSNP_MGR_NP_HOME_DIR(chfsnp_mgr, chfsnp_id); if(NULL_PTR == chfsnp_home_dir_cstr || EC_TRUE == cstring_is_empty(chfsnp_home_dir_cstr)) { continue; } chfsnp_home_dir_len = (uint32_t)cstring_get_len(chfsnp_home_dir_cstr); chfsnp_home_dir_str = cstring_get_str(chfsnp_home_dir_cstr); sys_log(LOGSTDOUT, "[DEBUG] __chfsnp_mgr_get_np_id_of_path: %.*s vs %s\n", path_len, (char *)path, (char *)cstring_get_str(chfsnp_home_dir_cstr)); sys_log(LOGSTDOUT, "[DEBUG] __chfsnp_mgr_get_np_id_of_path: path_len %u, chfsnp_home_dir_len %u\n", path_len, chfsnp_home_dir_len); if(path_len < chfsnp_home_dir_len) { continue; } /*now path_len >= chfsnp_home_dir_len*/ if(path_len != chfsnp_home_dir_len && '/' != path[ chfsnp_home_dir_len ]) { continue; } if(0 == BCMP(path, chfsnp_home_dir_str, chfsnp_home_dir_len)) { CHFSNP_MGR_NP_HOME_DIR_VEC_UNLOCK(chfsnp_mgr, LOC_CHFSNPMGR_0024); return (chfsnp_id); } } CHFSNP_MGR_NP_HOME_DIR_VEC_UNLOCK(chfsnp_mgr, LOC_CHFSNPMGR_0025); return (CHFSNP_ERR_ID); }
EC_BOOL ccurl_get(const UINT32 ccurl_md_id, const CSTRING *url_str, const CSTRING *proxy_ip_port, CSTRING *curl_reply_body) { CURL *curl; CURLcode res; long status; #if ( SWITCH_ON == CCURL_DEBUG_SWITCH ) if ( CCURL_MD_ID_CHECK_INVALID(ccurl_md_id) ) { sys_log(LOGSTDOUT, "error:ccurl_get: ccurl module #0x%lx not started.\n", ccurl_md_id); ccurl_print_module_status(ccurl_md_id, LOGSTDOUT); dbg_exit(MD_CCURL, ccurl_md_id); } #endif/*CCURL_DEBUG_SWITCH*/ curl = curl_easy_init(); if(NULL_PTR == curl) { dbg_log(SEC_0030_CCURL, 0)(LOGSTDOUT, "error:ccurl_get: curl_easy_init failed\n"); return (EC_FALSE); } curl_easy_setopt(curl, CURLOPT_URL, (char *)cstring_get_str(url_str)); /* example.com is redirected, so we tell libcurl to follow redirection */ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_PROXY, (char *)cstring_get_str(proxy_ip_port)); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, __ccurl_write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, curl_reply_body); curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 120L); /*total download time in seconds*/ curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30L); /*total connect time in seconds*/ /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); /* Check for errors */ if(CURLE_OK != res) { dbg_log(SEC_0030_CCURL, 0)(LOGSTDOUT, "error:ccurl_get:curl_easy_perform() failed: %s where url '%s'\n", curl_easy_strerror(res), (char *)cstring_get_str(url_str)); curl_easy_cleanup(curl); return (EC_FALSE); } res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE , &status); if(CURLE_OK != res) { dbg_log(SEC_0030_CCURL, 0)(LOGSTDOUT, "error:ccurl_get:curl_easy_getinfo() failed: %s where url '%s'\n", curl_easy_strerror(res), (char *)cstring_get_str(url_str)); curl_easy_cleanup(curl); return (EC_FALSE); } if(CCURL_HTTP_OK != status) { dbg_log(SEC_0030_CCURL, 0)(LOGSTDOUT, "error:ccurl_get:reply status %d not OK! where url '%s'\n", status, (char *)cstring_get_str(url_str)); curl_easy_cleanup(curl); return (EC_FALSE); } /* always cleanup */ curl_easy_cleanup(curl); dbg_log(SEC_0030_CCURL, 9)(LOGSTDOUT, "[DEBUG] ccurl_get: GET '%s' from '%s' done\n", (char *)cstring_get_str(url_str), (char *)cstring_get_str(proxy_ip_port)); return (EC_TRUE); }
/*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); }
EC_BOOL chfsnp_mgr_load(CHFSNP_MGR *chfsnp_mgr, const CSTRING *chfsnp_db_root_dir) { cstring_clean(CHFSNP_MGR_DB_ROOT_DIR(chfsnp_mgr)); cstring_clone(chfsnp_db_root_dir, CHFSNP_MGR_DB_ROOT_DIR(chfsnp_mgr)); if(EC_FALSE == chfsnp_mgr_load_db(chfsnp_mgr)) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_load: load cfg db failed from dir %s\n", (char *)cstring_get_str(chfsnp_db_root_dir)); return (EC_FALSE); } return (EC_TRUE); }
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); }
EC_BOOL chfsnp_mgr_find(CHFSNP_MGR *chfsnp_mgr, const CSTRING *path) { return chfsnp_mgr_search(chfsnp_mgr, (uint32_t)cstring_get_len(path), cstring_get_str(path), NULL_PTR); }
/*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); }