/** * 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; }
/** * ilo2_ribcl_close: * @oh_handler: Handler data pointer. * * This function closes the instance of the iLO2 RIBCL plugin specified * by the oh_handler input parameter. * Detailed description: * - Free allocated memory * - Assumption: RIBCL connection is closed after each transaction. * If this assumption is incorrect, close open SSL connections to * iLO2. * Return values: * Void **/ void ilo2_ribcl_close(void *handler) { struct oh_handler_state *oh_handler = (struct oh_handler_state *) handler; ilo2_ribcl_handler_t *ilo2_ribcl_handler; if(oh_handler == NULL) { return; } close_handler = SAHPI_TRUE; dbg("ilo2 ribcl close_handler is set"); /* Sleep so that discovery thread get this variable */ sleep(1); ilo2_ribcl_handler = (ilo2_ribcl_handler_t *) oh_handler->data; if(ilo2_ribcl_handler == NULL) { free(oh_handler); return; } g_mutex_lock(ilo2_ribcl_handler->ilo_thread_data->iLO_mutex); g_cond_broadcast(ilo2_ribcl_handler->ilo_thread_data->iLO_cond); g_mutex_unlock(ilo2_ribcl_handler->ilo_thread_data->iLO_mutex); if (ilo2_ribcl_handler->ilo_thread_data->hthread) g_thread_join(ilo2_ribcl_handler->ilo_thread_data->hthread); wrap_g_cond_free(ilo2_ribcl_handler->ilo_thread_data->iLO_cond); wrap_g_mutex_free_clear(ilo2_ribcl_handler->ilo_thread_data->iLO_mutex); g_free(ilo2_ribcl_handler->ilo_thread_data); /* Free SSL infrastructure */ oh_ssl_ctx_free(ilo2_ribcl_handler->ssl_ctx); /* Free the RIBCL command strings in the ilo2_ribcl_handler */ ir_xml_free_cmdbufs( ilo2_ribcl_handler); /* Free any allocated discovery data in the ilo2_ribcl_handler */ ilo2_ribcl_free_discoverydata( ilo2_ribcl_handler); #ifdef ILO2_RIBCL_SIMULATE_iLO2_RESPONSE /* If we specified a response file for discovery testing, * free the space we used for its namestring. */ if( ilo2_ribcl_handler->discovery_responsefile){ free( ilo2_ribcl_handler->discovery_responsefile); } #endif /* ILO2_RIBCL_SIMULATE_iLO2_RESPONSE */ oh_flush_rpt(oh_handler->rptcache); free(ilo2_ribcl_handler->ilo2_hostport); free(ilo2_ribcl_handler); free(oh_handler->rptcache); free(oh_handler); return; }
static void __delete_domain(struct oh_domain *d) { oh_flush_rpt(&d->rpt); oh_el_close(d->del); oh_close_alarmtable(d); __free_drt_list(d->drt.list); g_static_rec_mutex_free(&d->lock); g_static_rec_mutex_free(&d->refcount_lock); g_free(d); }
static void __delete_domain(struct oh_domain *d) { disconnect_parent(d); /* Remove drt entry from parent */ disconnect_peers(d); /* Remove drt entry from brothers */ oh_flush_rpt(&d->rpt); oh_el_close(d->del); oh_close_alarmtable(d); __free_drt_list(d->drt.list); g_array_free(d->sessions, TRUE); g_static_rec_mutex_free(&d->lock); g_static_rec_mutex_free(&d->refcount_lock); /*oh_destroy_domain_sessions(d->id);*/ /* Not needed after all */ g_free(d); }
/** * ilo2_ribcl_close: * @oh_handler: Handler data pointer. * * This function closes the instance of the iLO2 RIBCL plugin specified * by the oh_handler input parameter. * Detailed description: * - Free allocated memory * - Assumption: RIBCL connection is closed after each transaction. * If this assumption is incorrect, close open SSL connections to * iLO2. * Return values: * Void **/ void ilo2_ribcl_close(void *handler) { struct oh_handler_state *oh_handler = (struct oh_handler_state *) handler; ilo2_ribcl_handler_t *ilo2_ribcl_handler; if(oh_handler == NULL) { return; } ilo2_ribcl_handler = (ilo2_ribcl_handler_t *) oh_handler->data; if(ilo2_ribcl_handler == NULL) { free(oh_handler); return; } /* Free SSL infrastructure */ oh_ssl_ctx_free(ilo2_ribcl_handler->ssl_ctx); /* Free the RIBCL command strings in the ilo2_ribcl_handler */ ir_xml_free_cmdbufs( ilo2_ribcl_handler); /* Free any allocated discovery data in the ilo2_ribcl_handler */ ilo2_ribcl_free_discoverydata( ilo2_ribcl_handler); #ifdef ILO2_RIBCL_SIMULATE_iLO2_RESPONSE /* If we specified a response file for discovery testing, * free the space we used for its namestring. */ if( ilo2_ribcl_handler->discovery_responsefile){ free( ilo2_ribcl_handler->discovery_responsefile); } #endif /* ILO2_RIBCL_SIMULATE_iLO2_RESPONSE */ oh_flush_rpt(oh_handler->rptcache); free(ilo2_ribcl_handler->ilo2_hostport); free(ilo2_ribcl_handler); free(oh_handler->rptcache); free(oh_handler); return; }
/** * snmp_bc_close: * @hnd: Pointer to handler structure. * * Close an SNMP BladeCenter/RSA plugin handler instance. * * Returns: * Void **/ void snmp_bc_close(void *hnd) { struct oh_handler_state *handle; if (!hnd) { dbg("INVALID PARM - NULL handle pointer."); return; } handle = (struct oh_handler_state *)hnd; oh_el_close(handle->elcache); if (is_simulator()) { sim_close(); } else { struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; snmp_sess_close(custom_handle->sessp); /* Windows32 specific net-snmp cleanup (noop on unix) */ SOCK_CLEANUP; } /* Cleanup event2hpi hash table */ event2hpi_hash_free(handle); /* Cleanup errlog2event_hash table */ errlog2event_hash_use_count--; if (errlog2event_hash_use_count == 0) { errlog2event_hash_free(); } oh_flush_rpt(handle->rptcache); g_free(handle->rptcache); }
static void IpmiClose( void *hnd ) { dbg( "IpmiClose" ); cIpmi *ipmi = VerifyIpmi( hnd ); ipmi->IfEnter(); ipmi->IfClose(); ipmi->IfLeave(); delete ipmi; oh_handler_state *handler = (oh_handler_state *)hnd; assert( handler ); assert( handler->rptcache ); oh_flush_rpt( handler->rptcache ); g_free( handler->rptcache ); g_free( handler ); // close logfile IpmiLogClose(); }
static int snmp_rsa_discover_resources(void *hnd) { SaHpiEntityPathT entity_root; guint i; struct oh_event *e; struct snmp_value get_value; // struct snmp_value get_active; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_rsa_hnd *custom_handle = (struct snmp_rsa_hnd *)handle->data; RPTable *tmpcache = (RPTable *)g_malloc0(sizeof(RPTable)); GSList *tmpqueue = NULL; char *root_tuple = (char *)g_hash_table_lookup(handle->config,"entity_root"); string2entitypath(root_tuple, &entity_root); /* see if the chassis exists by querying system health */ if(snmp_get(custom_handle->ss,".1.3.6.1.4.1.2.3.51.1.2.7.1.0",&get_value) != 0) { /* If we get here, something is hosed. No need to do more discovery */ dbg("Couldn't fetch SNMP RSA system health.\n"); dbg("There is no chassis."); g_free(tmpcache); return -1; } /* discover the chassis */ e = snmp_rsa_discover_chassis(handle, &entity_root); if(e != NULL) { struct ResourceMibInfo *res_mib = g_memdup(&(snmp_rsa_rpt_array[RSA_RPT_ENTRY_CHASSIS].rsa_res_info.mib), sizeof(struct snmp_rpt)); oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0); tmpqueue = g_slist_append(tmpqueue, e); SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId; SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity; find_sensors(snmp_rsa_chassis_sensors); find_controls(snmp_rsa_chassis_controls); find_inventories(snmp_rsa_chassis_inventories); } /* discover all cpus */ for (i = 0; i < RSA_MAX_CPU; i++) { /* see if the cpu exists by querying the thermal sensor */ if((snmp_get(custom_handle->ss, snmp_rsa_cpu_thermal_sensors[i].rsa_sensor_info.mib.oid, &get_value) != 0) || (get_value.type != ASN_OCTET_STR) || (strcmp(get_value.string, "Not Readable!") == 0)) { /* If we get here the CPU is not installed */ dbg("CPU %d not found.\n", i+RSA_HPI_INSTANCE_BASE); continue; } e = snmp_rsa_discover_cpu(handle, &entity_root, i); if(e != NULL) { struct ResourceMibInfo *res_mib = g_memdup(&(snmp_rsa_rpt_array[RSA_RPT_ENTRY_CPU].rsa_res_info.mib), sizeof(struct snmp_rpt)); oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0); tmpqueue = g_slist_append(tmpqueue, e); SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId; SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity; /* add the CPU thermal sensor */ e = snmp_rsa_discover_sensors(handle, parent_ep, &snmp_rsa_cpu_thermal_sensors[i]); if(e != NULL) { struct RSA_SensorInfo *rsa_data = g_memdup(&(snmp_rsa_cpu_thermal_sensors[i].rsa_sensor_info), sizeof(struct RSA_SensorInfo)); oh_add_rdr(tmpcache,rid,&(e->u.rdr_event.rdr), rsa_data, 0); tmpqueue = g_slist_append(tmpqueue, e); } } } /* discover all dasd */ for (i = 0; i < RSA_MAX_DASD; i++) { /* see if the dasd exists by querying the thermal sensor */ if((snmp_get(custom_handle->ss, snmp_rsa_dasd_thermal_sensors[i].rsa_sensor_info.mib.oid, &get_value) != 0) || (get_value.type != ASN_OCTET_STR) || (strcmp(get_value.string, "Not Readable!") == 0)) { /* If we get here the DASD is not installed */ dbg("DASD %d not found.\n", i+RSA_HPI_INSTANCE_BASE); continue; } e = snmp_rsa_discover_dasd(handle, &entity_root, i); if(e != NULL) { struct ResourceMibInfo *res_mib = g_memdup(&(snmp_rsa_rpt_array[RSA_RPT_ENTRY_DASD].rsa_res_info.mib), sizeof(struct snmp_rpt)); oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0); tmpqueue = g_slist_append(tmpqueue, e); SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId; SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity; /* add the DASD thermal sensor */ e = snmp_rsa_discover_sensors(handle, parent_ep, &snmp_rsa_dasd_thermal_sensors[i]); if(e != NULL) { struct RSA_SensorInfo *rsa_data = g_memdup(&(snmp_rsa_dasd_thermal_sensors[i].rsa_sensor_info), sizeof(struct RSA_SensorInfo)); oh_add_rdr(tmpcache,rid,&(e->u.rdr_event.rdr), rsa_data, 0); tmpqueue = g_slist_append(tmpqueue, e); } } } /* discover all fans */ for (i = 0; i < RSA_MAX_FAN; i++) { /* see if the fan exists by querying the sensor */ if((snmp_get(custom_handle->ss, snmp_rsa_fan_sensors[i].rsa_sensor_info.mib.oid, &get_value) != 0) || (get_value.type != ASN_OCTET_STR) || (strcmp(get_value.string, "Not Readable!") == 0)) { /* If we get here the fan is not installed */ dbg("Fan %d not found.\n", i+RSA_HPI_INSTANCE_BASE); continue; } e = snmp_rsa_discover_fan(handle, &entity_root, i); if(e != NULL) { struct ResourceMibInfo *res_mib = g_memdup(&(snmp_rsa_rpt_array[RSA_RPT_ENTRY_FAN].rsa_res_info.mib), sizeof(struct snmp_rpt)); oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0); tmpqueue = g_slist_append(tmpqueue, e); SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId; SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity; /* add the fan sensor */ e = snmp_rsa_discover_sensors(handle, parent_ep, &snmp_rsa_fan_sensors[i]); if(e != NULL) { struct RSA_SensorInfo *rsa_data = g_memdup(&(snmp_rsa_fan_sensors[i].rsa_sensor_info), sizeof(struct RSA_SensorInfo)); oh_add_rdr(tmpcache,rid,&(e->u.rdr_event.rdr), rsa_data, 0); tmpqueue = g_slist_append(tmpqueue, e); } } } /* Rediscovery: Get difference between current rptcache and tmpcache. Delete obsolete items from rptcache and add new items in. */ GSList *res_new = NULL, *rdr_new = NULL, *res_gone = NULL, *rdr_gone = NULL; GSList *node = NULL; rpt_diff(handle->rptcache, tmpcache, &res_new, &rdr_new, &res_gone, &rdr_gone); dbg("%d resources have gone away.", g_slist_length(res_gone)); dbg("%d resources are new or have changed", g_slist_length(res_new)); for (node = rdr_gone; node != NULL; node = node->next) { SaHpiRdrT *rdr = (SaHpiRdrT *)node->data; SaHpiRptEntryT *res = oh_get_resource_by_ep(handle->rptcache, &(rdr->Entity)); /* Create remove rdr event and add to event queue */ struct oh_event *e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); if (e) { e->type = OH_ET_RDR_DEL; e->u.rdr_del_event.record_id = rdr->RecordId; e->u.rdr_del_event.parent_entity = rdr->Entity; handle->eventq = g_slist_append(handle->eventq, e); } else dbg("Could not allocate more memory to create event."); /* Remove rdr from plugin's rpt cache */ if (rdr && res) oh_remove_rdr(handle->rptcache, res->ResourceId, rdr->RecordId); else dbg("No valid resource or rdr at hand. Could not remove rdr."); } g_slist_free(rdr_gone); for (node = res_gone; node != NULL; node = node->next) { SaHpiRptEntryT *res = (SaHpiRptEntryT *)node->data; /* Create remove resource event and add to event queue */ struct oh_event *e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); if (e) { e->type = OH_ET_RESOURCE_DEL; e->u.res_del_event.resource_id = res->ResourceId; handle->eventq = g_slist_append(handle->eventq, e); } else dbg("Could not allocate more memory to create event."); /* Remove resource from plugin's rpt cache */ if (res) oh_remove_resource(handle->rptcache, res->ResourceId); else dbg("No valid resource at hand. Could not remove resource."); } g_slist_free(res_gone); for (node = res_new; node != NULL; node = node->next) { GSList *tmpnode = NULL; SaHpiRptEntryT *res = (SaHpiRptEntryT *)node->data; if (!res) { dbg("No valid resource at hand. Could not process new resource."); continue; } gpointer data = oh_get_resource_data(tmpcache, res->ResourceId); oh_add_resource(handle->rptcache, res, g_memdup(data, sizeof(struct snmp_rpt)),0); /* Add new/changed resources to the event queue */ for (tmpnode = tmpqueue; tmpnode != NULL; tmpnode = tmpnode->next) { struct oh_event *e = (struct oh_event *)tmpnode->data; if (e->type == OH_ET_RESOURCE && e->u.res_event.entry.ResourceId == res->ResourceId) { handle->eventq = g_slist_append(handle->eventq, e); tmpqueue = g_slist_remove_link(tmpqueue, tmpnode); g_slist_free_1(tmpnode); break; } } } g_slist_free(res_new); for (node = rdr_new; node != NULL; node = node->next) { guint rdr_data_size = 0; GSList *tmpnode = NULL; SaHpiRdrT *rdr = (SaHpiRdrT *)node->data; SaHpiRptEntryT *res = oh_get_resource_by_ep(handle->rptcache, &(rdr->Entity)); if (!res || !rdr) { dbg("No valid resource or rdr at hand. Could not process new rdr."); continue; } gpointer data = oh_get_rdr_data(tmpcache, res->ResourceId, rdr->RecordId); /* Need to figure out the size of the data associated with the rdr */ if (rdr->RdrType == SAHPI_SENSOR_RDR) rdr_data_size = sizeof(struct RSA_SensorMibInfo); else if (rdr->RdrType == SAHPI_CTRL_RDR) rdr_data_size = sizeof(struct RSA_ControlMibInfo); else if (rdr->RdrType == SAHPI_INVENTORY_RDR) rdr_data_size = sizeof(struct RSA_InventoryMibInfo); oh_add_rdr(handle->rptcache, res->ResourceId, rdr, g_memdup(data, rdr_data_size),0); /* Add new/changed rdrs to the event queue */ for (tmpnode = tmpqueue; tmpnode != NULL; tmpnode = tmpnode->next) { struct oh_event *e = (struct oh_event *)tmpnode->data; if (e->type == OH_ET_RDR && ep_cmp(&(e->u.rdr_event.rdr.Entity),&(rdr->Entity)) == 0 && e->u.rdr_event.rdr.RecordId == rdr->RecordId) { handle->eventq = g_slist_append(handle->eventq, e); tmpqueue = g_slist_remove_link(tmpqueue, tmpnode); g_slist_free_1(tmpnode); break; } } } g_slist_free(rdr_new); /* Clean up tmpqueue and tmpcache */ g_slist_free(tmpqueue); oh_flush_rpt(tmpcache); g_free(tmpcache); return SA_OK; }
/** * snmp_bc_discover_resources: * @hnd: Handler data pointer. * * Discover all the resources, sensors, controls, etc. for this instance * of the plugin. Found entities are compared with what the HPI * Infra-structure thinks is there and any new, deleted, or changed * entities are updated. * * Return values: * Builds/updates internal RPT cache - normal operation. * SA_ERR_HPI_OUT_OF_SPACE - Cannot allocate space for internal memory **/ SaErrorT snmp_bc_discover_resources(void *hnd) { char *root_tuple; SaErrorT err = SA_OK, err1 = SA_OK; SaHpiEntityPathT ep_root; if (!hnd) { 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); /* Find root Entity Path */ root_tuple = (char *)g_hash_table_lookup(handle->config, "entity_root"); if (root_tuple == NULL) { dbg("Cannot find configuration parameter."); snmp_bc_unlock_handler(custom_handle); return(SA_ERR_HPI_INTERNAL_ERROR); } err = oh_encode_entitypath(root_tuple, &ep_root); if (err) { dbg("Cannot convert entity path to string. Error=%s.", oh_lookup_error(err)); snmp_bc_unlock_handler(custom_handle); return(SA_ERR_HPI_INTERNAL_ERROR); } /* Allocate space for temporary RPT cache */ custom_handle->tmpcache = (RPTable *)g_malloc0(sizeof(RPTable)); if (custom_handle->tmpcache == NULL) { dbg("Out of memory."); snmp_bc_unlock_handler(custom_handle); return(SA_ERR_HPI_OUT_OF_SPACE); } /* Initialize tmpqueue */ custom_handle->tmpqueue = NULL; /* Individual platform discovery */ if (custom_handle->platform == SNMP_BC_PLATFORM_RSA) { err = snmp_bc_discover_rsa(handle, &ep_root); } else { err = snmp_bc_discover(handle, &ep_root); } if (err) { dbg("Discovery failed. Error=%s.", oh_lookup_error(err)); goto CLEANUP; } /********************************************************************** * Rediscovery: * Get difference between current rptcache and custom_handle->tmpcache. * Delete obsolete items from rptcache and add new items in. **********************************************************************/ GSList *res_new = NULL, *rdr_new = NULL, *res_gone = NULL, *rdr_gone = NULL; GSList *node = NULL; rpt_diff(handle->rptcache, custom_handle->tmpcache, &res_new, &rdr_new, &res_gone, &rdr_gone); trace("%d resources have gone away.", g_slist_length(res_gone)); trace("%d resources are new or have changed", g_slist_length(res_new)); for (node = rdr_gone; node != NULL; node = node->next) { SaHpiRdrT *rdr = (SaHpiRdrT *)node->data; SaHpiRptEntryT *res = oh_get_resource_by_ep(handle->rptcache, &(rdr->Entity)); /* Create remove RDR event and add to event queue */ struct oh_event *e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); if (e) { e->did = oh_get_default_domain_id(); e->type = OH_ET_RDR_DEL; e->u.rdr_event.parent = res->ResourceId; memcpy(&(e->u.rdr_event.rdr), rdr, sizeof(SaHpiRdrT)); handle->eventq = g_slist_append(handle->eventq, e); } else { dbg("Out of memory."); } /* Remove RDR from plugin's RPT cache */ if (rdr && res) oh_remove_rdr(handle->rptcache, res->ResourceId, rdr->RecordId); else { dbg("No valid resource or rdr at hand. Could not remove rdr."); } } g_slist_free(rdr_gone); for (node = res_gone; node != NULL; node = node->next) { SaHpiRptEntryT *res = (SaHpiRptEntryT *)node->data; /* Create remove resource event and add to event queue */ struct oh_event *e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); if (e) { e->did = oh_get_default_domain_id(); e->type = OH_ET_RESOURCE_DEL; e->u.res_event.entry.ResourceId = res->ResourceId; handle->eventq = g_slist_append(handle->eventq, e); } else { dbg("Out of memory."); } /* Remove resource from plugin's RPT cache */ if (res) oh_remove_resource(handle->rptcache, res->ResourceId); else dbg("No valid resource at hand. Could not remove resource."); } g_slist_free(res_gone); for (node = res_new; node != NULL; node = node->next) { GSList *tmpnode = NULL; SaHpiRptEntryT *res = (SaHpiRptEntryT *)node->data; if (!res) { dbg("No valid resource at hand. Could not process new resource."); continue; } gpointer data = oh_get_resource_data(custom_handle->tmpcache, res->ResourceId); oh_add_resource(handle->rptcache, res, g_memdup(data, sizeof(struct snmp_rpt)),0); /* Add new/changed resources to the event queue */ for (tmpnode = custom_handle->tmpqueue; tmpnode != NULL; tmpnode = tmpnode->next) { struct oh_event *e = (struct oh_event *)tmpnode->data; if (e->type == OH_ET_RESOURCE && e->u.res_event.entry.ResourceId == res->ResourceId) { handle->eventq = g_slist_append(handle->eventq, e); custom_handle->tmpqueue = g_slist_remove_link(custom_handle->tmpqueue, tmpnode); g_slist_free_1(tmpnode); break; } } } g_slist_free(res_new); for (node = rdr_new; node != NULL; node = node->next) { guint rdr_data_size = 0; GSList *tmpnode = NULL; SaHpiRdrT *rdr = (SaHpiRdrT *)node->data; SaHpiRptEntryT *res = oh_get_resource_by_ep(handle->rptcache, &(rdr->Entity)); if (!res || !rdr) { dbg("No valid resource or rdr at hand. Could not process new rdr."); continue; } gpointer data = oh_get_rdr_data(custom_handle->tmpcache, res->ResourceId, rdr->RecordId); /* Need to figure out the size of the data associated with the rdr */ if (rdr->RdrType == SAHPI_SENSOR_RDR) rdr_data_size = sizeof(struct SensorInfo); else if (rdr->RdrType == SAHPI_CTRL_RDR) rdr_data_size = sizeof(struct ControlInfo); else if (rdr->RdrType == SAHPI_INVENTORY_RDR) rdr_data_size = sizeof(struct InventoryInfo); oh_add_rdr(handle->rptcache, res->ResourceId, rdr, g_memdup(data, rdr_data_size),0); /* Add new/changed rdrs to the event queue */ for (tmpnode = custom_handle->tmpqueue; tmpnode != NULL; tmpnode = tmpnode->next) { struct oh_event *e = (struct oh_event *)tmpnode->data; if (e->type == OH_ET_RDR && oh_cmp_ep(&(e->u.rdr_event.rdr.Entity),&(rdr->Entity)) && e->u.rdr_event.rdr.RecordId == rdr->RecordId) { handle->eventq = g_slist_append(handle->eventq, e); custom_handle->tmpqueue = g_slist_remove_link(custom_handle->tmpqueue, tmpnode); g_slist_free_1(tmpnode); break; } } } g_slist_free(rdr_new); /* Build cache copy of SEL. RID == 1 (2nd parm) is a dummy id */ if (g_list_length(handle->elcache->elentries) != 0) { trace("Discovery called and elcache is not empty. Re-discovery?\n"); err1 = oh_el_clear(handle->elcache); } err1 = snmp_bc_build_selcache(handle, 1); /*err1 = snmp_bc_check_selcache(handle, 1, SAHPI_NEWEST_ENTRY); */ if (err1) { /* --------------------------------------------------------------- */ /* If an error is encounterred during building of snmp_bc elcache, */ /* only log the error. Do not do any recovery because log entries */ /* are still kept in bc mm. We'll pick them up during synch. */ /* --------------------------------------------------------------- */ dbg("snmp_bc_discover, Error %s when building elcache.\n", oh_lookup_error(err1)); } CLEANUP: g_slist_free(custom_handle->tmpqueue); oh_flush_rpt(custom_handle->tmpcache); g_free(custom_handle->tmpcache); snmp_bc_unlock_handler(custom_handle); return(err); }
/** * snmp_bc_discover_resources: * @hnd: Handler data pointer. * * Discover all the resources, sensors, controls, etc. for this instance * of the plugin. Found entities are compared with what the HPI * Infra-structure thinks is there and any new, deleted, or changed * entities are updated. * * Return values: * Builds/updates internal RPT cache - normal operation. * SA_ERR_HPI_OUT_OF_SPACE - Cannot allocate space for internal memory **/ SaErrorT snmp_bc_discover_resources(void *hnd) { char *root_tuple; SaErrorT err, err1; SaHpiEntityPathT ep_root; SaHpiEntityPathT valEntity; GSList *res_new, *rdr_new, *res_gone, *rdr_gone; GSList *node; guint rdr_data_size; GSList *tmpnode; SaHpiRdrT *rdr; SaHpiRptEntryT *res; struct oh_event *e; gpointer data; struct oh_handler_state *handle; struct snmp_bc_hnd *custom_handle; if (!hnd) { dbg("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } err = SA_OK; err1 = SA_OK; handle = (struct oh_handler_state *)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); /* Find root Entity Path */ root_tuple = (char *)g_hash_table_lookup(handle->config, "entity_root"); if (root_tuple == NULL) { dbg("Cannot find configuration parameter."); snmp_bc_unlock_handler(custom_handle); return(SA_ERR_HPI_INTERNAL_ERROR); } err = oh_encode_entitypath(root_tuple, &ep_root); if (err) { dbg("Cannot convert entity path to string. Error=%s.", oh_lookup_error(err)); snmp_bc_unlock_handler(custom_handle); return(SA_ERR_HPI_INTERNAL_ERROR); } /* Allocate space for temporary RPT cache */ custom_handle->tmpcache = (RPTable *)g_malloc0(sizeof(RPTable)); if (custom_handle->tmpcache == NULL) { dbg("Out of memory."); snmp_bc_unlock_handler(custom_handle); return(SA_ERR_HPI_OUT_OF_SPACE); } /* Initialize tmpqueue */ custom_handle->tmpqueue = NULL; /* Individual platform discovery */ if (custom_handle->platform == SNMP_BC_PLATFORM_RSA) { err = snmp_bc_discover_rsa(handle, &ep_root); } else { err = snmp_bc_discover(handle, &ep_root); } if (err) { if (err == SA_ERR_HPI_DUPLICATE) { /* Special case: * snmp_bc_discover() has found there is * no changes in any of the BladeCenter * resource masks, so there is nothing to do. * Setting returncode to SA_OK then return. */ err = SA_OK; } else { dbg("Discovery failed. Error=%s.", oh_lookup_error(err)); } goto CLEANUP; } /********************************************************************** * Rediscovery: * Get difference between current rptcache and custom_handle->tmpcache. * Delete obsolete items from rptcache and add new items in. **********************************************************************/ res_new = NULL; rdr_new = NULL; res_gone = NULL; rdr_gone = NULL; node = NULL; rpt_diff(handle->rptcache, custom_handle->tmpcache, &res_new, &rdr_new, &res_gone, &rdr_gone); trace("%d resources have gone away.", g_slist_length(res_gone)); trace("%d resources are new or have changed", g_slist_length(res_new)); for (node = rdr_gone; node != NULL; node = node->next) { rdr = (SaHpiRdrT *)node->data; snmp_bc_validate_ep(&(rdr->Entity), &valEntity); res = oh_get_resource_by_ep(handle->rptcache, &(valEntity)); /* Create remove RDR event and add to event queue */ e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); if (e) { e->did = oh_get_default_domain_id(); e->type = OH_ET_RDR_DEL; e->u.rdr_event.parent = res->ResourceId; memcpy(&(e->u.rdr_event.rdr), rdr, sizeof(SaHpiRdrT)); handle->eventq = g_slist_append(handle->eventq, e); } else { dbg("Out of memory."); } /* Remove RDR from plugin's RPT cache */ if (rdr && res) oh_remove_rdr(handle->rptcache, res->ResourceId, rdr->RecordId); else { dbg("No valid resource or rdr at hand. Could not remove rdr."); } } g_slist_free(rdr_gone); for (node = res_gone; node != NULL; node = node->next) { res = (SaHpiRptEntryT *)node->data; /* Create remove resource event and add to event queue */ e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); if (e) { e->did = oh_get_default_domain_id(); e->type = OH_ET_RESOURCE_DEL; e->u.res_event.entry.ResourceId = res->ResourceId; handle->eventq = g_slist_append(handle->eventq, e); } else { dbg("Out of memory."); } /* Remove resource from plugin's RPT cache */ if (res) oh_remove_resource(handle->rptcache, res->ResourceId); else dbg("No valid resource at hand. Could not remove resource."); } g_slist_free(res_gone); for (node = res_new; node != NULL; node = node->next) { tmpnode = NULL; res = (SaHpiRptEntryT *)node->data; if (!res) { dbg("No valid resource at hand. Could not process new resource."); continue; } data = oh_get_resource_data(custom_handle->tmpcache, res->ResourceId); if (data) { oh_add_resource(handle->rptcache, res, g_memdup(data, sizeof(struct snmp_rpt)),0); /* Add new/changed resources to the event queue */ for (tmpnode = custom_handle->tmpqueue; tmpnode != NULL; tmpnode = tmpnode->next) { struct oh_event *e = (struct oh_event *)tmpnode->data; if (e->type == OH_ET_RESOURCE && e->u.res_event.entry.ResourceId == res->ResourceId) { handle->eventq = g_slist_append(handle->eventq, e); custom_handle->tmpqueue = g_slist_remove_link(custom_handle->tmpqueue, tmpnode); g_slist_free_1(tmpnode); break; } } } else { dbg(" NULL data pointer for ResourceID %d \n", res->ResourceId); } } g_slist_free(res_new); for (node = rdr_new; node != NULL; node = node->next) { rdr_data_size = 0; tmpnode = NULL; rdr = (SaHpiRdrT *)node->data; snmp_bc_validate_ep(&(rdr->Entity), &valEntity); res = oh_get_resource_by_ep(handle->rptcache, &(valEntity)); if (!res || !rdr) { dbg("No valid resource or rdr at hand. Could not process new rdr."); continue; } data = oh_get_rdr_data(custom_handle->tmpcache, res->ResourceId, rdr->RecordId); /* Need to figure out the size of the data associated with the rdr */ if (rdr->RdrType == SAHPI_SENSOR_RDR) rdr_data_size = sizeof(struct SensorInfo); else if (rdr->RdrType == SAHPI_CTRL_RDR) rdr_data_size = sizeof(struct ControlInfo); else if (rdr->RdrType == SAHPI_INVENTORY_RDR) rdr_data_size = sizeof(struct InventoryInfo); oh_add_rdr(handle->rptcache, res->ResourceId, rdr, g_memdup(data, rdr_data_size),0); /* Add new/changed rdrs to the event queue */ for (tmpnode = custom_handle->tmpqueue; tmpnode != NULL; tmpnode = tmpnode->next) { struct oh_event *e = (struct oh_event *)tmpnode->data; if (e->type == OH_ET_RDR && oh_cmp_ep(&(e->u.rdr_event.rdr.Entity),&(rdr->Entity)) && e->u.rdr_event.rdr.RecordId == rdr->RecordId) { handle->eventq = g_slist_append(handle->eventq, e); custom_handle->tmpqueue = g_slist_remove_link(custom_handle->tmpqueue, tmpnode); g_slist_free_1(tmpnode); break; } } } g_slist_free(rdr_new); /* Build cache copy of SEL. RID == 1 (2nd parm) is a dummy id */ /** * This design depends on the BladeCenter management of the Event Log. * That is, * (a) The BC Event Log will always have at least one entry. It *never* has zero entry. * (b) If a Clear Event Log command is received, the BC clears the log, then creates * "Event Log has just been cleared by xxx" entry * So, if the cache copy of the Event Log is empty, this is the first invocation of OpenHPI/snmp_bc. * Otherwise, only processes newer entries for (re) discovery. **/ if (g_list_length(handle->elcache->elentries) == 0) err1 = snmp_bc_build_selcache(handle, 1); else err1 = snmp_bc_check_selcache(handle, 1, SAHPI_NEWEST_ENTRY); if (err1) { /* --------------------------------------------------------------- */ /* If an error is encounterred during building of snmp_bc elcache, */ /* only log the error. Do not do any recovery because log entries */ /* are still kept in bc mm. We'll pick them up during synch. */ /* --------------------------------------------------------------- */ trace("snmp_bc_discover, Error %s when building elcache.\n", oh_lookup_error(err1)); } if (custom_handle->isFirstDiscovery == SAHPI_TRUE) custom_handle->isFirstDiscovery = SAHPI_FALSE; CLEANUP: g_slist_free(custom_handle->tmpqueue); oh_flush_rpt(custom_handle->tmpcache); g_free(custom_handle->tmpcache); snmp_bc_unlock_handler(custom_handle); return(err); }
// ABI Interface functions static void * IpmiOpen( GHashTable *handler_config ) { // open log const char *logfile = 0; int max_logfiles = 10; char *tmp; int lp = dIpmiLogPropNone; dbg( "IpmiOpen" ); if ( !handler_config ) { dbg( "No config file provided.....ooops!" ); return 0; } logfile = (char *)g_hash_table_lookup( handler_config, "logfile" ); tmp = (char *)g_hash_table_lookup( handler_config, "logfile_max" ); if ( tmp ) max_logfiles = atoi( tmp ); tmp = (char *)g_hash_table_lookup( handler_config, "logflags" ); if ( tmp ) { if ( strstr( tmp, "StdOut" ) || strstr( tmp, "stdout" ) ) lp |= dIpmiLogStdOut; if ( strstr( tmp, "StdError" ) || strstr( tmp, "stderr" ) ) lp |= dIpmiLogStdError; if ( strstr( tmp, "File" ) || strstr( tmp, "file" ) ) { lp |= dIpmiLogFile; if ( logfile == 0 ) logfile = dDefaultLogfile; } } else { // default lp = dIpmiLogStdOut; if ( logfile && *logfile ) lp |= dIpmiLogFile; } IpmiLogOpen( lp, logfile, max_logfiles ); // create domain cIpmi *ipmi = new cIpmi; // allocate handler oh_handler_state *handler = (oh_handler_state *)g_malloc0( sizeof( oh_handler_state ) ); if ( !handler ) { dbg("Cannot allocate handler"); delete ipmi; return 0; } handler->data = ipmi; handler->rptcache = (RPTable *)g_malloc0( sizeof( RPTable ) ); handler->config = handler_config; ipmi->IfEnter(); ipmi->SetHandler( handler ); if ( !ipmi->IfOpen( handler_config ) ) { ipmi->IfClose(); ipmi->IfLeave(); delete ipmi; oh_flush_rpt( handler->rptcache ); g_free( handler->rptcache ); g_free( handler ); return 0; } ipmi->IfLeave(); return handler; }