xref: /titanic_44/usr/src/cmd/rcm_daemon/common/cluster_rcm.c (revision 648495d6a097a39eaebc7e56d25f2463ff3bba65)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*648495d6Svikram  * Common Development and Distribution License (the "License").
6*648495d6Svikram  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*648495d6Svikram  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * RCM module for managing the OS Quiesce event (SUNW_OS) in a
307c478bd9Sstevel@tonic-gate  * clustered environment.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <stdlib.h>
347c478bd9Sstevel@tonic-gate #include <unistd.h>
357c478bd9Sstevel@tonic-gate #include <fcntl.h>
367c478bd9Sstevel@tonic-gate #include <string.h>
377c478bd9Sstevel@tonic-gate #include <thread.h>
387c478bd9Sstevel@tonic-gate #include <synch.h>
397c478bd9Sstevel@tonic-gate #include <assert.h>
407c478bd9Sstevel@tonic-gate #include <errno.h>
417c478bd9Sstevel@tonic-gate #include <libintl.h>
427c478bd9Sstevel@tonic-gate #include <sys/param.h>
437c478bd9Sstevel@tonic-gate #include <sys/wait.h>
447c478bd9Sstevel@tonic-gate #include <sys/types.h>
457c478bd9Sstevel@tonic-gate #include <sys/stat.h>
467c478bd9Sstevel@tonic-gate #include <sys/cladm.h>
477c478bd9Sstevel@tonic-gate #include "rcm_module.h"
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #define	SUNW_OS		"SUNW_OS"
507c478bd9Sstevel@tonic-gate #define	OS_USAGE	gettext("Sun Cluster")
517c478bd9Sstevel@tonic-gate #define	OS_SUSPEND_ERR	gettext("OS cannot be quiesced on clustered nodes")
527c478bd9Sstevel@tonic-gate #define	OS_OFFLINE_ERR	gettext("Invalid operation: OS cannot be offlined")
537c478bd9Sstevel@tonic-gate #define	OS_REMOVE_ERR	gettext("Invalid operation: OS cannot be removed")
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate static int		cluster_register(rcm_handle_t *);
567c478bd9Sstevel@tonic-gate static int		cluster_unregister(rcm_handle_t *);
577c478bd9Sstevel@tonic-gate static int		cluster_getinfo(rcm_handle_t *, char *, id_t, uint_t,
587c478bd9Sstevel@tonic-gate 			    char **, char **, nvlist_t *, rcm_info_t **);
597c478bd9Sstevel@tonic-gate static int		cluster_suspend(rcm_handle_t *, char *, id_t,
607c478bd9Sstevel@tonic-gate 			    timespec_t *, uint_t, char **, rcm_info_t **);
617c478bd9Sstevel@tonic-gate static int		cluster_resume(rcm_handle_t *, char *, id_t, uint_t,
627c478bd9Sstevel@tonic-gate 			    char **, rcm_info_t **);
637c478bd9Sstevel@tonic-gate static int		cluster_offline(rcm_handle_t *, char *, id_t, uint_t,
647c478bd9Sstevel@tonic-gate 			    char **, rcm_info_t **);
657c478bd9Sstevel@tonic-gate static int		cluster_online(rcm_handle_t *, char *, id_t, uint_t,
667c478bd9Sstevel@tonic-gate 			    char **, rcm_info_t **);
677c478bd9Sstevel@tonic-gate static int		cluster_remove(rcm_handle_t *, char *, id_t, uint_t,
687c478bd9Sstevel@tonic-gate 			    char **, rcm_info_t **);
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate static int		cluster_SUNW_os_registered = 0;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate static struct rcm_mod_ops cluster_ops =
737c478bd9Sstevel@tonic-gate {
747c478bd9Sstevel@tonic-gate 	RCM_MOD_OPS_VERSION,
757c478bd9Sstevel@tonic-gate 	cluster_register,
767c478bd9Sstevel@tonic-gate 	cluster_unregister,
777c478bd9Sstevel@tonic-gate 	cluster_getinfo,
787c478bd9Sstevel@tonic-gate 	cluster_suspend,
797c478bd9Sstevel@tonic-gate 	cluster_resume,
807c478bd9Sstevel@tonic-gate 	cluster_offline,
817c478bd9Sstevel@tonic-gate 	cluster_online,
827c478bd9Sstevel@tonic-gate 	cluster_remove,
837c478bd9Sstevel@tonic-gate 	NULL,
847c478bd9Sstevel@tonic-gate 	NULL,
857c478bd9Sstevel@tonic-gate 	NULL
867c478bd9Sstevel@tonic-gate };
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate struct rcm_mod_ops *
rcm_mod_init()897c478bd9Sstevel@tonic-gate rcm_mod_init()
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate 	return (&cluster_ops);
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate const char *
rcm_mod_info()957c478bd9Sstevel@tonic-gate rcm_mod_info()
967c478bd9Sstevel@tonic-gate {
97*648495d6Svikram 	return (gettext("RCM Cluster module 1.3"));
987c478bd9Sstevel@tonic-gate }
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate int
rcm_mod_fini()1017c478bd9Sstevel@tonic-gate rcm_mod_fini()
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate 	return (RCM_SUCCESS);
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate static int
cluster_register(rcm_handle_t * hdl)1077c478bd9Sstevel@tonic-gate cluster_register(rcm_handle_t *hdl)
1087c478bd9Sstevel@tonic-gate {
1097c478bd9Sstevel@tonic-gate 	int bootflags;
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	if (cluster_SUNW_os_registered)
1127c478bd9Sstevel@tonic-gate 		return (RCM_SUCCESS);
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	if (_cladm(CL_INITIALIZE, CL_GET_BOOTFLAG, &bootflags) != 0) {
1157c478bd9Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR,
1167c478bd9Sstevel@tonic-gate 			gettext("unable to check cluster status\n"));
1177c478bd9Sstevel@tonic-gate 		return (RCM_FAILURE);
1187c478bd9Sstevel@tonic-gate 	}
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	/* attempt to determine if we are in cluster mode */
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	if (bootflags & CLUSTER_BOOTED) {
1237c478bd9Sstevel@tonic-gate 		if (rcm_register_interest(hdl, SUNW_OS, 0, NULL) !=
1247c478bd9Sstevel@tonic-gate 		    RCM_SUCCESS) {
1257c478bd9Sstevel@tonic-gate 			rcm_log_message(RCM_ERROR,
1267c478bd9Sstevel@tonic-gate 			    gettext("failed to register\n"));
1277c478bd9Sstevel@tonic-gate 			return (RCM_FAILURE);
1287c478bd9Sstevel@tonic-gate 		} else {
1297c478bd9Sstevel@tonic-gate 			cluster_SUNW_os_registered = 1;
1307c478bd9Sstevel@tonic-gate 			rcm_log_message(RCM_DEBUG, "registered " SUNW_OS
1317c478bd9Sstevel@tonic-gate 					"\n");
1327c478bd9Sstevel@tonic-gate 		}
1337c478bd9Sstevel@tonic-gate 	}
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	return (RCM_SUCCESS);
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate static int
cluster_unregister(rcm_handle_t * hdl)1397c478bd9Sstevel@tonic-gate cluster_unregister(rcm_handle_t *hdl)
1407c478bd9Sstevel@tonic-gate {
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	if (cluster_SUNW_os_registered) {
1437c478bd9Sstevel@tonic-gate 		if (rcm_unregister_interest(hdl, SUNW_OS, 0) !=
1447c478bd9Sstevel@tonic-gate 		    RCM_SUCCESS) {
1457c478bd9Sstevel@tonic-gate 			rcm_log_message(RCM_ERROR,
1467c478bd9Sstevel@tonic-gate 			    gettext("failed to unregister"));
1477c478bd9Sstevel@tonic-gate 		}
1487c478bd9Sstevel@tonic-gate 		cluster_SUNW_os_registered = 0;
1497c478bd9Sstevel@tonic-gate 	}
1507c478bd9Sstevel@tonic-gate 	return (RCM_SUCCESS);
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1547c478bd9Sstevel@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)1557c478bd9Sstevel@tonic-gate cluster_getinfo(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
1567c478bd9Sstevel@tonic-gate     char **infostr, char **errstr, nvlist_t *props, rcm_info_t **dependent)
1577c478bd9Sstevel@tonic-gate {
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	assert(rsrcname != NULL && infostr != NULL);
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	if ((*infostr = strdup(OS_USAGE)) == NULL)
1627c478bd9Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	return (RCM_SUCCESS);
1657c478bd9Sstevel@tonic-gate }
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1687c478bd9Sstevel@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)1697c478bd9Sstevel@tonic-gate cluster_suspend(rcm_handle_t *hdl, char *rsrcname, id_t id,
1707c478bd9Sstevel@tonic-gate     timespec_t *interval, uint_t flags, char **errstr,
1717c478bd9Sstevel@tonic-gate     rcm_info_t **dependent)
1727c478bd9Sstevel@tonic-gate {
1737c478bd9Sstevel@tonic-gate 	if ((*errstr = strdup(OS_SUSPEND_ERR)) == NULL)
1747c478bd9Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	return (RCM_FAILURE);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1807c478bd9Sstevel@tonic-gate static int
cluster_resume(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)1817c478bd9Sstevel@tonic-gate cluster_resume(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
1827c478bd9Sstevel@tonic-gate     char **errstr, rcm_info_t **dependent)
1837c478bd9Sstevel@tonic-gate {
1847c478bd9Sstevel@tonic-gate 	return (RCM_SUCCESS);
1857c478bd9Sstevel@tonic-gate }
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate  * By default, reject offline. If offline request is
1897c478bd9Sstevel@tonic-gate  * forced, attempt to relocate the cluster device.
1907c478bd9Sstevel@tonic-gate  */
1917c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1927c478bd9Sstevel@tonic-gate static int
cluster_offline(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)1937c478bd9Sstevel@tonic-gate cluster_offline(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
1947c478bd9Sstevel@tonic-gate     char **errstr, rcm_info_t **dependent)
1957c478bd9Sstevel@tonic-gate {
1967c478bd9Sstevel@tonic-gate 	if ((*errstr = strdup(OS_OFFLINE_ERR)) == NULL)
1977c478bd9Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	return (RCM_FAILURE);
2007c478bd9Sstevel@tonic-gate }
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2037c478bd9Sstevel@tonic-gate static int
cluster_online(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)2047c478bd9Sstevel@tonic-gate cluster_online(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
2057c478bd9Sstevel@tonic-gate     char  **errstr, rcm_info_t **dependent)
2067c478bd9Sstevel@tonic-gate {
2077c478bd9Sstevel@tonic-gate 	return (RCM_SUCCESS);
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2117c478bd9Sstevel@tonic-gate static int
cluster_remove(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)2127c478bd9Sstevel@tonic-gate cluster_remove(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
2137c478bd9Sstevel@tonic-gate     char **errstr, rcm_info_t **dependent)
2147c478bd9Sstevel@tonic-gate {
2157c478bd9Sstevel@tonic-gate 	if ((*errstr = strdup(OS_REMOVE_ERR)) == NULL)
2167c478bd9Sstevel@tonic-gate 		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	return (RCM_FAILURE);
2197c478bd9Sstevel@tonic-gate }
220