1 /*
2  *	S hoot
3  *	T he
4  *	O ther
5  *	N ode
6  *	I n
7  *	T he
8  *	H ead
9  *
10  *	Cause the other machine to reboot or die - now.
11  *
12  *	We guarantee that when we report that the machine has been
13  *	rebooted, then it has been (barring misconfiguration or hardware
14  *	errors)
15  *
16  *	A machine which we have STONITHed won't do anything more to its
17  *	peripherials etc. until it goes through the reboot cycle.
18  */
19 
20 /*
21  *
22  * Copyright (c) 2000 Alan Robertson <alanr@unix.sh>
23  * Copyright (c) 2004 International Business Machines, Inc.
24  *
25  * Author: Alan Robertson
26  *
27  * This library is free software; you can redistribute it and/or
28  * modify it under the terms of the GNU Lesser General Public
29  * License as published by the Free Software Foundation; either
30  * version 2.1 of the License, or (at your option) any later version.
31  *
32  * This library is distributed in the hope that it will be useful,
33  * but WITHOUT ANY WARRANTY; without even the implied warranty of
34  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
35  * Lesser General Public License for more details.
36  *
37  * You should have received a copy of the GNU Lesser General Public
38  * License along with this library; if not, write to the Free Software
39  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
40  *
41  */
42 
43 #ifndef __STONITH_H
44 #	define __STONITH_H
45 #include <glib.h>
46 #include <ctype.h>
47 
48 #include <pils/plugin.h>
49 #define	STONITH_VERS	2
50 
51 /*
52  *	Return codes from "Stonith" operations
53  */
54 
55 #define	S_OK		0	/* Machine correctly reset	*/
56 #define	S_BADCONFIG	1	/* Bad config info given	*/
57 #define	S_ACCESS	2	/* Can't access STONITH device	*/
58 				/* (login/passwd problem?)	*/
59 #define	S_INVAL		3	/* Bad/illegal argument		*/
60 #define	S_BADHOST	4	/* Bad/illegal host/node name	*/
61 #define	S_RESETFAIL	5	/* Reset failed			*/
62 #define	S_TIMEOUT	6	/* Timed out in the dialogues	*/
63 #define	S_ISOFF		7	/* Can't reboot: Outlet is off	*/
64 #define	S_OOPS		8	/* Something strange happened	*/
65 
66 typedef struct stonith {
67 	char *	stype;
68 }Stonith;
69 
70 /* An array of StonithNVpairs is terminated by a NULL s_name */
71 typedef struct {
72 	char *	s_name;
73 	char *	s_value;
74 }StonithNVpair;
75 
76 /*
77  *	Operation requested by reset_req()
78  */
79 #define	ST_GENERIC_RESET	1 /* Reset the machine any way you can */
80 #define	ST_POWERON		2 /* Power the node on */
81 #define	ST_POWEROFF		3 /* Power the node off */
82 /*
83  *	Type of information requested by the get_info() call
84  */
85 #define ST_CONF_XML	1	/* XML config info */
86 #define ST_DEVICEID	2	/* Device Type Identification */
87 #define ST_DEVICENAME	3	/* Unique Individual Device Identification */
88 				/* (only after stonith_set_config() call) */
89 #define ST_DEVICEDESCR	4	/* Device Description text */
90 #define ST_DEVICEURL	5	/* Manufacturer/Device URL */
91 
92 extern PILPluginUniv *StonithPIsys;
93 
94 char **	stonith_types(void);	/* NULL-terminated list */
95 				/* valid until next call of stonith_types() */
96 Stonith*stonith_new(const char * type);
97 void	stonith_delete(Stonith *);
98 
99 const char * const *	stonith_get_confignames	(Stonith* s);
100 				/* static/global return */
101 				/* Return number and list of valid s_names */
102 
103 const char*			/* static/global return - lots of things! */
104 	stonith_get_info	(Stonith* s, int infotype);
105 
106 void	stonith_set_debug	(Stonith* s, int debuglevel);
107 void	stonith_set_log		(Stonith* s
108 				, PILLogFun);
109 
110 int	stonith_set_config	(Stonith* s, StonithNVpair* list);
111 int	stonith_set_config_file(Stonith* s, const char * configname);
112 				/* uses get_confignames to determine which
113 				 * names to look for in file configname, which
114 				 * is passed in by the -F option */
115 int	stonith_set_config_info(Stonith* s, const char * info);
116 				/* uses get_confignames to determine which
117 				 * names to look for in string info, which
118 				 * is passed in by the -p option */
119 	/*
120 	 * Must call stonith_set_config() before calling functions below...
121 	 */
122 char**	stonith_get_hostlist	(Stonith* s);
123 void	stonith_free_hostlist	(char** hostlist);
124 int	stonith_get_status	(Stonith* s);
125 int	stonith_req_reset	(Stonith* s, int operation, const char* node);
126 
127 StonithNVpair* stonith_env_to_NVpair(Stonith* s);
128 
129 /* Stonith 1 compatibility:  Convert string to an NVpair set */
130 StonithNVpair*
131 	stonith1_compat_string_to_NVpair(Stonith* s, const char * str);
132 StonithNVpair*
133 	stonith_ghash_to_NVpair(GHashTable* stringtable);
134 void	free_NVpair(StonithNVpair*); /* Free result from above 2 functions */
135 void strdown(char *str); /* simple replacement for g_strdown */
136 
137 /*
138  * The ST_DEVICEID info call is intended to return the type of the Stonith
139  * device.  Note that it may return a different result once it has attempted
140  * to talk to the device (like after a status() call).  This is because
141  * a given STONITH module may be able to talk to more than one kind of
142  * model of STONITH device, and can't tell which type is out there
143  * to until it talks to it.  For example, Baytech 3, Baytech 5 and
144  * Baytech 5a are all supported by one module, and this module actually
145  * captures the particular model number after it talks to it.
146  *
147  * The ST_DEVICEDESCR info call is intended to return information identifying
148  * the type of STONITH device supported by this STONITH object.  This is so
149  * users can tell if they have this kind of device or not.
150  *
151  * SHOULD THIS BE IN THE XML SO IT CAN BE SUPPLIED IN SEVERAL LANGUAGES??
152  * But, this would mean the STONITH command would have to parse XML.
153  * Sigh...  I'd rather not...  Or maybe it can be supplied duplicately
154  * in the XML if that is thought to be desirable...
155  *
156  * The ST_DEVICEURL info call is intended to return the URL of a web site
157  * related to the device in question.  This might be the manufacturer,
158  * a pointer to the product line, or the individual product itself.
159  *
160  * A good way for a GUI to work which configures STONITH devices would be to
161  * use the result of the stonith_types() call in a pulldown menu.
162  *
163  * Once the type is selected, create a Stonith object of the selected type.
164  * One can then create a dialog box to create the configuration info for the
165  * device using return from the ST_CONF_XML info call to direct the
166  * GUI in what information to ask for to fill up the StonithNVpair
167  * argument to the stonith_set_config() call.  This information would then
168  * be prompted for according to the XML information, and then put into
169  * a NULL-terminated array of StonithNVpair objects.
170  *
171  * Once this has been done, it can be tested for syntactic
172  * validity with stonith_set_config().
173  *
174  * If it passes set_config(), it can be further validated using status()
175  * which will then actually try and talk to the STONITH device.  If status()
176  * returns S_OK, then communication with the device was successfully
177  * established.
178  *
179  * Normally that would mean that logins, passwords, device names, and IP
180  * addresses, etc. have been validated as required by the particular device.
181  *
182  * At this point, you can ask the device which machines it knows how to reset
183  * using the stonith_get_hostlist() function.
184  *
185  */
186 
187 #endif /*__STONITH_H*/
188