?? ibmhmc.c
字號:
LOG(PIL_DEBUG, "%s: called.", __FUNCTION__); } return names;}/* * Reset the given host, and obey the request type. * We should reset without power cycle for the non-partitioned case */static intibmhmc_reset_req(StonithPlugin * s, int request, const char * host){ GList* node = NULL; struct pluginDevice* dev = NULL; char off_cmd[MAX_CMD_LEN]; char on_cmd[MAX_CMD_LEN]; /* reset_cmd is only used by full system partition */ char reset_cmd[MAX_CMD_LEN]; gchar** names = NULL; int i; int is_lpar = FALSE; int status; status = 0; if(Debug){ LOG(PIL_DEBUG , "%s : called , host=%s\n" , __FUNCTION__,host); } ERRIFWRONGDEV(s,S_OOPS); if (NULL == host) { LOG( PIL_CRIT, "invalid argument to %s", __FUNCTION__); return(S_OOPS); } dev = (struct pluginDevice*) s; for (node=g_list_first(dev->hostlist) ; NULL != node ; node=g_list_next(node)) { if(Debug){ LOG(PIL_DEBUG , "%s:node->data = %s\n" , __FUNCTION__ , (char*)node->data); } if (strcasecmp((char*)node->data, host) == 0) { break; }; } if (!node) { LOG( PIL_CRIT, "%s %s", _("host s is not configured in this STONITH module." "Please check you configuration information."), host); return (S_OOPS); } names = g_strsplit((char*)node->data, "/", 2); /* names[0] will be the name of managed system */ /* names[1] will be the name of the lpar partition */ if(Debug){ LOG(PIL_DEBUG , "%s:names[0]=%s, names[1]=%s\n" , __FUNCTION__ , names[0] , names[1]); } if (0 == strcasecmp(names[1], FULLSYSTEMPARTITION)) { is_lpar = FALSE; snprintf(off_cmd, MAX_CMD_LEN , SSH_CMD " -l " HMCROOT " %s chsysstate" " -r sys -m %s -o off -n %s -c full" , dev->hmc, dev->hmc, names[0]); snprintf(on_cmd, MAX_CMD_LEN , SSH_CMD " -l " HMCROOT " %s chsysstate" " -r sys -m %s -o on -n %s -c full -b norm" , dev->hmc, names[0], names[0]); snprintf(reset_cmd, MAX_CMD_LEN , SSH_CMD " -l " HMCROOT " %s chsysstate" " -r sys -m %s -o reset -n %s -c full -b norm" , dev->hmc, names[0], names[0]); } else { is_lpar = TRUE; snprintf(off_cmd, MAX_CMD_LEN , SSH_CMD " -l " HMCROOT " %s reset_partition" " -m %s -p %s -t hard" , dev->hmc, names[0], names[1]); snprintf(on_cmd, MAX_CMD_LEN , SSH_CMD " -l " HMCROOT " %s chsysstate" " -r lpar -m %s -o on -n %s" , dev->hmc, names[0], names[1]); } if(Debug){ LOG(PIL_DEBUG , "%s: off_cmd=%s , on_cmd=%s , reset_cmd=%s\n" , __FUNCTION__ , off_cmd , on_cmd , reset_cmd); } g_strfreev(names); switch (request) { case ST_POWERON: do_shell_cmd(on_cmd,&status); if (0!=status) { LOG( PIL_CRIT, "command %s failed", on_cmd); } break; case ST_POWEROFF: do_shell_cmd(off_cmd,&status); if (0!=status) { LOG( PIL_CRIT, "command %s failed", off_cmd); } break; case ST_GENERIC_RESET: if (is_lpar) { do_shell_cmd(off_cmd,&status); if (0!=status) { LOG( PIL_CRIT, "command %s failed", off_cmd); break; } for (i=0; i < MAX_POWERON_RETRY; i++) { do_shell_cmd(on_cmd,&status); if (0!=status) { sleep(1); }else{ break; } } if (MAX_POWERON_RETRY == i) { LOG( PIL_CRIT, "command %s failed", on_cmd); } } else { do_shell_cmd(reset_cmd,&status); if (0!=status) { LOG( PIL_CRIT, "command %s failed", reset_cmd); } break; } break; default: LOG( PIL_CRIT, "unknown reset request"); } LOG( PIL_INFO, "%s: %s", _("Host ibmhmc-reset."), host); return S_OK;}/* * Parse the information in the given configuration file, * and stash it away... */static intibmhmc_set_config(StonithPlugin * s, StonithNVpair* list){ struct pluginDevice* dev = NULL; const char * hlist; ERRIFWRONGDEV(s,S_OOPS); if(Debug){ LOG(PIL_DEBUG , "%s: called\n" , __FUNCTION__); } dev = (struct pluginDevice*) s; if(( hlist = OurImports->GetValue(list , ST_HOSTLIST)) == NULL){ return S_OOPS; } if(Debug){ LOG(PIL_DEBUG, "%s: hlist = %s\n" , __FUNCTION__ , hlist); } if (S_OK != ibmhmc_parse_config_info(dev , hlist)){ return S_BADCONFIG; } return S_OK;}static const char*ibmhmc_getinfo(StonithPlugin* s, int reqtype){ struct pluginDevice* dev; char* ret; ERRIFWRONGDEV(s,NULL); dev = (struct pluginDevice *)s; switch (reqtype) { case ST_DEVICEID: ret = _("IBM pSeries HMC"); break; case ST_DEVICEDESCR: ret = _("IBM pSeries Hardware Management Console (HMC)\n" "Use for HMC-equipped IBM pSeries Server\n" "Providing the list of hosts should go away (!)...\n" "This code probably only works on the POWER4 " "architecture systems\n See " HMCURL " for more " "information.\n"); break; default: ret = NULL; break; } return ret;}/* * HMC Stonith destructor... */static voidibmhmc_destroy(StonithPlugin *s){ struct pluginDevice* dev; VOIDERRIFWRONGDEV(s); if(Debug){ LOG(PIL_DEBUG , "%s : called\n" , __FUNCTION__); } dev = (struct pluginDevice *)s; dev->pluginid = NOTpluginID; if (dev->hmc) { FREE(dev->hmc); dev->hmc = NULL; } if (dev->hostlist) { GList* node; while (NULL != (node=g_list_first(dev->hostlist))) { dev->hostlist = g_list_remove_link(dev->hostlist, node); FREE(node->data); g_list_free(node); } dev->hostlist = NULL; } FREE(dev);}static StonithPlugin *ibmhmc_new(void){ struct pluginDevice* dev = MALLOCT(struct pluginDevice); if(Debug){ LOG(PIL_DEBUG , "%s: called\n" , __FUNCTION__); } if (dev == NULL) { LOG( PIL_CRIT, "%s: out of memory" , __FUNCTION__); return(NULL); } memset(dev, 0, sizeof(*dev)); dev->pluginid = pluginid; dev->hmc = NULL; dev->hostlist = NULL; dev->sp.s_ops = &ibmhmcOps; if(Debug){ LOG(PIL_DEBUG , "%s: returning successfully\n" , __FUNCTION__); } return((void *)dev);}static char*do_shell_cmd(const char* cmd, int* status){ const int BUFF_LEN=4096; int read_len = 0; char buff[BUFF_LEN]; char* data = NULL; GString* g_str_tmp = NULL; FILE* file = popen(cmd, "r"); if (NULL==file) { return NULL; } g_str_tmp = g_string_new(""); while(!feof(file)) { memset(buff, 0, BUFF_LEN); read_len = fread(buff, 1, BUFF_LEN, file); if (0<read_len) { g_string_append(g_str_tmp, buff); } else { sleep(1); } } data = (char*)MALLOC(g_str_tmp->len+1); data[0] = data[g_str_tmp->len] = 0; strncpy(data, g_str_tmp->str, g_str_tmp->len); g_string_free(g_str_tmp, TRUE); *status = pclose(file); return data;}static intcheck_hmc_status(const char* hmc){ int status; char check_status[MAX_CMD_LEN]; char* output = NULL; if(Debug){ LOG(PIL_DEBUG , "%s: called,hmc=%s\n" , __FUNCTION__,hmc); } snprintf(check_status, MAX_CMD_LEN, SSH_CMD " -l " HMCROOT " %s lshmc -r -F ssh", hmc); if(Debug){ LOG(PIL_INFO , "%s: check_status=%s\n" , __FUNCTION__ , check_status); } output = do_shell_cmd(check_status, &status); if (Debug) { LOG(PIL_DEBUG , "%s : output=%s\n" , __FUNCTION__ , output); } if (NULL==output || strncmp(output, "enable", 6)!= 0) { return S_BADCONFIG; } FREE(output); return S_OK;}/*static char*do_shell_cmd_fake(const char* cmd, int* status){printf("%s()\n",__FUNCTION__); printf("cmd:%s\n",cmd); *status=0; return NULL;}*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -