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 /*
277c478bd9Sstevel@tonic-gate * RCM module for managing the OS Quiesce event (SUNW_OS) in a
287c478bd9Sstevel@tonic-gate * clustered environment.
297c478bd9Sstevel@tonic-gate */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #include <stdlib.h>
327c478bd9Sstevel@tonic-gate #include <unistd.h>
337c478bd9Sstevel@tonic-gate #include <fcntl.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate #include <thread.h>
367c478bd9Sstevel@tonic-gate #include <synch.h>
377c478bd9Sstevel@tonic-gate #include <assert.h>
387c478bd9Sstevel@tonic-gate #include <errno.h>
397c478bd9Sstevel@tonic-gate #include <libintl.h>
407c478bd9Sstevel@tonic-gate #include <sys/param.h>
417c478bd9Sstevel@tonic-gate #include <sys/wait.h>
427c478bd9Sstevel@tonic-gate #include <sys/types.h>
437c478bd9Sstevel@tonic-gate #include <sys/stat.h>
447c478bd9Sstevel@tonic-gate #include <sys/cladm.h>
457c478bd9Sstevel@tonic-gate #include "rcm_module.h"
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate #define SUNW_OS "SUNW_OS"
487c478bd9Sstevel@tonic-gate #define OS_USAGE gettext("Sun Cluster")
497c478bd9Sstevel@tonic-gate #define OS_SUSPEND_ERR gettext("OS cannot be quiesced on clustered nodes")
507c478bd9Sstevel@tonic-gate #define OS_OFFLINE_ERR gettext("Invalid operation: OS cannot be offlined")
517c478bd9Sstevel@tonic-gate #define OS_REMOVE_ERR gettext("Invalid operation: OS cannot be removed")
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate static int cluster_register(rcm_handle_t *);
547c478bd9Sstevel@tonic-gate static int cluster_unregister(rcm_handle_t *);
557c478bd9Sstevel@tonic-gate static int cluster_getinfo(rcm_handle_t *, char *, id_t, uint_t,
567c478bd9Sstevel@tonic-gate char **, char **, nvlist_t *, rcm_info_t **);
577c478bd9Sstevel@tonic-gate static int cluster_suspend(rcm_handle_t *, char *, id_t,
587c478bd9Sstevel@tonic-gate timespec_t *, uint_t, char **, rcm_info_t **);
597c478bd9Sstevel@tonic-gate static int cluster_resume(rcm_handle_t *, char *, id_t, uint_t,
607c478bd9Sstevel@tonic-gate char **, rcm_info_t **);
617c478bd9Sstevel@tonic-gate static int cluster_offline(rcm_handle_t *, char *, id_t, uint_t,
627c478bd9Sstevel@tonic-gate char **, rcm_info_t **);
637c478bd9Sstevel@tonic-gate static int cluster_online(rcm_handle_t *, char *, id_t, uint_t,
647c478bd9Sstevel@tonic-gate char **, rcm_info_t **);
657c478bd9Sstevel@tonic-gate static int cluster_remove(rcm_handle_t *, char *, id_t, uint_t,
667c478bd9Sstevel@tonic-gate char **, rcm_info_t **);
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate static int cluster_SUNW_os_registered = 0;
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate static struct rcm_mod_ops cluster_ops =
717c478bd9Sstevel@tonic-gate {
727c478bd9Sstevel@tonic-gate RCM_MOD_OPS_VERSION,
737c478bd9Sstevel@tonic-gate cluster_register,
747c478bd9Sstevel@tonic-gate cluster_unregister,
757c478bd9Sstevel@tonic-gate cluster_getinfo,
767c478bd9Sstevel@tonic-gate cluster_suspend,
777c478bd9Sstevel@tonic-gate cluster_resume,
787c478bd9Sstevel@tonic-gate cluster_offline,
797c478bd9Sstevel@tonic-gate cluster_online,
807c478bd9Sstevel@tonic-gate cluster_remove,
817c478bd9Sstevel@tonic-gate NULL,
827c478bd9Sstevel@tonic-gate NULL,
837c478bd9Sstevel@tonic-gate NULL
847c478bd9Sstevel@tonic-gate };
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate struct rcm_mod_ops *
rcm_mod_init()877c478bd9Sstevel@tonic-gate rcm_mod_init()
887c478bd9Sstevel@tonic-gate {
897c478bd9Sstevel@tonic-gate return (&cluster_ops);
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate const char *
rcm_mod_info()937c478bd9Sstevel@tonic-gate rcm_mod_info()
947c478bd9Sstevel@tonic-gate {
95*648495d6Svikram return (gettext("RCM Cluster module 1.3"));
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate int
rcm_mod_fini()997c478bd9Sstevel@tonic-gate rcm_mod_fini()
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate return (RCM_SUCCESS);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate static int
cluster_register(rcm_handle_t * hdl)1057c478bd9Sstevel@tonic-gate cluster_register(rcm_handle_t *hdl)
1067c478bd9Sstevel@tonic-gate {
1077c478bd9Sstevel@tonic-gate int bootflags;
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate if (cluster_SUNW_os_registered)
1107c478bd9Sstevel@tonic-gate return (RCM_SUCCESS);
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate if (_cladm(CL_INITIALIZE, CL_GET_BOOTFLAG, &bootflags) != 0) {
1137c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
1147c478bd9Sstevel@tonic-gate gettext("unable to check cluster status\n"));
1157c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate /* attempt to determine if we are in cluster mode */
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate if (bootflags & CLUSTER_BOOTED) {
1217c478bd9Sstevel@tonic-gate if (rcm_register_interest(hdl, SUNW_OS, 0, NULL) !=
1227c478bd9Sstevel@tonic-gate RCM_SUCCESS) {
1237c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
1247c478bd9Sstevel@tonic-gate gettext("failed to register\n"));
1257c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
1267c478bd9Sstevel@tonic-gate } else {
1277c478bd9Sstevel@tonic-gate cluster_SUNW_os_registered = 1;
1287c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG, "registered " SUNW_OS
1297c478bd9Sstevel@tonic-gate "\n");
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate return (RCM_SUCCESS);
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate static int
cluster_unregister(rcm_handle_t * hdl)1377c478bd9Sstevel@tonic-gate cluster_unregister(rcm_handle_t *hdl)
1387c478bd9Sstevel@tonic-gate {
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate if (cluster_SUNW_os_registered) {
1417c478bd9Sstevel@tonic-gate if (rcm_unregister_interest(hdl, SUNW_OS, 0) !=
1427c478bd9Sstevel@tonic-gate RCM_SUCCESS) {
1437c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
1447c478bd9Sstevel@tonic-gate gettext("failed to unregister"));
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate cluster_SUNW_os_registered = 0;
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate return (RCM_SUCCESS);
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1527c478bd9Sstevel@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)1537c478bd9Sstevel@tonic-gate cluster_getinfo(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
1547c478bd9Sstevel@tonic-gate char **infostr, char **errstr, nvlist_t *props, rcm_info_t **dependent)
1557c478bd9Sstevel@tonic-gate {
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate assert(rsrcname != NULL && infostr != NULL);
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate if ((*infostr = strdup(OS_USAGE)) == NULL)
1607c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate return (RCM_SUCCESS);
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1667c478bd9Sstevel@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)1677c478bd9Sstevel@tonic-gate cluster_suspend(rcm_handle_t *hdl, char *rsrcname, id_t id,
1687c478bd9Sstevel@tonic-gate timespec_t *interval, uint_t flags, char **errstr,
1697c478bd9Sstevel@tonic-gate rcm_info_t **dependent)
1707c478bd9Sstevel@tonic-gate {
1717c478bd9Sstevel@tonic-gate if ((*errstr = strdup(OS_SUSPEND_ERR)) == NULL)
1727c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1787c478bd9Sstevel@tonic-gate static int
cluster_resume(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)1797c478bd9Sstevel@tonic-gate cluster_resume(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
1807c478bd9Sstevel@tonic-gate char **errstr, rcm_info_t **dependent)
1817c478bd9Sstevel@tonic-gate {
1827c478bd9Sstevel@tonic-gate return (RCM_SUCCESS);
1837c478bd9Sstevel@tonic-gate }
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate /*
1867c478bd9Sstevel@tonic-gate * By default, reject offline. If offline request is
1877c478bd9Sstevel@tonic-gate * forced, attempt to relocate the cluster device.
1887c478bd9Sstevel@tonic-gate */
1897c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1907c478bd9Sstevel@tonic-gate static int
cluster_offline(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)1917c478bd9Sstevel@tonic-gate cluster_offline(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
1927c478bd9Sstevel@tonic-gate char **errstr, rcm_info_t **dependent)
1937c478bd9Sstevel@tonic-gate {
1947c478bd9Sstevel@tonic-gate if ((*errstr = strdup(OS_OFFLINE_ERR)) == NULL)
1957c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2017c478bd9Sstevel@tonic-gate static int
cluster_online(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)2027c478bd9Sstevel@tonic-gate cluster_online(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
2037c478bd9Sstevel@tonic-gate char **errstr, rcm_info_t **dependent)
2047c478bd9Sstevel@tonic-gate {
2057c478bd9Sstevel@tonic-gate return (RCM_SUCCESS);
2067c478bd9Sstevel@tonic-gate }
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2097c478bd9Sstevel@tonic-gate static int
cluster_remove(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)2107c478bd9Sstevel@tonic-gate cluster_remove(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
2117c478bd9Sstevel@tonic-gate char **errstr, rcm_info_t **dependent)
2127c478bd9Sstevel@tonic-gate {
2137c478bd9Sstevel@tonic-gate if ((*errstr = strdup(OS_REMOVE_ERR)) == NULL)
2147c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
2177c478bd9Sstevel@tonic-gate }
218