Пример #1
0
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;
}
Пример #2
0
result_t libwrap_get_listener_links(int reg, memdb_integer nid, rf_link_t *links)
{
	int mask = 0;
	int subnode_num, i, j, index = 0;
	memdb_integer listener_nid = 0;
	char listener[256] = {0};
	struct node_info *subnode = NULL;

	subnode = libdb_list_subnode(DB_RMM, nid, &subnode_num, NULL, LOCK_ID_NULL);

	for (i = 0; i < subnode_num; i++) {
		listener_nid = libwrap_get_subnode_id_by_type(subnode[i].node_id, MC_REDFISH_LISTENER);
		if (listener_nid == 0)
			continue;

		libdb_attr_get_int(DB_RMM, listener_nid, RF_EVENT_LISTENER_INDEXES_STR, &mask, LOCK_ID_NULL);
		if ((mask & reg) != 0) {
			libdb_attr_get_string(DB_RMM, listener_nid, RF_EVENT_LISTENER_DEST_STR, listener, 256, LOCK_ID_NULL);
			for (j = 0; j < index; j++) {
				if (strcmp(listener, links->listeners[j]) == 0)
					break;
			}
			if (j == index) {
				snprintf_s_s(links->listeners[index], sizeof(links->listeners[index]), "%s", listener);
				index++;
			}
		}
	}

	return RESULT_OK;
}
Пример #3
0
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;
}
Пример #4
0
/**
 * @brief Generate redfish event map cache when redfishd initialize.
 *
 */
