xref: /illumos-gate/usr/src/cmd/rcm_daemon/common/cluster_rcm.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2001, 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * RCM module for managing the OS Quiesce event (SUNW_OS) in a
31*7c478bd9Sstevel@tonic-gate  * clustered environment.
32*7c478bd9Sstevel@tonic-gate  */
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
35*7c478bd9Sstevel@tonic-gate #include <unistd.h>
36*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
37*7c478bd9Sstevel@tonic-gate #include <string.h>
38*7c478bd9Sstevel@tonic-gate #include <thread.h>
39*7c478bd9Sstevel@tonic-gate #include <synch.h>
40*7c478bd9Sstevel@tonic-gate #include <assert.h>
41*7c478bd9Sstevel@tonic-gate #include <errno.h>
42*7c478bd9Sstevel@tonic-gate #include <libintl.h>
43*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
44*7c478bd9Sstevel@tonic-gate #include <sys/wait.h>
45*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
46*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
47*7c478bd9Sstevel@tonic-gate #include <sys/cladm.h>
48*7c478bd9Sstevel@tonic-gate #include "rcm_module.h"
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #define	SUNW_OS		"SUNW_OS"
51*7c478bd9Sstevel@tonic-gate #define	OS_USAGE	gettext("Sun Cluster")
52*7c478bd9Sstevel@tonic-gate #define	OS_SUSPEND_ERR	gettext("OS cannot be quiesced on clustered nodes")
53*7c478bd9Sstevel@tonic-gate #define	OS_OFFLINE_ERR	gettext("Invalid operation: OS cannot be offlined")
54*7c478bd9Sstevel@tonic-gate #define	OS_REMOVE_ERR	gettext("Invalid operation: OS cannot be removed")
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate static int		cluster_register(rcm_handle_t *);
57*7c478bd9Sstevel@tonic-gate static int		cluster_unregister(rcm_handle_t *);
58*7c478bd9Sstevel@tonic-gate static int		cluster_getinfo(rcm_handle_t *, char *, id_t, uint_t,
59*7c478bd9Sstevel@tonic-gate 			    char **, char **, nvlist_t *, rcm_info_t **);
60*7c478bd9Sstevel@tonic-gate static int		cluster_suspend(rcm_handle_t *, char *, id_t,
61*7c478bd9Sstevel@tonic-gate 			    timespec_t *, uint_t, char **, rcm_info_t **);
62*7c478bd9Sstevel@tonic-gate static int		cluster_resume(rcm_handle_t *, char *, id_t, uint_t,
63*7c478bd9Sstevel@tonic-gate 			    char **, rcm_info_t **);
64*7c478bd9Sstevel@tonic-gate static int		cluster_offline(rcm_handle_t *, char *, id_t, uint_t,
65*7c478bd9Sstevel@tonic-gate 			    char **, rcm_info_t **);
66*7c478bd9Sstevel@tonic-gate static int		cluster_online(rcm_handle_t *, char *, id_t, uint_t,
67*7c478bd9Sstevel@tonic-gate 			    char **, rcm_info_t **);
68*7c478bd9Sstevel@tonic-gate static int		cluster_remove(rcm_handle_t *, char *, id_t, uint_t,
69*7c478bd9Sstevel@tonic-gate 			    char **, rcm_info_t **);
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate static int		cluster_SUNW_os_registered = 0;
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate static struct rcm_mod_ops cluster_ops =
74*7c478bd9Sstevel@tonic-gate {
75*7c478bd9Sstevel@tonic-gate 	RCM_MOD_OPS_VERSION,
76*7c478bd9Sstevel@tonic-gate 	cluster_register,
77*7c478bd9Sstevel@tonic-gate 	cluster_unregister,
78*7c478bd9Sstevel@tonic-gate 	cluster_getinfo,
79*7c478bd9Sstevel@tonic-gate 	cluster_suspend,
80*7c478bd9Sstevel@tonic-gate 	cluster_resume,
81*7c478bd9Sstevel@tonic-gate 	cluster_offline,
82*7c478bd9Sstevel@tonic-gate 	cluster_online,
83*7c478bd9Sstevel@tonic-gate 	cluster_remove,
84*7c478bd9Sstevel@tonic-gate 	NULL,
85*7c478bd9Sstevel@tonic-gate 	NULL,
86*7c478bd9Sstevel@tonic-gate 	NULL
87*7c478bd9Sstevel@tonic-gate };
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate struct rcm_mod_ops *
90*7c478bd9Sstevel@tonic-gate rcm_mod_init()
91*7c478bd9Sstevel@tonic-gate {
92*7c478bd9Sstevel@tonic-gate 	return (&cluster_ops);
93*7c478bd9Sstevel@tonic-gate }
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate const char *
96*7c478bd9Sstevel@tonic-gate rcm_mod_info()
97*7c478bd9Sstevel@tonic-gate {
98*7c478bd9Sstevel@tonic-gate 	return (gettext("RCM Cluster module %I%"));
99*7c478bd9Sstevel@tonic-gate }
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate int
102*7c478bd9Sstevel@tonic-gate rcm_mod_fini()
103*7c478bd9Sstevel@tonic-gate {
104*7c478bd9Sstevel@tonic-gate 	return (RCM_SUCCESS);
105*7c478bd9Sstevel@tonic-gate }
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate static int
108*7c478bd9Sstevel@tonic-gate cluster_register(rcm_handle_t *hdl)
109*7c478bd9Sstevel@tonic-gate {
110*7c478bd9Sstevel@tonic-gate 	int bootflags;
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate 	if (cluster_SUNW_os_registered)
113*7c478bd9Sstevel@tonic-gate 		return (RCM_SUCCESS);
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 	if (_cladm(CL_INITIALIZE, CL_GET_BOOTFLAG, &bootflags) != 0) {
116*7c478bd9Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR,
117*7c478bd9Sstevel@tonic-gate 			gettext("unable to check cluster status\n"));
118*7c478bd9Sstevel@tonic-gate 		return (RCM_FAILURE);
119*7c478bd9Sstevel@tonic-gate 	}
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 	/* attempt to determine if we are in cluster mode */
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate 	if (bootflags & CLUSTER_BOOTED) {
124*7c478bd9Sstevel@tonic-gate 		if (rcm_register_interest(hdl, SUNW_OS, 0, NULL) !=
125*7c478bd9Sstevel@tonic-gate 		    RCM_SUCCESS) {
126*7c478bd9Sstevel@tonic-gate 			rcm_log_message(RCM_ERROR,
127*7c478bd9Sstevel@tonic-gate 			    gettext("failed to register\n"));
128*7c478bd9Sstevel@tonic-gate 			return (RCM_FAILURE);
129*7c478bd9Sstevel@tonic-gate 		} else {
130*7c478bd9Sstevel@tonic-gate 			cluster_SUNW_os_registered = 1;
131*7c478bd9Sstevel@tonic-gate 			rcm_log_message(RCM_DEBUG, "registered " SUNW_OS
132*7c478bd9Sstevel@tonic-gate 					"\n");
133*7c478bd9Sstevel@tonic-gate 		}
134*7c478bd9Sstevel@tonic-gate 	}
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 	return (RCM_SUCCESS);
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate static int
140*7c478bd9Sstevel@tonic-gate cluster_unregister(rcm_handle_t *hdl)
141*7c478bd9Sstevel@tonic-gate {
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 	if (cluster_SUNW_os_registered) {
144*7c478bd9Sstevel@tonic-gate 		if (rcm_unregister_interest(hdl, SUNW_OS, 0) !=
145*7c478bd9Sstevel@tonic-gate 		    RCM_SUCCESS) {
146*7c478bd9Sstevel@tonic-gate 			rcm_log_message(RCM_ERROR,
147*7c478bd9Sstevel@tonic-gate 			    gettext("failed to unregister"));
148*7c478bd9Sstevel@tonic-gate 		}
149*7c478bd9Sstevel@tonic-gate 		cluster_SUNW_os_registered = 0;
150*7c478bd9Sstevel@tonic-gate 	}
151*7c478bd9Sstevel@tonic-gate 	return (RCM_SUCCESS);
152*7c478bd9Sstevel@tonic-gate }
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
155*7c478bd9Sstevel@tonic-gate static int
156*7c478bd9Sstevel@tonic-gate cluster_getinfo(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
157*7c478bd9Sstevel@tonic-gate     char **infostr, char **errstr, nvlist_t *props, rcm_info_t **dependent)
158*7c478bd9Sstevel@tonic-gate {
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate 	assert(rsrcname != NULL && infostr != NULL);
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate 	if ((*infostr = strdup(OS_USAGE)) == NULL)
163*7c478bd9Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 	return (RCM_SUCCESS);
166*7c478bd9Sstevel@tonic-gate }
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
169*7c478bd9Sstevel@tonic-gate static int
170*7c478bd9Sstevel@tonic-gate cluster_suspend(rcm_handle_t *hdl, char *rsrcname, id_t id,
171*7c478bd9Sstevel@tonic-gate     timespec_t *interval, uint_t flags, char **errstr,
172*7c478bd9Sstevel@tonic-gate     rcm_info_t **dependent)
173*7c478bd9Sstevel@tonic-gate {
174*7c478bd9Sstevel@tonic-gate 	if ((*errstr = strdup(OS_SUSPEND_ERR)) == NULL)
175*7c478bd9Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate 	return (RCM_FAILURE);
178*7c478bd9Sstevel@tonic-gate }
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
181*7c478bd9Sstevel@tonic-gate static int
182*7c478bd9Sstevel@tonic-gate cluster_resume(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
183*7c478bd9Sstevel@tonic-gate     char **errstr, rcm_info_t **dependent)
184*7c478bd9Sstevel@tonic-gate {
185*7c478bd9Sstevel@tonic-gate 	return (RCM_SUCCESS);
186*7c478bd9Sstevel@tonic-gate }
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate /*
189*7c478bd9Sstevel@tonic-gate  * By default, reject offline. If offline request is
190*7c478bd9Sstevel@tonic-gate  * forced, attempt to relocate the cluster device.
191*7c478bd9Sstevel@tonic-gate  */
192*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
193*7c478bd9Sstevel@tonic-gate static int
194*7c478bd9Sstevel@tonic-gate cluster_offline(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
195*7c478bd9Sstevel@tonic-gate     char **errstr, rcm_info_t **dependent)
196*7c478bd9Sstevel@tonic-gate {
197*7c478bd9Sstevel@tonic-gate 	if ((*errstr = strdup(OS_OFFLINE_ERR)) == NULL)
198*7c478bd9Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate 	return (RCM_FAILURE);
201*7c478bd9Sstevel@tonic-gate }
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
204*7c478bd9Sstevel@tonic-gate static int
205*7c478bd9Sstevel@tonic-gate cluster_online(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
206*7c478bd9Sstevel@tonic-gate     char  **errstr, rcm_info_t **dependent)
207*7c478bd9Sstevel@tonic-gate {
208*7c478bd9Sstevel@tonic-gate 	return (RCM_SUCCESS);
209*7c478bd9Sstevel@tonic-gate }
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
212*7c478bd9Sstevel@tonic-gate static int
213*7c478bd9Sstevel@tonic-gate cluster_remove(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
214*7c478bd9Sstevel@tonic-gate     char **errstr, rcm_info_t **dependent)
215*7c478bd9Sstevel@tonic-gate {
216*7c478bd9Sstevel@tonic-gate 	if ((*errstr = strdup(OS_REMOVE_ERR)) == NULL)
217*7c478bd9Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate 	return (RCM_FAILURE);
220*7c478bd9Sstevel@tonic-gate }
221