📄 null.c
字号:
/* $Id: null.c,v 1.17 2005/01/03 18:12:11 alan Exp $ *//* * Stonith module for NULL Stonith device * * Copyright (c) 2000 Alan Robertson <alanr@unix.sh> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */#define DEVICE "NULL STONITH device"#include "stonith_plugin_common.h"#define PIL_PLUGIN null#define PIL_PLUGIN_S "null"#define PIL_PLUGINLICENSE LICENSE_LGPL#define PIL_PLUGINLICENSEURL URL_LGPL#include <pils/plugin.h>struct pluginDevice { StonithPlugin sp; const char * pluginid; char ** hostlist; int hostcount;};static StonithPlugin* null_new(void);static void null_destroy(StonithPlugin *);static int null_set_config(StonithPlugin*, StonithNVpair*);static const char** null_get_confignames(StonithPlugin*);static const char * null_getinfo(StonithPlugin * s, int InfoType);static int null_status(StonithPlugin * );static int null_reset_req(StonithPlugin * s, int request, const char * host);static char ** null_hostlist(StonithPlugin *);static struct stonith_ops nullOps ={ null_new, /* Create new STONITH object */ null_destroy, /* Destroy STONITH object */ null_getinfo, /* Return STONITH info string */ null_get_confignames, /* Return list of config params */ null_set_config, /* configure fron NV pairs */ null_status, /* Return STONITH device status */ null_reset_req, /* Request a reset */ null_hostlist, /* Return list of supported hosts */};PIL_PLUGIN_BOILERPLATE2("1.0", Debug)static const PILPluginImports* PluginImports;static PILPlugin* OurPlugin;static PILInterface* OurInterface;static StonithImports* OurImports;static void* interfprivate;PIL_rcPIL_PLUGIN_INIT(PILPlugin*us, const PILPluginImports* imports);PIL_rcPIL_PLUGIN_INIT(PILPlugin*us, const PILPluginImports* imports){ /* Force the compiler to do a little type checking */ (void)(PILPluginInitFun)PIL_PLUGIN_INIT; PluginImports = imports; OurPlugin = us; /* Register ourself as a plugin */ imports->register_plugin(us, &OurPIExports); /* Register our interface implementation */ return imports->register_interface(us, PIL_PLUGINTYPE_S , PIL_PLUGIN_S , &nullOps , NULL /*close */ , &OurInterface , (void*)&OurImports , &interfprivate); }/* * Null STONITH device. We are very agreeable, but don't do much :-) */static const char * pluginid = "pluginDevice-Stonith";static const char * NOTpluginID = "Hey, dummy this has been destroyed (NullDev)";static intnull_status(StonithPlugin *s){ ERRIFWRONGDEV(s, S_OOPS); return S_OK;}/* * Return the list of hosts configured for this NULL device */static char **null_hostlist(StonithPlugin *s){ struct pluginDevice* nd = (struct pluginDevice*)s; ERRIFWRONGDEV(s, NULL); return OurImports->CopyHostList((const char**)nd->hostlist);}/* * Pretend to reset the given host on this Stonith device. * (we don't even error check the "request" type) */static intnull_reset_req(StonithPlugin * s, int request, const char * host){ ERRIFWRONGDEV(s,S_OOPS); /* Real devices need to pay attention to the "request" */ /* (but we don't care ;-)) */ LOG(PIL_INFO,"%s: %s", _("Host null-reset"), host); return S_OK;}static const char**null_get_confignames(StonithPlugin* p){ static const char * NullParams[] = {ST_HOSTLIST, NULL }; return NullParams;}/* * Parse the config information in the given string, * and stash it away... */static intnull_set_config(StonithPlugin* s, StonithNVpair* list){ struct pluginDevice* nd = (struct pluginDevice*) s; const char * hlist; ERRIFWRONGDEV(s, S_OOPS); if ((hlist = OurImports->GetValue(list, ST_HOSTLIST)) == NULL) { LOG(PIL_CRIT,"GetValue(ST_HOSTLIST) failed"); return S_BADCONFIG; } nd->hostlist = OurImports->StringToHostList(hlist); if (nd->hostlist == NULL) { LOG(PIL_CRIT,"StringToHostList() failed"); return S_OOPS; } for (nd->hostcount = 0; nd->hostlist[nd->hostcount] ; nd->hostcount++) { /* Just count */ } return nd->hostcount ? S_OK : S_BADCONFIG;}static const char *null_getinfo(StonithPlugin * s, int reqtype){ const char * ret; ERRIFWRONGDEV(s, NULL); switch (reqtype) { case ST_DEVICEID: ret = "null STONITH device"; break; case ST_DEVICEDESCR: ret = "Dummy (do-nothing) STONITH device\n" "FOR TESTING ONLY!"; break; default: ret = NULL; break; } return ret;}/* * NULL Stonith destructor... */static voidnull_destroy(StonithPlugin *s){ struct pluginDevice* nd; VOIDERRIFWRONGDEV(s); nd = (struct pluginDevice *)s; nd->pluginid = NOTpluginID; if (nd->hostlist) { stonith_free_hostlist(nd->hostlist); nd->hostlist = NULL; } nd->hostcount = -1; FREE(s);}/* Create a new Null Stonith device. * Too bad this function can't be static */static StonithPlugin *null_new(void){ struct pluginDevice* nd = MALLOCT(struct pluginDevice); if (nd == NULL) { LOG(PIL_CRIT, "out of memory"); return(NULL); } memset(nd, 0, sizeof(*nd)); nd->pluginid = pluginid; nd->sp.s_ops = &nullOps; return (StonithPlugin *)nd;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -