⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmp_bc_event.c

📁 HIP 硬件设备管理标准接口
💻 C
📖 第 1 页 / 共 3 页
字号:
			}		}	}      /* Use resource's severity, if unexpected failure */	if (!sensor_severity_override && eventmap_info->event_res_failure_unexpected) {		SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, event->Source);		if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE);		*event_severity	= rpt->ResourceSeverity;	}	return(SA_OK);}/** * snmp_bc_set_cur_prev_event_states: * @handle: Handler data pointer. * @eventmap_info: Event state and recovery information pointer. * @event: Location to store current/previous event infomation. * @recovery_event: Is the event a recovery event or not. * * Attempts to set the optional current and previous state information * in an event. * * NOTES: * A sensor's previous state depends on if it is readable or not. If  * the sensor is not readable, then the previous state is just the state * of the sensor's last processed event. If the sensor is readable, * the previous state is set to the sensor's current state when the * last event was processed. That is when an event is processed, * the sensor is read and the info stored to be placed in the previous * state field for the next time an event for that sensor is processed. *  * For non-readable sensors, current state is simply the processed  * event's state. * * This routine is optional for sensors; but NOT hotswap.  * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. **/static SaErrorT snmp_bc_set_cur_prev_event_states(struct oh_handler_state *handle,						  EventMapInfoT *eventmap_info,						  SaHpiEventT *event,						  int recovery_event){	SaErrorT err;	if (!handle || !eventmap_info || !event) {		dbg("Invalid parameters.");		return(SA_ERR_HPI_INVALID_PARAMS);	}	switch (event->EventType) {	case SAHPI_ET_SENSOR:	{		SaHpiSensorReadingT cur_reading;		SaHpiEventStateT cur_state, prev_state;		struct SensorInfo *sinfo;		/* Set previous state to sensor's current state */		SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, event->Source, SAHPI_SENSOR_RDR,						    event->EventDataUnion.SensorEvent.SensorNum);		if (rdr == NULL) {			return(SA_ERR_HPI_NOT_PRESENT);		}		sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, event->Source, rdr->RecordId);		if (sinfo == NULL) {			dbg("No sensor data. Sensor=%s.", rdr->IdString.Data);			return(SA_ERR_HPI_INTERNAL_ERROR);		}		/* Record previous state info */		prev_state = sinfo->cur_state;		/* Try to read sensor to get and record the current state */		err = snmp_bc_get_sensor_reading((void *)handle,						 event->Source,						 event->EventDataUnion.SensorEvent.SensorNum,						 &cur_reading,						 &cur_state);				/* If can't read sensor (error, sensor disabled, or event-only), 		   use static event state definitions */		if (err || cur_reading.IsSupported == SAHPI_FALSE) {			if (recovery_event) {				cur_state = sinfo->cur_state = eventmap_info->sensor_recovery_state;			}			else {				cur_state = sinfo->cur_state = event->EventDataUnion.SensorEvent.EventState;			}		}		else {			sinfo->cur_state = cur_state;		}#if 0		{       /* Debug section */			SaHpiTextBufferT buffer;						dbg("Event for Sensor=%s", rdr->IdString.Data);			oh_decode_eventstate(prev_state, event->EventDataUnion.SensorEvent.EventCategory, &buffer);			dbg("  Previous Event State: %s.", buffer.Data);			oh_decode_eventstate(cur_state, event->EventDataUnion.SensorEvent.EventCategory, &buffer);			dbg("  Current Event State: %s\n", buffer.Data);		}#endif				/* Set previous and current state event info */		event->EventDataUnion.SensorEvent.PreviousState = prev_state;		event->EventDataUnion.SensorEvent.CurrentState = cur_state;		event->EventDataUnion.SensorEvent.OptionalDataPresent =			event->EventDataUnion.SensorEvent.OptionalDataPresent |			SAHPI_SOD_PREVIOUS_STATE |			SAHPI_SOD_CURRENT_STATE;		break;	}	case SAHPI_ET_HOTSWAP:	{		struct ResourceInfo *resinfo;		resinfo = (struct ResourceInfo *)oh_get_resource_data(handle->rptcache, event->Source);		if (resinfo == NULL) {			dbg("No resource data. RID=%x", event->Source);			return(SA_ERR_HPI_INTERNAL_ERROR);		}		event->EventDataUnion.HotSwapEvent.PreviousHotSwapState	= resinfo->cur_state;				if (recovery_event) {			event->EventDataUnion.HotSwapEvent.HotSwapState =				resinfo->cur_state =				eventmap_info->hotswap_recovery_state;		}		else {			event->EventDataUnion.HotSwapEvent.HotSwapState =				resinfo->cur_state =				event->EventDataUnion.HotSwapEvent.HotSwapState;		}		break;	}	default:		dbg("Unrecognized Event Type=%s.", oh_lookup_eventtype(event->EventType));		return(SA_ERR_HPI_INTERNAL_ERROR);	}		return(SA_OK);}/** * snmp_bc_map2oem: * @event: Pointer to handler's data. * @sel_entry: Error Log's "Source" field string. * @reason: Location to store HPI mapping data for resource. * * Any event not explicitly recognized is mapped into an HPI  * OEM event. This routine performs the mapping.  * * NOTE: * A reason code is passed, if in the future we record in some temp file,  * non-mapped events. Reason records why the event wasn't mapped. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. **/static SaErrorT snmp_bc_map2oem(SaHpiEventT *event,				sel_entry *sel_entry,				OEMReasonCodeT reason){	if (!event || !sel_entry) {		dbg("Invalid parameter.");		return(SA_ERR_HPI_INVALID_PARAMS);	}	trace("OEM Event Reason Code=%s\n", reason ? "NOT_ALERTABLE" : "NOT MAPPED");	event->EventType = SAHPI_ET_OEM;	event->EventDataUnion.OemEvent.MId = IBM_MANUFACTURING_ID;	/* Language set to ENGLISH, default  */	oh_init_textbuffer(&(event->EventDataUnion.OemEvent.OemEventData));	strncpy(event->EventDataUnion.OemEvent.OemEventData.Data,		sel_entry->text, SAHPI_MAX_TEXT_BUFFER_LENGTH - 1);	event->EventDataUnion.OemEvent.OemEventData.Data[SAHPI_MAX_TEXT_BUFFER_LENGTH - 1] = '\0';	event->EventDataUnion.OemEvent.OemEventData.DataLength = strlen(sel_entry->text);	return(SA_OK);}/** * snmp_bc_logsrc2rid: * @handle: Pointer to handler's data. * @src: Error Log's "Source" field string. * @resinfo: Location to store HPI resource mapping information. * @ovr_flags: Override flags * * Translates platform error log's "Source" field into an HPI resource ID * and stores HPI mapping info needed by other routines in * @resinfo. Assume "Source" field text is in the following format: * *   "BLADE_0x" - map to blade x RID *   "SWITCH_x" - map to switch x RID * * All other "Source" field text strings are mapped to the  * Chassis's resource ID. * * @ovr_flags is used to indicate exception cases. The only one * currently is to indicate if the resource is an expansion card. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. **/static SaErrorT snmp_bc_logsrc2rid(struct oh_handler_state *handle,				   gchar *src,				   LogSource2ResourceT *resinfo,				   unsigned short ovr_flags){	int rpt_index;	guint loc;	gchar **src_parts = NULL, *endptr = NULL, *root_tuple;	SaErrorT err;	SaHpiBoolT isblade, isexpansioncard, ischassis, isswitch;	SaHpiEntityPathT ep, ep_root;	SaHpiEntityTypeT entity_type;	struct snmp_bc_sensor *array_ptr;	if (!handle || !src || !resinfo) {		dbg("Invalid parameter.");		return(SA_ERR_HPI_INVALID_PARAMS);	}	/* Find top-level chassis entity path */        ep_init(&ep);	ep_init(&ep_root);	root_tuple = (gchar *)g_hash_table_lookup(handle->config, "entity_root");        string2entitypath(root_tuple, &ep_root);                /* Assume chassis location/type unless another resource type is discovered */	loc = ep_root.Entry[0].EntityLocation;	entity_type = ep_root.Entry[0].EntityType;	/* Break down "Source" text string to find source's RPT index and location */	src_parts = g_strsplit(src, "_", -1);	if (src_parts == NULL) {		dbg("Cannot split Source text string.");		g_strfreev(src_parts);		return(SA_ERR_HPI_INTERNAL_ERROR);	}	/* See if resource is something other than the chassis */	isblade = isexpansioncard = isswitch = ischassis = SAHPI_FALSE;	if (!strcmp(src_parts[0], "BLADE")) { 		/* All expansion card events are reported as blade events in the Error Log */		if (ovr_flags & OVR_EXP) { isexpansioncard = SAHPI_TRUE; }		else { isblade = SAHPI_TRUE; }	}	else {		if (!strcmp(src_parts[0], "SWITCH")) { isswitch = SAHPI_TRUE; }	}	/* If not the chassis, find the location value from last part of log's source string */	if (isexpansioncard == SAHPI_TRUE || isblade == SAHPI_TRUE || isswitch == SAHPI_TRUE) {		loc = strtoul(src_parts[1], &endptr, 10);		if (isexpansioncard == SAHPI_TRUE) {			rpt_index = BC_RPT_ENTRY_BLADE_ADDIN_CARD;			array_ptr = &snmp_bc_blade_addin_sensors[0];			}		else {			if (isblade == SAHPI_TRUE) { 				rpt_index = BC_RPT_ENTRY_BLADE; 				array_ptr = &snmp_bc_blade_sensors[0];			}			else { 				rpt_index = BC_RPT_ENTRY_SWITCH_MODULE;				array_ptr = &snmp_bc_switch_sensors[0];			}		}		entity_type = snmp_rpt_array[rpt_index].rpt.ResourceEntity.Entry[0].EntityType;	}	else {		ischassis = SAHPI_TRUE;		rpt_index = BC_RPT_ENTRY_CHASSIS;		array_ptr = &snmp_bc_chassis_sensors[0];	}	g_strfreev(src_parts);	/* Find rest of Entity Path and calculate the RID */	err = ep_concat(&ep, &snmp_rpt_array[rpt_index].rpt.ResourceEntity);	if (err) {		dbg("Cannot concat Entity Path. Error=%s.", oh_lookup_error(err));		return(SA_ERR_HPI_INTERNAL_ERROR);	}	err = ep_concat(&ep, &ep_root);	if (err) {		dbg("Cannot concat Entity Path. Error=%s.", oh_lookup_error(err));		return(SA_ERR_HPI_INTERNAL_ERROR);	}	err = set_ep_instance(&ep, entity_type, loc);	if (err) {		dbg("Cannot set location. Type=%s; Location=%d; Error=%s.",		    oh_lookup_entitytype(entity_type), loc, oh_lookup_error(err));		return(SA_ERR_HPI_INTERNAL_ERROR);	}		/* Special case - if Expansion Card set location of parent blade as well */	if (isexpansioncard == SAHPI_TRUE) {		err = set_ep_instance(&ep, SAHPI_ENT_SBC_BLADE, loc);		if (err) {			dbg("Cannot set location. Type=%s; Location=%d; Error=%s.",			    oh_lookup_entitytype(SAHPI_ENT_SBC_BLADE), loc, oh_lookup_error(err));  			return(SA_ERR_HPI_INTERNAL_ERROR);		}	}	/* Fill in RID and RPT table info about "Source" */	resinfo->rpt = rpt_index;	resinfo->sensor_array_ptr = array_ptr;	resinfo->ep = ep;	resinfo->rid = oh_uid_lookup(&ep);	/**********************************************************************************	 * Generate RID, if necessary.         * 	 * RID may be zero if resource hasn't ever been discovered since HPI initialization.	 * In this case, generate a valid RID. Infra-structure always assigns same RID          * number to an unique entity path. User app needs to worry about if resource          * is actually in the chassis - just as they do for hot-swapped resources.         **********************************************************************************/	if (resinfo->rid == 0) {		resinfo->rid = oh_uid_from_entity_path(&ep);		if (resinfo->rid == 0) {			dbg("No RID.");			return(SA_ERR_HPI_INTERNAL_ERROR);		}	}	return(SA_OK);} /** * snmp_bc_add_to_eventq * @handle: Pointer to handler's data. * @thisEvent: Location to store event. * * Add event to Infrastructure's event queue. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. **/SaErrorT snmp_bc_add_to_eventq(struct oh_handler_state *handle, SaHpiEventT *thisEvent){	SaHpiEntryIdT rdrid = 0;        struct oh_event working;        struct oh_event *e = NULL;	SaHpiRptEntryT *thisRpt;	        memset(&working, 0, sizeof(struct oh_event));	working.did = oh_get_default_domain_id();	working.type = OH_ET_HPI;		thisRpt = oh_get_resource_by_id(handle->rptcache, thisEvent->Source);        if (thisRpt) working.u.hpi_event.res = *thisRpt;	else dbg("NULL Rpt pointer for rid %d\n", thisEvent->Source);        memcpy(&working.u.hpi_event.event, thisEvent, sizeof(SaHpiEventT));	/* Setting RDR ID to event struct */		switch (thisEvent->EventType) {	case SAHPI_ET_OEM:	case SAHPI_ET_HOTSWAP:	case SAHPI_ET_USER:		/* There is no RDR associated to OEM event */		memset(&working.u.hpi_event.rdr, 0, sizeof(SaHpiRdrT));		working.u.hpi_event.rdr.RdrType = SAHPI_NO_RECORD;		/* Set RDR Type to SAHPI_NO_RECORD, spec B-01.01 */		/* It is redundant because SAHPI_NO_RECORD == 0, Put code here for clarity */		break;			           	case SAHPI_ET_SENSOR:		rdrid = get_rdr_uid(SAHPI_SENSOR_RDR,				    thisEvent->EventDataUnion.SensorEvent.SensorNum); 		working.u.hpi_event.rdr = *(oh_get_rdr_by_id(handle->rptcache, thisEvent->Source, rdrid));		break;	case SAHPI_ET_WATCHDOG:		rdrid = get_rdr_uid(SAHPI_WATCHDOG_RDR,				    thisEvent->EventDataUnion.WatchdogEvent.WatchdogNum);		working.u.hpi_event.rdr = *(oh_get_rdr_by_id(handle->rptcache, thisEvent->Source, rdrid));		break;	case SAHPI_ET_RESOURCE:	case SAHPI_ET_DOMAIN:	case SAHPI_ET_SENSOR_ENABLE_CHANGE:	case SAHPI_ET_HPI_SW:	default:		dbg("Unsupported Event Type=%s.", oh_lookup_eventtype(thisEvent->EventType));		return(SA_ERR_HPI_INTERNAL_ERROR);		break;	} 	        /* Insert entry to eventq for processing */        e = g_malloc0(sizeof(struct oh_event));        if (!e) {                dbg("Out of memory.");                return(SA_ERR_HPI_OUT_OF_SPACE);        }        memcpy(e, &working, sizeof(struct oh_event));        handle->eventq = g_slist_append(handle->eventq, e);        return(SA_OK);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -