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