static int bladehpi_status(StonithPlugin *s) { struct pluginDevice * dev; SaErrorT ohrc; SaHpiDomainInfoT ohdi; int rc = S_OK; if (Debug) { LOG(PIL_DEBUG, "%s: called", __FUNCTION__); } ERRIFWRONGDEV(s, S_OOPS); dev = (struct pluginDevice *)s; rc = open_hpi_session(dev); if( rc != S_OK ) return rc; /* Refresh the hostlist only if RPTs updated */ ohrc = saHpiDomainInfoGet(dev->ohsession, &ohdi); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to get domain info in %s (%d)" , __FUNCTION__, ohrc); rc = S_BADCONFIG; goto done; } if (dev->ohrptcnt != ohdi.RptUpdateCount) { free_bladehpi_hostlist(dev); if (get_bladehpi_hostlist(dev) != S_OK) { LOG(PIL_CRIT, "Unable to obtain list of hosts in %s" , __FUNCTION__); rc = S_BADCONFIG; goto done; } } /* At this point, hostlist is up to date */ if (dev->ohsensid && dev->ohsensnum) { /* * For accurate status, need to make a call that goes out to * BladeCenter MM because the calls made so far by this * function (and perhaps get_bladehpi_hostlist) only retrieve * information from memory cached by OpenHPI */ ohrc = saHpiSensorReadingGet(dev->ohsession , dev->ohsensid, dev->ohsensnum, NULL, NULL); if (ohrc == SA_ERR_HPI_BUSY || ohrc == SA_ERR_HPI_NO_RESPONSE) { LOG(PIL_CRIT, "Unable to connect to BladeCenter in %s" , __FUNCTION__); rc = S_OOPS; goto done; } } done: close_hpi_session(dev); return (rc == S_OK) ? (dev->ohdevid ? S_OK : S_OOPS) : rc; }
static int bladehpi_set_config(StonithPlugin *s, StonithNVpair *list) { struct pluginDevice * dev = NULL; StonithNamesToGet namestocopy [] = { {ST_ENTITYROOT, NULL} , {NULL, NULL} }; int rc, i; SaErrorT ohrc; if (Debug) { LOG(PIL_DEBUG, "%s: called", __FUNCTION__); } ERRIFWRONGDEV(s, S_OOPS); dev = (struct pluginDevice *)s; if (Debug) { LOG(PIL_DEBUG, "%s conditionally compiled with:" #ifdef IBMBC_WAIT_FOR_OFF " IBMBC_WAIT_FOR_OFF" #endif , dev->pluginid); } if ((rc = OurImports->CopyAllValues(namestocopy, list)) != S_OK) { return rc; } if (Debug) { LOG(PIL_DEBUG, "%s = %s", ST_ENTITYROOT , namestocopy[0].s_value); } if (get_num_tokens(namestocopy[0].s_value) == 1) { /* name=value pairs on command line, look for soft_reset */ const char *softreset = OurImports->GetValue(list, ST_SOFTRESET); if (softreset != NULL) { if (!strcasecmp(softreset, "true") || !strcmp(softreset, "1")) { dev->softreset = 1; } else if (!strcasecmp(softreset, "false") || !strcmp(softreset, "0")) { dev->softreset = 0; } else { LOG(PIL_CRIT, "Invalid %s %s, must be " "true, 1, false or 0" , ST_SOFTRESET, softreset); FREE(namestocopy[0].s_value); return S_OOPS; } } } else { /* -p or -F option with args "entity_root [soft_reset]..." */ char *pch = namestocopy[0].s_value; /* skip over entity_root and null-terminate */ pch += strcspn(pch, WHITESPACE); *pch = EOS; /* skip over white-space up to next token */ pch++; pch += strspn(pch, WHITESPACE); if (!strcasecmp(pch, "true") || !strcmp(pch, "1")) { dev->softreset = 1; } else if (!strcasecmp(pch, "false") || !strcmp(pch, "0")) { dev->softreset = 0; } else { LOG(PIL_CRIT, "Invalid %s %s, must be " "true, 1, false or 0" , ST_SOFTRESET, pch); FREE(namestocopy[0].s_value); return S_OOPS; } } dev->device = STRDUP(namestocopy[0].s_value); FREE(namestocopy[0].s_value); if (dev->device == NULL) { LOG(PIL_CRIT, "Out of memory for strdup in %s", __FUNCTION__); return S_OOPS; } if (strcspn(dev->device, WHITESPACE) != strlen(dev->device) || sscanf(dev->device, SYSTEM_CHASSIS_FMT, &i) != 1 || i < 0) { LOG(PIL_CRIT, "Invalid %s %s, must be of format %s" , ST_ENTITYROOT, dev->device, SYSTEM_CHASSIS_FMT); return S_BADCONFIG; } dev->ohver = saHpiVersionGet(); if (dev->ohver > SAHPI_INTERFACE_VERSION) { LOG(PIL_CRIT, "Installed OpenHPI interface (%x) greater than " "one used by plugin (%x), incompatibilites may exist" , dev->ohver, SAHPI_INTERFACE_VERSION); return S_BADCONFIG; } ohrc = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID , &dev->ohsession, NULL); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to open HPI session (%d)", ohrc); return S_BADCONFIG; } ohrc = saHpiDiscover(dev->ohsession); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to discover resources (%d)", ohrc); return S_BADCONFIG; } if (get_bladehpi_hostlist(dev) != S_OK) { LOG(PIL_CRIT, "Unable to obtain list of hosts in %s" , __FUNCTION__); return S_BADCONFIG; } return S_OK; }
static int bladehpi_reset_req(StonithPlugin *s, int request, const char *host) { GList * node = NULL; struct pluginDevice * dev = NULL; struct blade_info * bi = NULL; SaHpiPowerStateT ohcurstate, ohnewstate; SaHpiDomainInfoT ohdi; SaErrorT ohrc; int rc = S_OK; if (Debug) { LOG(PIL_DEBUG, "%s: called, request=%d, host=%s" , __FUNCTION__, request, host); } ERRIFWRONGDEV(s, S_OOPS); if (host == NULL) { LOG(PIL_CRIT, "Invalid host argument to %s", __FUNCTION__); rc = S_OOPS; goto done; } dev = (struct pluginDevice *)s; rc = open_hpi_session(dev); if( rc != S_OK ) return rc; ohrc = saHpiDomainInfoGet(dev->ohsession, &ohdi); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to get domain info in %s (%d)" , __FUNCTION__, ohrc); rc = S_BADCONFIG; goto done; } if (dev->ohrptcnt != ohdi.RptUpdateCount) { free_bladehpi_hostlist(dev); if (get_bladehpi_hostlist(dev) != S_OK) { LOG(PIL_CRIT, "Unable to obtain list of hosts in %s" , __FUNCTION__); rc = S_OOPS; goto done; } } for (node = g_list_first(dev->hostlist) ; node != NULL ; node = g_list_next(node)) { bi = ((struct blade_info *)node->data); if (Debug) { LOG(PIL_DEBUG, "Found host %s in hostlist", bi->name); } if (!strcasecmp(bi->name, host)) { break; } } if (!node || !bi) { LOG(PIL_CRIT , "Host %s is not configured in this STONITH module, " "please check your configuration information", host); rc = S_OOPS; goto done; } /* Make sure host has proper capabilities for get */ if (!(bi->resourceCaps & SAHPI_CAPABILITY_POWER)) { LOG(PIL_CRIT , "Host %s does not have power capability", host); rc = S_OOPS; goto done; } ohrc = saHpiResourcePowerStateGet(dev->ohsession, bi->resourceId , &ohcurstate); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to get host %s power state (%d)" , host, ohrc); rc = S_OOPS; goto done; } switch (request) { case ST_POWERON: if (ohcurstate == SAHPI_POWER_ON) { LOG(PIL_INFO, "Host %s already on", host); goto done; } ohnewstate = SAHPI_POWER_ON; break; case ST_POWEROFF: if (ohcurstate == SAHPI_POWER_OFF) { LOG(PIL_INFO, "Host %s already off", host); goto done; } ohnewstate = SAHPI_POWER_OFF; break; case ST_GENERIC_RESET: if (ohcurstate == SAHPI_POWER_OFF) { ohnewstate = SAHPI_POWER_ON; } else { ohnewstate = SAHPI_POWER_CYCLE; } break; default: LOG(PIL_CRIT, "Invalid request argument to %s" , __FUNCTION__); rc = S_INVAL; goto done; } if (!dev->softreset && (ohnewstate == SAHPI_POWER_CYCLE)) { int maxwait; ohrc = saHpiResourcePowerStateSet(dev->ohsession , bi->resourceId, SAHPI_POWER_OFF); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to set host %s power state to" " OFF (%d)", host, ohrc); rc = S_OOPS; goto done; } /* * Must wait for power off here or subsequent power on request * may take place while power is still on and thus ignored */ maxwait = MAX_POWEROFF_WAIT; do { maxwait--; sleep(1); ohrc = saHpiResourcePowerStateGet(dev->ohsession , bi->resourceId, &ohcurstate); } while ((ohrc == SA_OK) && (ohcurstate != SAHPI_POWER_OFF) && (maxwait > 0)); if (Debug) { LOG(PIL_DEBUG, "Waited %d seconds for power off" , MAX_POWEROFF_WAIT - maxwait); } ohrc = saHpiResourcePowerStateSet(dev->ohsession , bi->resourceId, SAHPI_POWER_ON); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to set host %s power state to" " ON (%d)", host, ohrc); rc = S_OOPS; goto done; } } else { /* Make sure host has proper capabilities to reset */ if ((ohnewstate == SAHPI_POWER_CYCLE) && (!(bi->resourceCaps & SAHPI_CAPABILITY_RESET))) { LOG(PIL_CRIT , "Host %s does not have reset capability" , host); rc = S_OOPS; goto done; } if ((ohrc = saHpiResourcePowerStateSet(dev->ohsession , bi->resourceId, ohnewstate)) != SA_OK) { LOG(PIL_CRIT, "Unable to set host %s power state (%d)" , host, ohrc); rc = S_OOPS; goto done; } } #ifdef IBMBC_WAIT_FOR_OFF if (ohnewstate == SAHPI_POWER_OFF) { int maxwait = MAX_POWEROFF_WAIT; do { maxwait--; sleep(1); ohrc = saHpiResourcePowerStateGet(dev->ohsession , bi->resourceId, &ohcurstate); } while ((ohrc == SA_OK) && (ohcurstate != SAHPI_POWER_OFF) && (maxwait > 0)); if (Debug) { LOG(PIL_DEBUG, "Waited %d seconds for power off" , MAX_POWEROFF_WAIT - maxwait); } } #endif LOG(PIL_INFO, "Host %s %s %d.", host, __FUNCTION__, request); done: close_hpi_session(dev); return rc; }