xref: /illumos-gate/usr/src/uts/common/syscall/cladm.c (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
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 #include <sys/systm.h>
28 #include <sys/errno.h>
29 #include <sys/cladm.h>
30 
31 /*
32  * cladm(2) cluster administation system call.
33  */
34 int
35 cladm(int fac, int cmd, void *arg)
36 {
37 	int error = 0;
38 	int copyout_bootflags;
39 
40 	switch (fac) {
41 	case CL_INITIALIZE:
42 		if (cmd != CL_GET_BOOTFLAG) {
43 			error = EINVAL;
44 			break;
45 		}
46 
47 		/*
48 		 * The CLUSTER_INSTALLING and CLUSTER_DCS_ENABLED bootflags are
49 		 * internal flags. We do not want to expose these to the user
50 		 * level.
51 		 */
52 		copyout_bootflags = (cluster_bootflags &
53 		    ~(CLUSTER_INSTALLING | CLUSTER_DCS_ENABLED));
54 		if (copyout(&copyout_bootflags, arg, sizeof (int))) {
55 			error = EFAULT;
56 		}
57 		break;
58 
59 	case CL_CONFIG:
60 		/*
61 		 * We handle CL_NODEID here so that the node number
62 		 * can be returned if the system is configured as part
63 		 * of a cluster but not booted as part of the cluster.
64 		 */
65 		if (cmd == CL_NODEID) {
66 			nodeid_t nid;
67 
68 			/* return error if not configured as a cluster */
69 			if (!(cluster_bootflags & CLUSTER_CONFIGURED)) {
70 				error = ENOSYS;
71 				break;
72 			}
73 
74 			nid = clconf_get_nodeid();
75 			error = copyout(&nid, arg, sizeof (nid));
76 			break;
77 		}
78 		/* FALLTHROUGH */
79 
80 	default:
81 		if ((cluster_bootflags & (CLUSTER_CONFIGURED|CLUSTER_BOOTED)) !=
82 		    (CLUSTER_CONFIGURED|CLUSTER_BOOTED)) {
83 			error = EINVAL;
84 			break;
85 		}
86 		error = cladmin(fac, cmd, arg);
87 		/*
88 		 * error will be -1 if the cladm module cannot be loaded;
89 		 * otherwise, it is the errno value returned
90 		 * (see {i86,sparc}/ml/modstubs.S).
91 		 */
92 		if (error < 0)
93 			error = ENOSYS;
94 		break;
95 	}
96 
97 	return (error ? set_errno(error) : 0);
98 }
99