27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
237c478bdstevel@tonic-gate * Copyright (c) 1998 by Sun Microsystems, Inc.
247c478bdstevel@tonic-gate * All rights reserved.
257c478bdstevel@tonic-gate */
277c478bdstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
297c478bdstevel@tonic-gate#include <sys/systm.h>
307c478bdstevel@tonic-gate#include <sys/errno.h>
317c478bdstevel@tonic-gate#include <sys/cladm.h>
347c478bdstevel@tonic-gate * cladm(2) cluster administation system call.
357c478bdstevel@tonic-gate */
377c478bdstevel@tonic-gatecladm(int fac, int cmd, void *arg)
397c478bdstevel@tonic-gate	int error = 0;
407c478bdstevel@tonic-gate	int copyout_bootflags;
427c478bdstevel@tonic-gate	switch (fac) {
437c478bdstevel@tonic-gate	case CL_INITIALIZE:
447c478bdstevel@tonic-gate		if (cmd != CL_GET_BOOTFLAG) {
457c478bdstevel@tonic-gate			error = EINVAL;
467c478bdstevel@tonic-gate			break;
477c478bdstevel@tonic-gate		}
497c478bdstevel@tonic-gate		/*
507c478bdstevel@tonic-gate		 * The CLUSTER_INSTALLING and CLUSTER_DCS_ENABLED bootflags are
517c478bdstevel@tonic-gate		 * internal flags. We do not want to expose these to the user
527c478bdstevel@tonic-gate		 * level.
537c478bdstevel@tonic-gate		 */
547c478bdstevel@tonic-gate		copyout_bootflags = (cluster_bootflags &
557c478bdstevel@tonic-gate		    ~(CLUSTER_INSTALLING | CLUSTER_DCS_ENABLED));
567c478bdstevel@tonic-gate		if (copyout(&copyout_bootflags, arg, sizeof (int))) {
577c478bdstevel@tonic-gate			error = EFAULT;
587c478bdstevel@tonic-gate		}
597c478bdstevel@tonic-gate		break;
617c478bdstevel@tonic-gate	case CL_CONFIG:
627c478bdstevel@tonic-gate		/*
637c478bdstevel@tonic-gate		 * We handle CL_NODEID here so that the node number
647c478bdstevel@tonic-gate		 * can be returned if the system is configured as part
657c478bdstevel@tonic-gate		 * of a cluster but not booted as part of the cluster.
667c478bdstevel@tonic-gate		 */
677c478bdstevel@tonic-gate		if (cmd == CL_NODEID) {
687c478bdstevel@tonic-gate			nodeid_t nid;
707c478bdstevel@tonic-gate			/* return error if not configured as a cluster */
717c478bdstevel@tonic-gate			if (!(cluster_bootflags & CLUSTER_CONFIGURED)) {
727c478bdstevel@tonic-gate				error = ENOSYS;
737c478bdstevel@tonic-gate				break;
747c478bdstevel@tonic-gate			}
767c478bdstevel@tonic-gate			nid = clconf_get_nodeid();
777c478bdstevel@tonic-gate			error = copyout(&nid, arg, sizeof (nid));
787c478bdstevel@tonic-gate			break;
797c478bdstevel@tonic-gate		}
807c478bdstevel@tonic-gate		/* FALLTHROUGH */
827c478bdstevel@tonic-gate	default:
837c478bdstevel@tonic-gate		if ((cluster_bootflags & (CLUSTER_CONFIGURED|CLUSTER_BOOTED)) !=
847c478bdstevel@tonic-gate		    (CLUSTER_CONFIGURED|CLUSTER_BOOTED)) {
857c478bdstevel@tonic-gate			error = EINVAL;
867c478bdstevel@tonic-gate			break;
877c478bdstevel@tonic-gate		}
887c478bdstevel@tonic-gate		error = cladmin(fac, cmd, arg);
897c478bdstevel@tonic-gate		/*
907c478bdstevel@tonic-gate		 * error will be -1 if the cladm module cannot be loaded;
917c478bdstevel@tonic-gate		 * otherwise, it is the errno value returned
927c478bdstevel@tonic-gate		 * (see {i86,sparc}/ml/modstubs.s).
937c478bdstevel@tonic-gate		 */
947c478bdstevel@tonic-gate		if (error < 0)
957c478bdstevel@tonic-gate			error = ENOSYS;
967c478bdstevel@tonic-gate		break;
977c478bdstevel@tonic-gate	}
997c478bdstevel@tonic-gate	return (error ? set_errno(error) : 0);