static memdb_integer get_rf_node_id(void) { int32 output = 0; struct node_info *subnode = NULL; int32 subnode_num = 0; int32 retry = 3; memdb_integer node_id = 0; while (retry--) { subnode = libdb_list_node_by_type(DB_RMM, MC_REDFISH, MC_REDFISH, &subnode_num, NULL, LOCK_ID_NULL); if (subnode) break; sleep(1); } if (subnode_num != 1 || subnode == NULL) { libdb_free_node(subnode); rmm_log(ERROR, "failed to get subnode\n"); return 0; } node_id = subnode[0].node_id; libdb_free_node(subnode); return node_id; }
static bool get_index_by_uuid(const int8 *uuid, const int32 type, int32 *index) { struct node_info *subnode = NULL; struct node_info *sub_node = NULL; int32 subnode_num = 0; int32 i; int8 rs[128] = {0}; int64 error_code = 0; int32 loc_id = 0; subnode = libdb_list_node_by_type(DB_RMM, (uint32)type, (uint32)type, &subnode_num, NULL, LOCK_ID_NULL); if (subnode == NULL) { rmm_log(ERROR, "get subnode error\n"); return FALSE; } sub_node = (struct node_info *)malloc(sizeof(struct node_info) * subnode_num); if (sub_node == NULL) { rmm_log(ERROR, "malloc error\n"); return FALSE; } memcpy_s(sub_node, sizeof(struct node_info) * subnode_num, subnode, sizeof(struct node_info) * subnode_num); for (i = 0; i < subnode_num; i++) { memset(rs, 0, 128); error_code = 0; error_code = libdb_attr_get_string(DB_RMM, sub_node[i].node_id, WRAP_UUID_STR, rs, 128, LOCK_ID_NULL); if (error_code != 0) { rmm_log(ERROR, "%s:%d: error code:%d\n", __func__, __LINE__, error_code); libdb_free_node(sub_node); return FALSE; } else { if (0 == strcasecmp(uuid, rs)) { memset(rs, 0, 128); error_code = 0; error_code = libdb_attr_get_string(DB_RMM, sub_node[i].node_id, WRAP_LOC_ID_STR, rs, 128, LOCK_ID_NULL); if (error_code != 0) { rmm_log(ERROR, "%s:%d: error code:%d\n", __func__, __LINE__, error_code); libdb_free_node(sub_node); return FALSE; } else if (index != NULL) { loc_id = str2int(rs); *index = gen_asset_index(type, loc_id, sub_node[i].node_id); libdb_free_node(sub_node); return TRUE; } } } } libdb_free_node(sub_node); return FALSE; }
memdb_integer libwrap_get_listener_id_by_dest(char *dest, memdb_integer parent, int type) { int i = 0; char output[1024] = {0}; struct node_info *subnode = NULL; struct node_info *sub_node = NULL; int subnode_num = 0; if (dest == NULL) { return 0; } subnode = libdb_list_subnode_by_type(DB_RMM, parent, type, &subnode_num, NULL, LOCK_ID_NULL); sub_node = (struct node_info *)malloc(CMDBUFSIZ); if (sub_node == NULL) { return 0; } memcpy_s(sub_node, sizeof(struct node_info) * subnode_num, subnode, sizeof(struct node_info) * subnode_num); for (i = 0; i < subnode_num; i++) { libdb_attr_get_string(DB_RMM, sub_node[i].node_id, RF_EVENT_LISTENER_DEST_STR, output, 1024, LOCK_ID_NULL); if (0 == strcmp(dest, output)) return sub_node[i].node_id; } libdb_free_node(sub_node); return 0; }
memdb_integer libwrap_get_listener(char *dest, memdb_integer *evt_nid, int type) { int nodenum = 0; memdb_integer listener_nid = 0; struct node_info *nodeinfo; nodeinfo = libdb_list_node_by_type(DB_RMM, type, type, &nodenum, NULL, LOCK_ID_NULL); if (nodenum != 1) { libdb_free_node(nodeinfo); return -1; } *evt_nid = nodeinfo->node_id; listener_nid = libwrap_get_listener_id_by_dest(dest, *evt_nid, MC_REDFISH_LISTENER); libdb_free_node(nodeinfo); return listener_nid; }
static bool get_index_by_uuid(const int8 *uuid, const int32 type, int32 *index) { struct node_info *subnode = NULL; int32 subnode_num = 0; int32 i; int8 rs[128] = {0}; int64 error_code = 0; int32 loc_id = 0; subnode = libdb_list_node_by_type(DB_RMM, (uint32)type, (uint32)type, &subnode_num, NULL, LOCK_ID_NULL); for (i = 0; i < subnode_num; i++) { memset(rs, 0, 128); error_code = 0; error_code = libdb_attr_get_string(DB_RMM, subnode[i].node_id, (int8 *)type_key[type].uuid_key, rs, 128, LOCK_ID_NULL); if (error_code != 0) { rmm_log(ERROR, "%s:%d: error code:%d\n", __func__, __LINE__, error_code); libdb_free_node(subnode); return FALSE; } else { if (0 == strcmp(uuid, rs)) { memset(rs, 0, 128); error_code = 0; error_code = libdb_attr_get_string(DB_RMM, subnode[i].node_id, (int8 *)type_key[type].id_key, rs, 128, LOCK_ID_NULL); if (error_code != 0) { rmm_log(ERROR, "%s:%d: error code:%d\n", __func__, __LINE__, error_code); libdb_free_node(subnode); return FALSE; } else if (index != NULL) { loc_id = str2int(rs); *index = gen_asset_index(type, loc_id, subnode[i].node_id); libdb_free_node(subnode); return TRUE; } } } } libdb_free_node(subnode); return FALSE; }
static void *asset_module_set_gami_attr_thread() { int attr_set = -1; long expire = 0; memdb_integer reg_node_id = 0; int self_ip = 0; int port = 0; int self_port = 0; int i = 0; char cap_name[GAMI_MAX_NAME_LEN] = {0}; struct node_info *subnode = NULL; struct node_info *sub_node = NULL; int node_num = 0; prctl(PR_SET_NAME, "attr_thread"); while(attr_set) { subnode = libdb_list_subnode_by_type(DB_RMM, MC_NODE_ROOT, MC_TYPE_REG, &node_num, NULL, LOCK_ID_NULL); if (node_num != 1) { rmm_log(ERROR, "invalid registry node num in memdb\n"); continue; } sub_node = (struct node_info *)malloc(CMDBUFSIZ); if (sub_node == NULL) { return 0; } memcpy_s(sub_node, sizeof(struct node_info) * node_num, subnode, sizeof(struct node_info) * node_num); reg_node_id = sub_node[0].node_id; subnode = libdb_list_subnode_by_type(DB_RMM, reg_node_id, MC_TYPE_REG_MODULE, &node_num, NULL, LOCK_ID_NULL); if (node_num == 0) { rmm_log(ERROR, "no asset module registry info found\n"); continue; } memset(sub_node, 0, CMDBUFSIZ); memcpy_s(sub_node, sizeof(struct node_info) * node_num, subnode, sizeof(struct node_info) * node_num); for (i = 0; i < node_num; i++) { libdb_attr_get_string(DB_RMM, sub_node[i].node_id, JRPC_GAMI_REG_NAME, cap_name, GAMI_MAX_NAME_LEN, LOCK_ID_NULL); if (strcmp(cap_name, PROC_ASSET_MODULE) == 0) { libdb_attr_get_int(DB_RMM, sub_node[i].node_id, JRPC_GAMI_REG_PORT, &port, LOCK_ID_NULL); connect_asset_module(port); self_port = rmm_cfg_get_port(ASSETD_PORT); if(asset_module_set_gami_attr(&self_ip, &self_port) != -1) { rmm_log(INFO, "asset module set gami attr success\n"); attr_set = 0; break; } } } libdb_free_node(sub_node); sleep(1); } return NULL; }
static result_t get_listeners(int32 mask, listener_t** header) { struct node_info *subnode = NULL; int32 subnode_num = 0; struct node_info *listener_subnode = NULL; struct node_info *listener_sub_node = NULL; int32 listener_subnode_num = 0; int32 i,j = 0; memdb_integer error_code = 0; int32 subscribe_mask = 0; int8 tmp_url[MAX_URL] = {0}; listener_dest_t listener = {}; int32 listener_count = 0; struct node_info *evt_type_nodes = NULL; result_t rc = RESULT_OK; /* get event root node */ subnode = libdb_list_node_by_type(DB_RMM, MC_REDFISH_EVENT, MC_REDFISH_EVENT, &subnode_num, NULL, LOCK_ID_NULL); if (subnode_num != 1) { rc = RESULT_NO_NODE; goto end; } /* get supported event type nodes */ subnode = libdb_list_subnode(DB_RMM, subnode[0].node_id, &subnode_num, NULL, LOCK_ID_NULL); if (subnode_num == 0) { rc = RESULT_NO_NODE; goto end; } evt_type_nodes = (struct node_info *)malloc(CMDBUFSIZ); if (evt_type_nodes == NULL) { rc = RESULT_MALLOC_ERR; goto end; } memcpy_s(evt_type_nodes, sizeof(struct node_info) * subnode_num, subnode, sizeof(struct node_info) * subnode_num); listener_sub_node = (struct node_info *)malloc(CMDBUFSIZ); if (listener_sub_node == NULL) { rc = RESULT_MALLOC_ERR; goto end; } for (i = 0; i < subnode_num; i++) { /* get listeners of each event type */ listener_subnode = libdb_list_subnode_by_type(DB_RMM, evt_type_nodes[i].node_id, MC_REDFISH_LISTENER, &listener_subnode_num, NULL, LOCK_ID_NULL); if (listener_subnode == NULL) goto end; bzero(listener_sub_node, CMDBUFSIZ); memcpy_s(listener_sub_node, sizeof(struct node_info) * listener_subnode_num, listener_subnode, sizeof(struct node_info) * listener_subnode_num); for (j = 0; j < listener_subnode_num; j++) { error_code = 0; /* get listener's mask */ error_code = libdb_attr_get_int(DB_RMM, listener_sub_node[j].node_id, RF_EVENT_LISTENER_INDEXES_STR, &subscribe_mask, LOCK_ID_NULL); if (error_code != 0) continue; if ((subscribe_mask & mask) != 0) { error_code = 0; error_code = libdb_attr_get_string(DB_RMM, listener_sub_node[j].node_id, RF_EVENT_LISTENER_DEST_STR, tmp_url, sizeof(tmp_url), LOCK_ID_NULL); if (error_code == 0) { if (libdb_attr_get_string(DB_RMM, listener_sub_node[j].node_id, RF_EVENT_LISTENER_CONTEXT_STR, listener.context, sizeof(listener.context), LOCK_ID_NULL) != 0) continue; if (libdb_attr_get_string(DB_RMM, listener_sub_node[j].node_id, RF_EVENT_LISTENER_PROTOCOL_STR, listener.protocol, sizeof(listener.protocol), LOCK_ID_NULL) != 0) continue; if (libdb_attr_get_string(DB_RMM, listener_sub_node[j].node_id, RF_EVENT_LISTENER_NAME_STR, listener.name, sizeof(listener.name), LOCK_ID_NULL) != 0) continue; if (libdb_attr_get_string(DB_RMM, listener_sub_node[j].node_id, RF_EVENT_LISTENER_DESC_STR, listener.description, sizeof(listener.description), LOCK_ID_NULL) != 0) continue; /* add matched listener into list */ add_listener(header, tmp_url, &listener, evt_type_nodes[i].type); } } } } end: libdb_free_node(listener_sub_node); libdb_free_node(evt_type_nodes); return rc; }
static result_t del_listener(int8 *url) { struct node_info *subnode = NULL; struct node_info *listener_subnode = NULL; struct node_info *listener_sub_node = NULL; int32 subnode_num = 0; int32 listener_subnode_num = 0; int32 i,j = 0; memdb_integer error_code = 0; int8 tmp_url[MAX_URL] = {0}; int32 listener_count = 0; struct node_info *evt_type_nodes = NULL; result_t rc = RESULT_OK; /* get event root node */ subnode = libdb_list_node_by_type(DB_RMM, MC_REDFISH_EVENT, MC_REDFISH_EVENT, &subnode_num, NULL, LOCK_ID_NULL); if (subnode_num != 1) { rc = RESULT_NO_NODE; goto end; } /* get supported event type nodes */ subnode = libdb_list_subnode(DB_RMM, subnode[0].node_id, &subnode_num, NULL, LOCK_ID_NULL); if (subnode_num == 0) { rc = RESULT_NO_NODE; goto end; } evt_type_nodes = (struct node_info *)malloc(CMDBUFSIZ); if (evt_type_nodes == NULL) { rc = RESULT_MALLOC_ERR; goto end; } memcpy_s(evt_type_nodes, sizeof(struct node_info) * subnode_num, subnode, sizeof(struct node_info) * subnode_num); for (i = 0; i < subnode_num; i++) { /* get listeners of each event type */ listener_subnode = libdb_list_subnode_by_type(DB_RMM, evt_type_nodes[i].node_id, MC_REDFISH_LISTENER, &listener_subnode_num, NULL, LOCK_ID_NULL); if (listener_subnode == NULL) goto end; listener_sub_node = (struct node_info *)malloc(CMDBUFSIZ); if (listener_sub_node == NULL) { rc = RESULT_MALLOC_ERR; goto end; } memcpy_s(listener_sub_node, sizeof(struct node_info) * listener_subnode_num, listener_subnode, sizeof(struct node_info) * listener_subnode_num); for (j = 0; j < listener_subnode_num; j++) { if (libdb_attr_get_string(DB_RMM, listener_sub_node[j].node_id, RF_EVENT_LISTENER_DEST_STR, tmp_url, sizeof(tmp_url), LOCK_ID_NULL) != 0) goto end; if (strcmp(tmp_url, url) == 0) libdb_destroy_node(DB_RMM, listener_sub_node[j].node_id, LOCK_ID_NULL); } } end: if (listener_sub_node) libdb_free_node(listener_sub_node); if (evt_type_nodes) libdb_free_node(evt_type_nodes); return rc; }