static int32 gen_node_msg_id_map(p_rf_node_msg_id_map evt_types)
{
	int32 i = 0, j = 0;
	int32 nodenum = 0;
	int32 index = 0;
	int32 evt_source_num = 0;
	struct node_info *evt_source_nodeinfo = NULL, *rf_node = NULL;
	int32 action_num = 0;
	struct node_info *action_node_info;

	/*Get redfish event nid*/
	rf_node = libdb_list_node_by_type(DB_RMM, MC_REDFISH_EVENT, MC_REDFISH_EVENT, &nodenum, NULL, LOCK_ID_NULL);
	if (nodenum == 0)
		return 0;

	evt_source_nodeinfo = libdb_list_subnode(DB_RMM, rf_node[0].node_id, &evt_source_num, NULL, LOCK_ID_NULL);
	if (evt_source_num == 0)
		return 0;

	/*traverse all of event sources*/
	for (i = 0; i < evt_source_num; i++) {
		action_node_info = libdb_list_subnode(DB_RMM, evt_source_nodeinfo[i].node_id, &action_num, NULL, LOCK_ID_NULL);
		for (j = 0; j < action_num; j++) {
			/*Load event type information.*/
			evt_types[index].node_id = action_node_info[j].node_id;
			libdb_attr_get_string(DB_RMM, action_node_info[j].node_id, MSG_ID_KEY, evt_types[index].msg_id_str, MSG_ID_STR_LEN, LOCK_ID_NULL);
			index += 1;
		}
	}

	/*The index is total of event types count.*/
	return index;
}
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;
}
Пример #6
0
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 int32 gen_asset_index(const int32 type, int32 loc_id,  memdb_integer node_id)
{
	int8 *name;
	struct node_info *pnode = NULL;
	int64 error_code = 0;
	int32 zone_num = 0;
	int32 cm_lid = 0;
	int32 index = 0;
	int8 rs[128] = {0};

	switch (type) {
	case MC_TYPE_PZONE:
		zone_num = MAX_PZONE_NUM;
		break;
	case MC_TYPE_TZONE:
		zone_num = MAX_TZONE_NUM;
		break;
	case MC_TYPE_DZONE:
		zone_num = MAX_DZONE_NUM;
		break;
	default:
		return loc_id;
	}

	pnode = libdb_get_node_by_node_id(DB_RMM, node_id, LOCK_ID_NULL);
	if (pnode == NULL) {
		 return -1;
	}

	memset(rs, 0, 128);
	error_code = 0;
	error_code = libdb_attr_get_string(DB_RMM, pnode->parent, MBP_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);
		return -1;
	}
	cm_lid = str2int(rs);

	index = (cm_lid - 1) * zone_num + loc_id;

	return index;
}
Пример #8
0
static void get_listeners_by_nid(memdb_integer nid, int location_idx, struct dest_info *listeners)
{
	struct node_info *subnode = NULL;
	int32 subnode_num = 0;
	int32 mask = 0;
	int32 lds_idx = 0;
	int32 i = 0;
	struct dest_info *tmp;
	int32 is_listen_validate_flag = 1;
	int64 error_code = 0;

	subnode = libdb_list_subnode_by_type(DB_RMM, nid, MC_REDFISH_LISTENER, &subnode_num, NULL, LOCK_ID_NULL);
	for (i = 0; i < subnode_num; i++) {
		if (location_idx != INVAILD_IDX) {
			error_code = libdb_attr_get_int(DB_RMM, subnode[i].node_id, RF_EVENT_LISTENER_INDEXES_STR, &mask, LOCK_ID_NULL);
			if (error_code != 0)
				continue;
			if (location_idx < 1)
				continue;
			if ((mask & (1<<(location_idx - 1))) == 0)
				is_listen_validate_flag = 0;
			else
				is_listen_validate_flag = 1;
		} else
			is_listen_validate_flag = 1;

		if (is_listen_validate_flag == 1) {
			error_code = libdb_attr_get_string(DB_RMM, subnode[i].node_id, RF_EVENT_LISTENER_DEST_STR, listeners->dest, 256, LOCK_ID_NULL);
			if (error_code == 0) {
				tmp = (struct dest_info *)malloc(sizeof(struct dest_info));
				if (tmp == NULL)
					continue;
				listeners->pnext = tmp;
				listeners = tmp;
				listeners->pnext = NULL;
			}
		}
	}
}
Пример #9
0
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;
}
Пример #10
0
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;
}
Пример #11
0
int main(int argc, char **argv)
{
	int fd;
	int port;
	pthread_t	tid_ipmi_cb;
	pthread_t	tid_asset_module_set_attr;
	gami_reg_t reg_info = {{0}};
	char value[WRAP_DB_MAX_VALUE_LEN] = {0};
	int64 error_code;
	memdb_integer root_service_nid = 0;
	memdb_integer rmc_nid = 0;
	struct node_info *pnode = NULL;
	int32 node_num = 0;

	reg_sigterm_handler(sigterm_handler);

	if (rmm_modules_init(MODULEINIT_LOG | MODULEINIT_COREDUMP | MODULEINIT_REDFISHD,
				ASSETMGR_JSONRPC_PORT,
				JSONRPCINIT_MEMDB | JSONRPCINIT_JIPMI) == -1) {
		exit(-1);
	}

	rmm_log(INFO, "Assetd daemon is Running ...\n");

	create_listen_socket(&fd);

	libdb_is_ready(DB_RMM, LOCK_ID_NULL, -1);
	error_code = libdb_attr_get_string(DB_RMM, MC_NODE_ROOT, RACK_FW_VER_STR, value, WRAP_DB_MAX_VALUE_LEN, LOCK_ID_NULL);
	if (error_code == 0) {
		/*TODO: compare the fw version to decide if need to do db-migration. */
	}

	init_rack_attr();

	pnode = libdb_list_node_by_type(DB_RMM, MC_TYPE_V1, MC_TYPE_V1, &node_num, NULL, LOCK_ID_NULL);
	if ((pnode == NULL) || (node_num == 0)) {
		root_service_nid = libdb_create_node(DB_RMM, MC_NODE_ROOT, MC_TYPE_V1, SNAPSHOT_NEED, LOCK_ID_NULL);
		if (root_service_nid == 0) {
			rmm_log(ERROR, "Failed to create root service node!\n");
			return -1;
		}
		init_root_service_attr(&root_service_nid, PERSISTENT_ALL);

		rmc_nid = libdb_create_node(DB_RMM, root_service_nid, MC_TYPE_RMC, SNAPSHOT_NEED, LOCK_ID_NULL);
		if (rmc_nid == 0) {
			rmm_log(ERROR, "Failed to create root service node!\n");
			return -1;
		}
		init_rmc_attr(&rmc_nid, PERSISTENT_ALL);
	} else {
		root_service_nid = pnode[0].node_id;
		init_root_service_attr(&root_service_nid, PERSISTENT_N);

		pnode = libdb_list_subnode_by_type(DB_RMM, root_service_nid, MC_TYPE_RMC, &node_num, NULL, LOCK_ID_NULL);
		if (pnode != NULL)
			rmc_nid = pnode[0].node_id;
		init_rmc_attr(&rmc_nid, PERSISTENT_N);
	}

	if (pthread_create(&tid_ipmi_cb, NULL, ipmi_cb_thread, NULL) != 0) {
		rmm_log(ERROR, "Failed to create ipmi callback thread!\n");
		return -1;
	}

	if (pthread_create(&tid_asset_module_set_attr, NULL, asset_module_set_gami_attr_thread, NULL) != 0) {
		rmm_log(ERROR, "Failed to create asset module notify thread!\n");
		return -1;
	}

	main_loop(fd);
	return 0;
}