/** * rpt_diff * @cur_rpt: IN. Pointer to RPTable that represents the current state of resources * and rdrs. * @new_rpt: IN. Pointer to RPTable that contains rpt entries and rdrs just recently * discovered. * @res_new: OUT. List of new or changed rpt entries * @rdr_new: OUT. List of new or changed rdrs * @res_gone: OUT. List of old and not present resources. * @rdr_gone: OUT. List of old and not present rdrs. * * Extracts from current the resources and rdrs that are not found * in new and puts them in res_gone and rdr_gone. Also, puts in res_new and rdr_new * the resources and rdrs that are not already in current Or that are not identical * to the ones in current. * * Returns: void. **/ void rpt_diff(RPTable *cur_rpt, RPTable *new_rpt, GSList **res_new, GSList **rdr_new, GSList **res_gone, GSList **rdr_gone) { SaHpiRptEntryT *res = NULL; if (!cur_rpt || !new_rpt || !res_new || !rdr_new || !res_gone || !rdr_gone) return; /* Look for absent resources and rdrs */ for (res = oh_get_resource_by_id(cur_rpt, SAHPI_FIRST_ENTRY); res != NULL; res = oh_get_resource_next(cur_rpt, res->ResourceId)) { SaHpiRptEntryT *tmp_res = oh_get_resource_by_id(new_rpt, res->ResourceId); if (tmp_res == NULL) *res_gone = g_slist_append(*res_gone, (gpointer)res); else { SaHpiRdrT *rdr = NULL; for (rdr = oh_get_rdr_by_id(cur_rpt, res->ResourceId, SAHPI_FIRST_ENTRY); rdr != NULL; rdr = oh_get_rdr_next(cur_rpt, res->ResourceId, rdr->RecordId)) { SaHpiRdrT *tmp_rdr = oh_get_rdr_by_id(new_rpt, res->ResourceId, rdr->RecordId); if (tmp_rdr == NULL) *rdr_gone = g_slist_append(*rdr_gone, (gpointer)rdr); } } } /* Look for new resources and rdrs*/ for (res = oh_get_resource_by_id(new_rpt, SAHPI_FIRST_ENTRY); res != NULL; res = oh_get_resource_next(new_rpt, res->ResourceId)) { SaHpiRptEntryT *tmp_res = oh_get_resource_by_id(cur_rpt, res->ResourceId); SaHpiRdrT *rdr = NULL; if (tmp_res == NULL || memcmp(res, tmp_res, sizeof(SaHpiRptEntryT))) { *res_new = g_slist_append(*res_new, (gpointer)res); } for (rdr = oh_get_rdr_by_id(new_rpt, res->ResourceId, SAHPI_FIRST_ENTRY); rdr != NULL; rdr = oh_get_rdr_next(new_rpt, res->ResourceId, rdr->RecordId)) { SaHpiRdrT *tmp_rdr = NULL; if (tmp_res != NULL) tmp_rdr = oh_get_rdr_by_id(cur_rpt, res->ResourceId, rdr->RecordId); if (tmp_rdr == NULL || memcmp(rdr, tmp_rdr, sizeof(SaHpiRdrT))) *rdr_new = g_slist_append(*rdr_new, (gpointer)rdr); } } }
SaErrorT sim_set_reset_state(void *hnd, SaHpiResourceIdT rid, SaHpiResetActionT act) { if (!hnd || NULL == oh_lookup_resetaction(act)){ err("Invalid parameter."); return SA_ERR_HPI_INVALID_PARAMS; } if (act == SAHPI_RESET_ASSERT || act == SAHPI_RESET_DEASSERT) return SA_ERR_HPI_INVALID_CMD; struct oh_handler_state *state = (struct oh_handler_state *)hnd; /* Check if resource exists and has reset capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(state->rptcache, rid); if (!rpt) { return SA_ERR_HPI_INVALID_RESOURCE; } if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_RESET)) { return SA_ERR_HPI_CAPABILITY; } return SA_OK; }
/** * snmp_bc_control_parm: * @hnd: Handler data pointer. * @rid: Resource ID. * @act: Configuration action. * * Save and restore saved configuration parameters. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_INVALID_PARAMS - @act is invalid. **/ SaErrorT snmp_bc_control_parm(void *hnd, SaHpiResourceIdT rid, SaHpiParmActionT act) { SaHpiRptEntryT *rpt; struct oh_handler_state *handle; struct snmp_bc_hnd *custom_handle; if (!hnd) return(SA_ERR_HPI_INVALID_PARAMS); if (oh_lookup_parmaction(act) == NULL) { dbg("Invalid parameter"); return(SA_ERR_HPI_INVALID_PARAMS); } handle = (struct oh_handler_state *)hnd; custom_handle = (struct snmp_bc_hnd *)handle->data; snmp_bc_lock_handler(custom_handle); rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) { dbg("No RID."); snmp_bc_unlock_handler(custom_handle); return(SA_ERR_HPI_INVALID_RESOURCE); } if (rpt->ResourceCapabilities & SAHPI_CAPABILITY_CONFIGURATION) { dbg("Resource configuration saving not supported."); snmp_bc_unlock_handler(custom_handle); return(SA_ERR_HPI_INTERNAL_ERROR); } else { snmp_bc_unlock_handler(custom_handle); return(SA_ERR_HPI_CAPABILITY); } }
/** * snmp_bc_set_resource_severity: * @hnd: Handler data pointer. * @rid: Resource ID. * @tag: Resource's severity. * * Sets severity of events when resource unexpectedly becomes unavailable. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_INVALID_PARAMS - @sev is invalid. * SA_ERR_HPI_OUT_OF_SPACE - No memory to allocate event. **/ SaErrorT snmp_bc_set_resource_severity(void *hnd, SaHpiResourceIdT rid, SaHpiSeverityT sev) { SaHpiRptEntryT *rpt; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct oh_event *e; if (oh_lookup_severity(sev) == NULL) { dbg("Invalid parameter"); return(SA_ERR_HPI_INVALID_PARAMS); } rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) { dbg("No RID."); return(SA_ERR_HPI_INVALID_RESOURCE); } rpt->ResourceSeverity = sev; /* Add changed resource to event queue */ e = g_malloc0(sizeof(struct oh_event)); if (e == NULL) { dbg("Out of memory."); return(SA_ERR_HPI_OUT_OF_SPACE); } e->type = OH_ET_RESOURCE; e->u.res_event.entry = *rpt; handle->eventq = g_slist_append(handle->eventq, e); return(SA_OK); }
/** * snmp_bc_get_announce: * @hnd: Handler data pointer. * @rid: Resource ID. * @aid: Annunciator ID. * @entry: Annunicator's announcement ID. * @announcment: Location to store annunicator's announcement. * * Gets the annunicator's announcement information. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_CAPABILITY - Resource doesn't have SAHPI_CAPABILITY_ANNUNICATOR. * SA_ERR_HPI_INVALID_RESOURCE - Resource doesn't exist. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. **/ SaErrorT snmp_bc_get_announce(void *hnd, SaHpiResourceIdT rid, SaHpiAnnunciatorNumT aid, SaHpiEntryIdT entry, SaHpiAnnouncementT *announcement) { if (!hnd || !announcement) { dbg("Invalid parameter."); return SA_ERR_HPI_INVALID_PARAMS; } struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; if (!custom_handle) { dbg("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } /* Check if resource exists and has managed hotswap capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_ANNUNCIATOR)) return(SA_ERR_HPI_CAPABILITY); dbg("Annunciators not supported by platform"); return(SA_ERR_HPI_INTERNAL_ERROR); }
SaErrorT snmp_bc_set_power_state(void *hnd, SaHpiResourceIdT id, SaHpiHsPowerStateT state) { gchar *oid; int rtn_code = SA_OK; struct snmp_value set_value; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; SaHpiRptEntryT *res = oh_get_resource_by_id(handle->rptcache, id); if(res == NULL) { return SA_ERR_HPI_NOT_PRESENT; } struct BC_ResourceInfo *s = (struct BC_ResourceInfo *)oh_get_resource_data(handle->rptcache, id); if(s == NULL) { return -1; } if(s->mib.OidPowerOnOff == NULL) { return SA_ERR_HPI_INVALID_CMD; } oid = snmp_derive_objid(res->ResourceEntity, s->mib.OidPowerOnOff); if(oid == NULL) { dbg("NULL SNMP OID returned for %s\n",s->mib.OidPowerOnOff); return -1; } set_value.type = ASN_INTEGER; switch (state) { case SAHPI_HS_POWER_OFF: set_value.integer = 0; if((snmp_set(custom_handle->ss, oid, set_value) != 0)) { dbg("SNMP could not set %s; Type=%d.\n",s->mib.OidPowerOnOff,set_value.type); rtn_code = SA_ERR_HPI_NO_RESPONSE; } break; case SAHPI_HS_POWER_ON: set_value.integer = 1; if((snmp_set(custom_handle->ss, oid, set_value) != 0)) { dbg("SNMP could not set %s; Type=%d.\n",s->mib.OidPowerOnOff,set_value.type); rtn_code = SA_ERR_HPI_NO_RESPONSE; } break; case SAHPI_HS_POWER_CYCLE: { SaHpiResetActionT act = SAHPI_COLD_RESET; rtn_code=snmp_bc_set_reset_state(hnd, id, act); } break; default: dbg("Invalid Power Action Type - %d\n", state); rtn_code = SA_ERR_HPI_INVALID_PARAMS; } g_free(oid); return rtn_code; }
SaErrorT rtas_set_resource_tag(void *hnd, SaHpiResourceIdT id, SaHpiTextBufferT *tag) { struct oh_handler_state *h = hnd; SaHpiRptEntryT *rptentry = NULL; SaErrorT error = SA_OK; struct oh_event *e = NULL; if (!hnd) return SA_ERR_HPI_INTERNAL_ERROR; rptentry = oh_get_resource_by_id(h->rptcache, id); if (!rptentry) return SA_ERR_HPI_NOT_PRESENT; error = oh_append_textbuffer(&rptentry->ResourceTag, tag->Data); if (error) return error; e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); e->did = oh_get_default_domain_id(); e->type = OH_ET_RESOURCE; e->u.res_event.entry = *rptentry; h->eventq = g_slist_append(h->eventq, e); return SA_OK; }
/** * main: Starts with an RPTable of 10 resources, multiple rdrs * on some resources. Remove resource. Check if resource was removed * searching for it in sequence. If not fail, else passed test. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); SaHpiRptEntryT *tmpentry = NULL; guint i = 0; for (i = 0; rptentries[i].ResourceId != 0; i++) { if (oh_add_resource(rptable, rptentries + i, NULL, 0)) return 1; } for (i = 0; i < 5; i++) { if (oh_add_rdr(rptable, SAHPI_FIRST_ENTRY, rdrs + i, NULL,0)) return 1; } for (; i < 7; i++) { if (oh_add_rdr(rptable, rptentries[9].ResourceId, rdrs + i, NULL,0)) return 1; } oh_remove_resource(rptable, rptentries[0].ResourceId); for (tmpentry = oh_get_resource_by_id(rptable, SAHPI_FIRST_ENTRY); tmpentry; tmpentry = oh_get_resource_next(rptable, tmpentry->ResourceId)) { if (tmpentry->ResourceId == rptentries[0].ResourceId) return 1; } return 0; }
SaErrorT rtas_set_resource_tag(void *hnd, SaHpiResourceIdT id, SaHpiTextBufferT *tag) { struct oh_handler_state *h = hnd; SaHpiRptEntryT *rptentry = NULL; SaErrorT error = SA_OK; struct oh_event *e = NULL; if (!hnd) return SA_ERR_HPI_INTERNAL_ERROR; rptentry = oh_get_resource_by_id(h->rptcache, id); if (!rptentry) return SA_ERR_HPI_NOT_PRESENT; error = oh_append_textbuffer(&rptentry->ResourceTag, (char *)tag->Data); if (error) return error; e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); e->hid = h->hid; e->event.EventType = SAHPI_ET_RESOURCE; e->event.Source = rptentry->ResourceId; e->event.Severity = rptentry->ResourceSeverity; e->event.Timestamp = SAHPI_TIME_UNSPECIFIED; e->event.EventDataUnion.ResourceEvent.ResourceEventType = SAHPI_RESE_RESOURCE_ADDED; e->resource = *rptentry; oh_evt_queue_push(h->eventq, e); return SA_OK; }
SaErrorT rtas_set_resource_severity(void *hnd, SaHpiResourceIdT id, SaHpiSeverityT sev) { struct oh_handler_state *h = hnd; SaHpiRptEntryT *rptentry = NULL; struct oh_event *e = NULL; if (!hnd) return SA_ERR_HPI_INTERNAL_ERROR; rptentry = oh_get_resource_by_id(h->rptcache, id); if (!rptentry) return SA_ERR_HPI_NOT_PRESENT; rptentry->ResourceSeverity = sev; e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); e->event.EventType = SAHPI_ET_RESOURCE; e->event.Source = rptentry->ResourceId; e->event.Severity = rptentry->ResourceSeverity; e->event.Timestamp = SAHPI_TIME_UNSPECIFIED; e->event.EventDataUnion.ResourceEvent.ResourceEventType = SAHPI_RESE_RESOURCE_ADDED; e->resource = *rptentry; oh_evt_queue_push(h->eventq, e); return SA_OK; }
/** * main: Starts with an RPTable of 10 resources (one with data), adds 5 rdr * to first resource and 2 to the last one. * Invokes oh_flush on the table. * Should return without crashing and there should be no resources left * in the table. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); guint i; gchar *data = "My data."; if (oh_add_resource(rptable, rptentries, data, 1)) return 1; for (i = 1; rptentries[i].ResourceId != 0; i++) { if (oh_add_resource(rptable, rptentries + i, NULL, 0)) return 1; } for (i = 0; i < 5; i++) { if (oh_add_rdr(rptable, SAHPI_FIRST_ENTRY, rdrs + i, NULL, 0)) return 1; } for (; i < 7; i++) { if (oh_add_rdr(rptable, rptentries[9].ResourceId, rdrs + i, NULL, 0)) return 1; } oh_flush_rpt(rptable); if (oh_get_resource_by_id(rptable, SAHPI_FIRST_ENTRY)) return 1; return 0; }
/** * oa_soap_build_control_rdr: * @oh_handler: Handler data pointer * @rdr: Pointer to the rdr structure * @resource_id: Resource ID * @control_num: Control rdr number * * Purpose: * Builds the control rdr. * * Detailed Description: * - Retrieves and populates the control rdr contents from global controls * array based in control num. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_INVALID_PARAMS - On wrong parameter * SA_ERR_HPI_INTERNAL_ERROR - Internal error encountered **/ SaErrorT oa_soap_build_control_rdr(struct oh_handler_state *oh_handler, SaHpiRdrT *rdr, SaHpiResourceIdT resource_id, SaHpiCtrlNumT control_num) { SaHpiRptEntryT *rpt = NULL; if (oh_handler == NULL || rdr == NULL) { err("Invalid parameters"); return SA_ERR_HPI_INVALID_PARAMS; } rpt = oh_get_resource_by_id(oh_handler->rptcache, resource_id); if (!rpt) { err("Could not find blade resource rpt"); return(SA_ERR_HPI_INTERNAL_ERROR); } /* Set the control rdr with default values */ rdr->Entity = rpt->ResourceEntity; rdr->RdrType = SAHPI_CTRL_RDR; rdr->RdrTypeUnion.CtrlRec = oa_soap_cntrl_arr[control_num].control; oh_init_textbuffer(&(rdr->IdString)); oh_append_textbuffer(&(rdr->IdString), oa_soap_cntrl_arr[control_num].comment); return SA_OK; }
/** * snmp_bc_get_reset_state: * @hnd: Handler data pointer. * @rid: Resource ID. * @act: Location to store resource's reset action state. * * Retrieves a resource's reset action state. * Always return SAHPI_RESET_DEASSERT. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_CAPABILITY - Resource doesn't have SAHPI_CAPABILITY_RESET. * SA_ERR_HPI_INVALID_RESOURCE - Resource doesn't exist. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. **/ SaErrorT snmp_bc_get_reset_state(void *hnd, SaHpiResourceIdT rid, SaHpiResetActionT *act) { if (!hnd || !act) { dbg("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; if (!custom_handle) { dbg("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } snmp_bc_lock_handler(custom_handle); /* Check if resource exists and has reset capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) { snmp_bc_unlock_handler(custom_handle); return(SA_ERR_HPI_INVALID_RESOURCE); } if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_RESET)) { snmp_bc_unlock_handler(custom_handle); return(SA_ERR_HPI_CAPABILITY); } *act = SAHPI_RESET_DEASSERT; snmp_bc_unlock_handler(custom_handle); return(SA_OK); }
SaErrorT sim_reset_watchdog(void *hnd, SaHpiResourceIdT rid, SaHpiWatchdogNumT num) { SaHpiRdrT *rdr; if (!hnd) { dbg("Invalid parameter."); return SA_ERR_HPI_INVALID_PARAMS; } struct oh_handler_state *state = (struct oh_handler_state *)hnd; /* Check if resource exists and has managed hotswap capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(state->rptcache, rid); if (!rpt) { return SA_ERR_HPI_INVALID_RESOURCE; } if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_WATCHDOG)) { return SA_ERR_HPI_CAPABILITY; } rdr = oh_get_rdr_by_type(state->rptcache, rid, SAHPI_WATCHDOG_RDR, num); if (rdr == NULL) return SA_ERR_HPI_NOT_PRESENT; // since no timer is actually running we can just do nothing here return SA_OK; }
SaErrorT oa_soap_set_resource_severity(void *oh_handler, SaHpiResourceIdT resource_id, SaHpiSeverityT severity) { struct oh_handler_state *handler; SaHpiRptEntryT *rpt = NULL; if (oh_handler == NULL) { err("Invalid parameters"); return SA_ERR_HPI_INVALID_PARAMS; } /* Validate the severity */ if (oh_lookup_severity(severity) == NULL) { err("Invalid parameter"); return SA_ERR_HPI_INVALID_PARAMS; } handler = (struct oh_handler_state *) oh_handler; rpt = oh_get_resource_by_id(handler->rptcache, resource_id); if (rpt == NULL) { err("Not able to find the resource. Invalid resource id"); return SA_ERR_HPI_NOT_PRESENT; } rpt->ResourceSeverity = severity; return SA_OK; }
/** * snmp_bc_set_hotswap_state: * @hnd: Handler data pointer. * @rid: Resource ID. * @state: Hotswap state to set. * * Sets a resource's hotswap state. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_CAPABILITY - Resource doesn't have SAHPI_CAPABILITY_MANAGED_HOTSWAP. * SA_ERR_HPI_INVALID_REQUEST - @state invalid. * SA_ERR_HPI_INVALID_RESOURCE - Resource doesn't exist. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. **/ SaErrorT snmp_bc_set_hotswap_state(void *hnd, SaHpiResourceIdT rid, SaHpiHsStateT state) { if (!hnd) { dbg("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } if (NULL == oh_lookup_hsstate(state)) { dbg("Invalid hotswap state."); return(SA_ERR_HPI_INVALID_REQUEST); } struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; if (!custom_handle) { dbg("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } /* Check if resource exists and has managed hotswap capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_MANAGED_HOTSWAP)) return(SA_ERR_HPI_CAPABILITY); dbg("Managed Hotswap is not supported by platform"); return(SA_ERR_HPI_INTERNAL_ERROR); }
static int snmp_rsa_set_resource_tag(void *hnd, SaHpiResourceIdT id, SaHpiTextBufferT *tag) { struct oh_handler_state *handle = (struct oh_handler_state *)hnd; SaHpiRptEntryT *resource = oh_get_resource_by_id(handle->rptcache, id); struct oh_event *e = NULL; guint datalength = tag->DataLength; if (!resource) { dbg("Error. Cannot set resource tag in plugin. No resource found by that id."); return SA_ERR_HPI_NOT_PRESENT; } if (datalength > SAHPI_MAX_TEXT_BUFFER_LENGTH) datalength = SAHPI_MAX_TEXT_BUFFER_LENGTH; strncpy(resource->ResourceTag.Data, tag->Data, datalength); resource->ResourceTag.DataLength = tag->DataLength; resource->ResourceTag.DataType = tag->DataType; resource->ResourceTag.Language = tag->Language; /** Can we persist this to hardware or disk? */ /* Add changed resource to event queue */ e = g_malloc0(sizeof(struct oh_event)); e->type = OH_ET_RESOURCE; e->u.res_event.entry = *resource; handle->eventq = g_slist_append(handle->eventq, e); return SA_OK; }
/** * oh_get_resource_by_ep * @table: Pointer to the RPT for looking up the RPT entry. * @ep: Entity path of the RPT entry to be looked up. * * Get a RPT entry from the RPT by using the entity path. * * Returns: * Pointer to the RPT entry found or NULL if an RPT entry by that * entity path was not found or the table was a NULL pointer. **/ SaHpiRptEntryT *oh_get_resource_by_ep(RPTable *table, SaHpiEntityPathT *ep) { RPTEntry *rptentry = NULL; GSList *node = NULL; SaHpiResourceIdT rid = 0; if (!table) { dbg("ERROR: Cannot work on a null table pointer."); return NULL; } /* Check the uid database first */ rid = oh_uid_is_initialized() ? oh_uid_lookup(ep) : 0; if (rid > 0) { /* Found it in uid database */ return oh_get_resource_by_id(table, rid); } else { trace("Didn't find the EP in the Uid table so " "looking manually in the RPTable"); } for (node = table->rptlist; node != NULL; node = node->next) { rptentry = (RPTEntry *) node->data; if (oh_cmp_ep(&(rptentry->rpt_entry.ResourceEntity), ep)) break; else rptentry = NULL; } if (!rptentry) { /*dbg("Warning: RPT entry not found. Returning NULL.");*/ return NULL; } return &(rptentry->rpt_entry); }
/** * snmp_bc_get_sensor_event_enable: * @hnd: Handler data pointer. * @rid: Resource ID. * @sid: Sensor ID. * @enable: Location to store sensor event enablement boolean. * * Retrieves a sensor's boolean event enablement status. * * Return values: * SA_OK - normal case. * SA_ERR_HPI_CAPABILITY - if resource doesn't have SAHPI_CAPABILITY_SENSOR. * SA_ERR_HPI_NOT_PRESENT - if sensor doesn't exist. **/ SaErrorT snmp_bc_get_sensor_event_enable(void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT sid, SaHpiBoolT *enable) { SaHpiRdrT *rdr; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct SensorInfo *sinfo; if (!enable) { dbg("Invalid parameter"); return(SA_ERR_HPI_INVALID_PARAMS); } /* Check if resource exists and has sensor capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_SENSOR)) return(SA_ERR_HPI_CAPABILITY); /* Check if sensor exists and return enablement status */ rdr = oh_get_rdr_by_type(handle->rptcache, rid, SAHPI_SENSOR_RDR, sid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, rid, rdr->RecordId); if (sinfo == NULL) { dbg("Cannot retrieve sensor data."); return(SA_ERR_HPI_INTERNAL_ERROR); } *enable = sinfo->events_enabled; return(SA_OK); }
/** * main: Starts with an RPTable of 10 resources and fetches * them randomly by the ResourceId and compares them against the original * resource. A failed comparison means the test failed, * otherwise the test passed. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); guint i = 0, k = 0; GSList *resources = NULL; for (i = 0; rptentries[i].ResourceId != 0; i++) { if (oh_add_resource(rptable, rptentries + i, NULL, 0)) return 1; else resources = g_slist_append(resources, rptentries + i); } for (; resources; i--) { SaHpiRptEntryT *randentry = NULL, *tmpentry = NULL; GSList *tmpnode = NULL; k = (guint) (((gfloat)i)*rand()/(RAND_MAX+1.0)); tmpnode = g_slist_nth(resources, k); randentry = (SaHpiRptEntryT *)tmpnode->data; tmpentry = oh_get_resource_by_id(rptable, randentry->ResourceId); if (!tmpentry || memcmp(randentry, tmpentry, sizeof(SaHpiRptEntryT))) return 1; else { resources = g_slist_remove_link(resources, tmpnode); g_slist_free_1(tmpnode); } } return 0; }
/** * oa_soap_get_power_state * @oh_handler: Pointer to openhpi handler * @resource_id: Resource id * @state: Pointer to power state * * Purpose: * Gets the power state of the resource. * * Detailed Description: NA * * Return values: * SA_OK - on success. * SA_ERR_HPI_INVALID_PARAMS - on wrong parameters * SA_ERR_HPI_CAPABILITY - on power capability is not set for * the given resource * SA_ERR_HPI_INVALID_RESOURCE - on not able to find the resource * SA_ERR_HPI_INTERNAL_ERROR - on failure. **/ SaErrorT oa_soap_get_power_state(void *oh_handler, SaHpiResourceIdT resource_id, SaHpiPowerStateT *state) { SaErrorT rv = SA_OK; SaHpiRptEntryT *rpt; struct oa_soap_handler *oa_handler = NULL; SaHpiInt32T bay_number; struct oh_handler_state *handler; if (oh_handler == NULL || state == NULL) { err("Invalid parameters"); return SA_ERR_HPI_INVALID_PARAMS; } handler = (struct oh_handler_state *) oh_handler; oa_handler = (struct oa_soap_handler *) handler->data; /* Check whether the oa_handler mutex has been locked or not */ rv = lock_oa_soap_handler(oa_handler); if (rv != SA_OK) { err("OA SOAP handler is locked"); return rv; } rpt = oh_get_resource_by_id(handler->rptcache, resource_id); if (rpt == NULL) { err("INVALID RESOURCE"); return SA_ERR_HPI_INVALID_RESOURCE; } /* Check the resource has power capability */ if (! (rpt->ResourceCapabilities & SAHPI_CAPABILITY_POWER)) { err("INVALID RESOURCE CAPABILITY"); return SA_ERR_HPI_CAPABILITY; } bay_number = rpt->ResourceEntity.Entry[0].EntityLocation; /* Check resource type and query server or interconnect power state*/ switch (rpt->ResourceEntity.Entry[0].EntityType) { case (SAHPI_ENT_SYSTEM_BLADE): case (SAHPI_ENT_IO_BLADE): case (SAHPI_ENT_DISK_BLADE): rv = get_server_power_state(oa_handler->active_con, bay_number, state); break; case (SAHPI_ENT_SWITCH_BLADE): rv = get_interconnect_power_state( oa_handler->active_con, bay_number, state); break; default: err("Invalid Resource Type"); rv = SA_ERR_HPI_INTERNAL_ERROR; } return rv; }
/** * snmp_bc_set_resource_severity: * @hnd: Handler data pointer. * @rid: Resource ID. * @tag: Resource's severity. * * Sets severity of events when resource unexpectedly becomes unavailable. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_INVALID_PARAMS - @sev is invalid. * SA_ERR_HPI_OUT_OF_SPACE - No memory to allocate event. **/ SaErrorT snmp_bc_set_resource_severity(void *hnd, SaHpiResourceIdT rid, SaHpiSeverityT sev) { SaHpiRptEntryT *rpt; struct oh_handler_state *handle; struct snmp_bc_hnd *custom_handle; struct oh_event *e; struct ResourceInfo *res_info_ptr; if (oh_lookup_severity(sev) == NULL) { dbg("Invalid parameter"); return(SA_ERR_HPI_INVALID_PARAMS); } handle = (struct oh_handler_state *)hnd; custom_handle = (struct snmp_bc_hnd *)handle->data; snmp_bc_lock_handler(custom_handle); rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) { snmp_bc_unlock_handler(custom_handle); dbg("No RID."); return(SA_ERR_HPI_INVALID_RESOURCE); } res_info_ptr = (struct ResourceInfo *)oh_get_resource_data( handle->rptcache, rpt->ResourceId); if (!res_info_ptr) { snmp_bc_unlock_handler(custom_handle); dbg("No resource information."); return(SA_ERR_HPI_INVALID_RESOURCE); } rpt->ResourceSeverity = sev; /* Add changed resource to event queue */ /* Add changed resource to event queue */ e = snmp_bc_alloc_oh_event(); if (e == NULL) { snmp_bc_unlock_handler(custom_handle); dbg("Out of memory."); return(SA_ERR_HPI_OUT_OF_SPACE); } e->resource = *rpt; /* ---------------------------------------- */ /* Construct .event of struct oh_event */ /* ---------------------------------------- */ snmp_bc_set_resource_add_oh_event(custom_handle, e, res_info_ptr); /* ---------------------------------------- */ /* Prime event to evenq */ /* ---------------------------------------- */ handle->eventq = g_slist_append(handle->eventq, e); snmp_bc_unlock_handler(custom_handle); return(SA_OK); }
SaErrorT sim_add_idr_area(void *hnd, SaHpiResourceIdT rid, SaHpiIdrIdT IdrId, SaHpiIdrAreaTypeT AreaType, SaHpiEntryIdT *AreaId) { struct sim_inventory_info *info; if (!hnd || !AreaId) { dbg("Invalid parameter."); return SA_ERR_HPI_INVALID_PARAMS; } struct oh_handler_state *state = (struct oh_handler_state *)hnd; /* Check if resource exists and has inventory capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(state->rptcache, rid); if (!rpt) { return SA_ERR_HPI_INVALID_RESOURCE; } if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA)) { return SA_ERR_HPI_CAPABILITY; } /* Find inventory and its data - see if it accessable */ SaHpiRdrT *rdr = oh_get_rdr_by_type(state->rptcache, rid, SAHPI_INVENTORY_RDR, IdrId); if (rdr == NULL) { return SA_ERR_HPI_NOT_PRESENT; } info = (struct sim_inventory_info *)oh_get_rdr_data(state->rptcache, rid, rdr->RecordId); if (info == NULL) { dbg("No inventory data. IdrId=%s", rdr->IdString.Data); return SA_ERR_HPI_NOT_PRESENT; } /* check to see if space is available for the new area */ if (info->idrinfo.NumAreas == SIM_INVENTORY_AREAS) { return SA_ERR_HPI_OUT_OF_SPACE; } else if (info->idrinfo.ReadOnly) { return SA_ERR_HPI_READ_ONLY; } /* add the area */ info->area[info->idrinfo.NumAreas].idrareahead.AreaId = info->nextareaid; info->area[info->idrinfo.NumAreas].idrareahead.Type = AreaType; info->area[info->idrinfo.NumAreas].idrareahead.ReadOnly = SAHPI_FALSE; info->area[info->idrinfo.NumAreas].idrareahead.NumFields = 0; /* increment our counters and set return info */ info->idrinfo.NumAreas++; *AreaId = info->nextareaid; info->nextareaid++; return SA_OK; }
/** * snmp_bc_get_power_state: * @hnd: Handler data pointer. * @rid: Resource ID. * @state: Location to store resource's power state. * * Retrieves a resource's power state. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_CAPABILITY - Resource doesn't have SAHPI_CAPABILITY_POWER. * SA_ERR_HPI_INVALID_RESOURCE - Resource doesn't exist. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. **/ SaErrorT snmp_bc_get_power_state(void *hnd, SaHpiResourceIdT rid, SaHpiPowerStateT *state) { SaErrorT err = SA_OK; struct ResourceInfo *resinfo; struct snmp_value get_value; if (!hnd || !state) { dbg("Invalid parameter"); return SA_ERR_HPI_INVALID_PARAMS; } struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; if (!custom_handle) { dbg("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } /* Check if resource exists and has power capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_POWER)) return(SA_ERR_HPI_CAPABILITY); resinfo = (struct ResourceInfo *)oh_get_resource_data(handle->rptcache, rid); if (resinfo == NULL) { dbg("No resource data. Resource=%s", rpt->ResourceTag.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } if (resinfo->mib.OidPowerState == NULL) { dbg("No Power OID."); return(SA_ERR_HPI_INTERNAL_ERROR); } /* Read power state of resource */ err = snmp_bc_oid_snmp_get(custom_handle, &(rpt->ResourceEntity), resinfo->mib.OidPowerState, &get_value, SAHPI_TRUE); if (!err && (get_value.type == ASN_INTEGER)) { switch (get_value.integer) { case 0: *state = SAHPI_POWER_OFF; break; case 1: *state = SAHPI_POWER_ON; break; default: dbg("Invalid power state for OID=%s.", resinfo->mib.OidPowerState); err = SA_ERR_HPI_INTERNAL_ERROR; } } else { dbg("Cannot read SNMP OID=%s; Type=%d.", resinfo->mib.OidPowerState, get_value.type); } return(err); }
static int process_session_event(struct oh_handler *h, RPTable *rpt, struct oh_hpi_event *e) { SaHpiRptEntryT *res; GSList *i; unsigned int log_severity; data_access_lock(); res = oh_get_resource_by_id(rpt, e->parent); if (res == NULL) { dbg("No resource"); data_access_unlock(); return -1; } if (res->ResourceCapabilities & SAHPI_CAPABILITY_MANAGED_HOTSWAP && e->event.EventType == SAHPI_ET_HOTSWAP) { hotswap_push_event(e); } /* Domain System Event Logging Mechanism. Check the handler configuration for the "log_severity" value and log everything equal or above that severity value. If there is no "log_severity" configured for the handler, then the default bar will be SAHPI_INFORMATIONAL. */ log_severity = get_log_severity(getenv("OPENHPI_LOG_SEV")); if (e->event.Severity <= log_severity) { struct oh_domain *d; SaHpiSelEntryT selentry; /* yes, we need to add real domain support later here */ d = get_domain_by_id(OH_DEFAULT_DOMAIN_ID); selentry.Event = e->event; oh_sel_add(d->sel, &selentry); } g_slist_for_each(i, global_session_list) { struct oh_session *s = i->data; /* yes, we need to add real domain support later here */ if (s->domain_id == SAHPI_DEFAULT_DOMAIN_ID && (s->event_state == OH_EVENT_SUBSCRIBE || (s->event_state == OH_EVENT_UNSUBSCRIBE && (e->event.Severity == SAHPI_MINOR || e->event.Severity == SAHPI_MAJOR || e->event.Severity == SAHPI_CRITICAL)))) { /* Push event if session is subscribed, or, if session is unsubscribed, the event is an active alarm. */ session_push_event(s, e); } } data_access_unlock(); return 0; }
/** * oh_flush_rpt * @table: Pointer to the RPT to flush. * * Cleans RPT from all entries and RDRs and frees the memory * associated with them. * * Returns: SA_OK on success Or minus SA_OK on error. **/ SaErrorT oh_flush_rpt(RPTable *table) { SaHpiRptEntryT *tmp_entry; while ((tmp_entry = oh_get_resource_by_id(table, SAHPI_FIRST_ENTRY)) != NULL) { oh_remove_resource(table, SAHPI_FIRST_ENTRY); } return SA_OK; }
SaErrorT sim_resource_failed_remove(void *hnd, SaHpiResourceIdT rid) { struct oh_handler_state *h; SaHpiRptEntryT *resource = NULL; struct oh_event e; SaHpiHsStateT hsstate = SAHPI_HS_STATE_ACTIVE; SaErrorT rv; if (hnd == NULL) { err("Invalid parameter"); return SA_ERR_HPI_INVALID_PARAMS; } h = (struct oh_handler_state *) hnd; resource = oh_get_resource_by_id(h->rptcache, rid); if (resource == NULL) { err("Failed to get the RPT entry"); return SA_ERR_HPI_NOT_PRESENT; } if (resource->ResourceCapabilities & SAHPI_CAPABILITY_MANAGED_HOTSWAP) { rv = sim_get_hotswap_state(hnd, rid, &hsstate); if (rv != SA_OK) { err("Failed to get the hotswap state"); return rv; } } /* Raise the resource removal hotswap event */ memset(&e, 0, sizeof(struct oh_event)); e.hid = h->hid; e.resource = *resource; e.rdrs = NULL; e.event.Source = rid; e.event.Severity = resource->ResourceSeverity; oh_gettimeofday(&e.event.Timestamp); e.event.EventType = SAHPI_ET_HOTSWAP; e.event.EventDataUnion.HotSwapEvent.PreviousHotSwapState = hsstate; e.event.EventDataUnion.HotSwapEvent.HotSwapState = SAHPI_HS_STATE_NOT_PRESENT; e.event.EventDataUnion.HotSwapEvent.CauseOfStateChange = SAHPI_HS_CAUSE_USER_UPDATE; oh_evt_queue_push(h->eventq, oh_dup_event(&e)); /* Remove the failed resource from plugin rptcache */ rv = oh_remove_resource(h->rptcache, rid); if (rv != SA_OK) { err("Resource removal from RPTable failed"); return rv; } return SA_OK; }
bool cIpmiResource::Destroy() { SaHpiRptEntryT *rptentry; stdlog << "removing resource: " << m_entity_path << ").\n"; // remove sensors while( Num() ) { cIpmiRdr *rdr = GetRdr( 0 ); RemRdr( rdr ); delete rdr; } // create remove event oh_event *e = (oh_event *)g_malloc0( sizeof( oh_event ) ); if ( !e ) { stdlog << "out of space !\n"; return false; } memset( e, 0, sizeof( struct oh_event ) ); e->type = OH_ET_RESOURCE_DEL; rptentry = oh_get_resource_by_id( Domain()->GetHandler()->rptcache, m_resource_id ); if ( !rptentry ) { stdlog << "Can't find resource in plugin cache !\n"; g_free( e ); return false; } e->u.res_event.entry = *rptentry; stdlog << "cIpmiResource::Destroy OH_ET_RESOURCE_DEL Event resource " << m_resource_id << "\n"; Domain()->AddHpiEvent( e ); // remove resource from local cache int rv = oh_remove_resource( Domain()->GetHandler()->rptcache, m_resource_id ); if ( rv != 0 ) { stdlog << "Can't remove resource from plugin cache !\n"; return false; } m_mc->RemResource( this ); delete this; return true; }
/** * main: Starting with an empty RPTable, adds 1 resource to it. * Fetches the resource back by id using a NULL table. * Passes the test if the interface returns NULL, else it fails. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { RPTable *rptable = (RPTable *)g_malloc0(sizeof(RPTable)); oh_init_rpt(rptable); if (oh_add_resource(rptable, rptentries, NULL, 1)) return 1; if (oh_get_resource_by_id(NULL, rptentries[0].ResourceId)) return 1; return 0; }
static int snmp_rsa_control_parm(void *hnd, SaHpiResourceIdT id, SaHpiParmActionT act) { struct oh_handler_state *handle = (struct oh_handler_state *)hnd; SaHpiRptEntryT *res = oh_get_resource_by_id(handle->rptcache, id); if (res->ResourceCapabilities & SAHPI_CAPABILITY_CONFIGURATION) { dbg("ERROR: RSA does not yet support Resource Configuration saving"); return -1; } else { return SA_ERR_HPI_INVALID_CMD; } }