xref: /onnv-gate/usr/src/cmd/rcm_daemon/common/cluster_rcm.c (revision 7202:41866725ef2f)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7202Svikram  * Common Development and Distribution License (the "License").
6*7202Svikram  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*7202Svikram  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * RCM module for managing the OS Quiesce event (SUNW_OS) in a
300Sstevel@tonic-gate  * clustered environment.
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <stdlib.h>
340Sstevel@tonic-gate #include <unistd.h>
350Sstevel@tonic-gate #include <fcntl.h>
360Sstevel@tonic-gate #include <string.h>
370Sstevel@tonic-gate #include <thread.h>
380Sstevel@tonic-gate #include <synch.h>
390Sstevel@tonic-gate #include <assert.h>
400Sstevel@tonic-gate #include <errno.h>
410Sstevel@tonic-gate #include <libintl.h>
420Sstevel@tonic-gate #include <sys/param.h>
430Sstevel@tonic-gate #include <sys/wait.h>
440Sstevel@tonic-gate #include <sys/types.h>
450Sstevel@tonic-gate #include <sys/stat.h>
460Sstevel@tonic-gate #include <sys/cladm.h>
470Sstevel@tonic-gate #include "rcm_module.h"
480Sstevel@tonic-gate 
490Sstevel@tonic-gate #define	SUNW_OS		"SUNW_OS"
500Sstevel@tonic-gate #define	OS_USAGE	gettext("Sun Cluster")
510Sstevel@tonic-gate #define	OS_SUSPEND_ERR	gettext("OS cannot be quiesced on clustered nodes")
520Sstevel@tonic-gate #define	OS_OFFLINE_ERR	gettext("Invalid operation: OS cannot be offlined")
530Sstevel@tonic-gate #define	OS_REMOVE_ERR	gettext("Invalid operation: OS cannot be removed")
540Sstevel@tonic-gate 
550Sstevel@tonic-gate static int		cluster_register(rcm_handle_t *);
560Sstevel@tonic-gate static int		cluster_unregister(rcm_handle_t *);
570Sstevel@tonic-gate static int		cluster_getinfo(rcm_handle_t *, char *, id_t, uint_t,
580Sstevel@tonic-gate 			    char **, char **, nvlist_t *, rcm_info_t **);
590Sstevel@tonic-gate static int		cluster_suspend(rcm_handle_t *, char *, id_t,
600Sstevel@tonic-gate 			    timespec_t *, uint_t, char **, rcm_info_t **);
610Sstevel@tonic-gate static int		cluster_resume(rcm_handle_t *, char *, id_t, uint_t,
620Sstevel@tonic-gate 			    char **, rcm_info_t **);
630Sstevel@tonic-gate static int		cluster_offline(rcm_handle_t *, char *, id_t, uint_t,
640Sstevel@tonic-gate 			    char **, rcm_info_t **);
650Sstevel@tonic-gate static int		cluster_online(rcm_handle_t *, char *, id_t, uint_t,
660Sstevel@tonic-gate 			    char **, rcm_info_t **);
670Sstevel@tonic-gate static int		cluster_remove(rcm_handle_t *, char *, id_t, uint_t,
680Sstevel@tonic-gate 			    char **, rcm_info_t **);
690Sstevel@tonic-gate 
700Sstevel@tonic-gate static int		cluster_SUNW_os_registered = 0;
710Sstevel@tonic-gate 
720Sstevel@tonic-gate static struct rcm_mod_ops cluster_ops =
730Sstevel@tonic-gate {
740Sstevel@tonic-gate 	RCM_MOD_OPS_VERSION,
750Sstevel@tonic-gate 	cluster_register,
760Sstevel@tonic-gate 	cluster_unregister,
770Sstevel@tonic-gate 	cluster_getinfo,
780Sstevel@tonic-gate 	cluster_suspend,
790Sstevel@tonic-gate 	cluster_resume,
800Sstevel@tonic-gate 	cluster_offline,
810Sstevel@tonic-gate 	cluster_online,
820Sstevel@tonic-gate 	cluster_remove,
830Sstevel@tonic-gate 	NULL,
840Sstevel@tonic-gate 	NULL,
850Sstevel@tonic-gate 	NULL
860Sstevel@tonic-gate };
870Sstevel@tonic-gate 
880Sstevel@tonic-gate struct rcm_mod_ops *
rcm_mod_init()890Sstevel@tonic-gate rcm_mod_init()
900Sstevel@tonic-gate {
910Sstevel@tonic-gate 	return (&cluster_ops);
920Sstevel@tonic-gate }
930Sstevel@tonic-gate 
940Sstevel@tonic-gate const char *
rcm_mod_info()950Sstevel@tonic-gate rcm_mod_info()
960Sstevel@tonic-gate {
97*7202Svikram 	return (gettext("RCM Cluster module 1.3"));
980Sstevel@tonic-gate }
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate int
rcm_mod_fini()1010Sstevel@tonic-gate rcm_mod_fini()
1020Sstevel@tonic-gate {
1030Sstevel@tonic-gate 	return (RCM_SUCCESS);
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate static int
cluster_register(rcm_handle_t * hdl)1070Sstevel@tonic-gate cluster_register(rcm_handle_t *hdl)
1080Sstevel@tonic-gate {
1090Sstevel@tonic-gate 	int bootflags;
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	if (cluster_SUNW_os_registered)
1120Sstevel@tonic-gate 		return (RCM_SUCCESS);
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	if (_cladm(CL_INITIALIZE, CL_GET_BOOTFLAG, &bootflags) != 0) {
1150Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR,
1160Sstevel@tonic-gate 			gettext("unable to check cluster status\n"));
1170Sstevel@tonic-gate 		return (RCM_FAILURE);
1180Sstevel@tonic-gate 	}
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	/* attempt to determine if we are in cluster mode */
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate 	if (bootflags & CLUSTER_BOOTED) {
1230Sstevel@tonic-gate 		if (rcm_register_interest(hdl, SUNW_OS, 0, NULL) !=
1240Sstevel@tonic-gate 		    RCM_SUCCESS) {
1250Sstevel@tonic-gate 			rcm_log_message(RCM_ERROR,
1260Sstevel@tonic-gate 			    gettext("failed to register\n"));
1270Sstevel@tonic-gate 			return (RCM_FAILURE);
1280Sstevel@tonic-gate 		} else {
1290Sstevel@tonic-gate 			cluster_SUNW_os_registered = 1;
1300Sstevel@tonic-gate 			rcm_log_message(RCM_DEBUG, "registered " SUNW_OS
1310Sstevel@tonic-gate 					"\n");
1320Sstevel@tonic-gate 		}
1330Sstevel@tonic-gate 	}
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	return (RCM_SUCCESS);
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate static int
cluster_unregister(rcm_handle_t * hdl)1390Sstevel@tonic-gate cluster_unregister(rcm_handle_t *hdl)
1400Sstevel@tonic-gate {
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	if (cluster_SUNW_os_registered) {
1430Sstevel@tonic-gate 		if (rcm_unregister_interest(hdl, SUNW_OS, 0) !=
1440Sstevel@tonic-gate 		    RCM_SUCCESS) {
1450Sstevel@tonic-gate 			rcm_log_message(RCM_ERROR,
1460Sstevel@tonic-gate 			    gettext("failed to unregister"));
1470Sstevel@tonic-gate 		}
1480Sstevel@tonic-gate 		cluster_SUNW_os_registered = 0;
1490Sstevel@tonic-gate 	}
1500Sstevel@tonic-gate 	return (RCM_SUCCESS);
1510Sstevel@tonic-gate }
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate /*ARGSUSED*/
1540Sstevel@tonic-gate static int
cluster_getinfo(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** infostr,char ** errstr,nvlist_t * props,rcm_info_t ** dependent)1550Sstevel@tonic-gate cluster_getinfo(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
1560Sstevel@tonic-gate     char **infostr, char **errstr, nvlist_t *props, rcm_info_t **dependent)
1570Sstevel@tonic-gate {
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 	assert(rsrcname != NULL && infostr != NULL);
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 	if ((*infostr = strdup(OS_USAGE)) == NULL)
1620Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	return (RCM_SUCCESS);
1650Sstevel@tonic-gate }
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate /*ARGSUSED*/
1680Sstevel@tonic-gate static int
cluster_suspend(rcm_handle_t * hdl,char * rsrcname,id_t id,timespec_t * interval,uint_t flags,char ** errstr,rcm_info_t ** dependent)1690Sstevel@tonic-gate cluster_suspend(rcm_handle_t *hdl, char *rsrcname, id_t id,
1700Sstevel@tonic-gate     timespec_t *interval, uint_t flags, char **errstr,
1710Sstevel@tonic-gate     rcm_info_t **dependent)
1720Sstevel@tonic-gate {
1730Sstevel@tonic-gate 	if ((*errstr = strdup(OS_SUSPEND_ERR)) == NULL)
1740Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate 	return (RCM_FAILURE);
1770Sstevel@tonic-gate }
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate /*ARGSUSED*/
1800Sstevel@tonic-gate static int
cluster_resume(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)1810Sstevel@tonic-gate cluster_resume(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
1820Sstevel@tonic-gate     char **errstr, rcm_info_t **dependent)
1830Sstevel@tonic-gate {
1840Sstevel@tonic-gate 	return (RCM_SUCCESS);
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate /*
1880Sstevel@tonic-gate  * By default, reject offline. If offline request is
1890Sstevel@tonic-gate  * forced, attempt to relocate the cluster device.
1900Sstevel@tonic-gate  */
1910Sstevel@tonic-gate /*ARGSUSED*/
1920Sstevel@tonic-gate static int
cluster_offline(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)1930Sstevel@tonic-gate cluster_offline(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
1940Sstevel@tonic-gate     char **errstr, rcm_info_t **dependent)
1950Sstevel@tonic-gate {
1960Sstevel@tonic-gate 	if ((*errstr = strdup(OS_OFFLINE_ERR)) == NULL)
1970Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate 	return (RCM_FAILURE);
2000Sstevel@tonic-gate }
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate /*ARGSUSED*/
2030Sstevel@tonic-gate static int
cluster_online(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)2040Sstevel@tonic-gate cluster_online(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
2050Sstevel@tonic-gate     char  **errstr, rcm_info_t **dependent)
2060Sstevel@tonic-gate {
2070Sstevel@tonic-gate 	return (RCM_SUCCESS);
2080Sstevel@tonic-gate }
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate /*ARGSUSED*/
2110Sstevel@tonic-gate static int
cluster_remove(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)2120Sstevel@tonic-gate cluster_remove(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
2130Sstevel@tonic-gate     char **errstr, rcm_info_t **dependent)
2140Sstevel@tonic-gate {
2150Sstevel@tonic-gate 	if ((*errstr = strdup(OS_REMOVE_ERR)) == NULL)
2160Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate 	return (RCM_FAILURE);
2190Sstevel@tonic-gate }
220