xref: /titanic_50/usr/src/uts/common/syscall/cladm.c (revision e5dcf7beb7c949f9234713d5818b581ec3825443)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1998 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/systm.h>
30 #include <sys/errno.h>
31 #include <sys/cladm.h>
32 
33 /*
34  * cladm(2) cluster administation system call.
35  */
36 int
37 cladm(int fac, int cmd, void *arg)
38 {
39 	int error = 0;
40 	int copyout_bootflags;
41 
42 	switch (fac) {
43 	case CL_INITIALIZE:
44 		if (cmd != CL_GET_BOOTFLAG) {
45 			error = EINVAL;
46 			break;
47 		}
48 
49 		/*
50 		 * The CLUSTER_INSTALLING and CLUSTER_DCS_ENABLED bootflags are
51 		 * internal flags. We do not want to expose these to the user
52 		 * level.
53 		 */
54 		copyout_bootflags = (cluster_bootflags &
55 		    ~(CLUSTER_INSTALLING | CLUSTER_DCS_ENABLED));
56 		if (copyout(&copyout_bootflags, arg, sizeof (int))) {
57 			error = EFAULT;
58 		}
59 		break;
60 
61 	case CL_CONFIG:
62 		/*
63 		 * We handle CL_NODEID here so that the node number
64 		 * can be returned if the system is configured as part
65 		 * of a cluster but not booted as part of the cluster.
66 		 */
67 		if (cmd == CL_NODEID) {
68 			nodeid_t nid;
69 
70 			/* return error if not configured as a cluster */
71 			if (!(cluster_bootflags & CLUSTER_CONFIGURED)) {
72 				error = ENOSYS;
73 				break;
74 			}
75 
76 			nid = clconf_get_nodeid();
77 			error = copyout(&nid, arg, sizeof (nid));
78 			break;
79 		}
80 		/* FALLTHROUGH */
81 
82 	default:
83 		if ((cluster_bootflags & (CLUSTER_CONFIGURED|CLUSTER_BOOTED)) !=
84 		    (CLUSTER_CONFIGURED|CLUSTER_BOOTED)) {
85 			error = EINVAL;
86 			break;
87 		}
88 		error = cladmin(fac, cmd, arg);
89 		/*
90 		 * error will be -1 if the cladm module cannot be loaded;
91 		 * otherwise, it is the errno value returned
92 		 * (see {i86,sparc}/ml/modstubs.s).
93 		 */
94 		if (error < 0)
95 			error = ENOSYS;
96 		break;
97 	}
98 
99 	return (error ? set_errno(error) : 0);
100 }
101