fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <locale.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libgen.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/cfg.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ncall/ncall.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic CFGFILE *cfg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int cfg_changed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *progname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic ncall_node_t *getnodelist(int, int *, int *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteusage(int exitstat)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("usage:\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(" %s -d\n"), progname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(" %s -e\n"), progname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(" %s -h\n"), progname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(" %s -c [nodeid <nodeid>]\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(" %s -i\n"), progname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(" %s -p <host>\n"), progname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("where:\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(" -d disable ncall\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(" -e enable ncall core\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(" -h this help message\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext(" -c set or print ncall configuration\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(" -i ncall information\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(" -p ncall ping <host>\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(exitstat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortencall_cfg_open(CFGLOCK lk)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char hostid[32];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (snprintf(hostid, sizeof (hostid), "%lx", gethostid()) >=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (hostid)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("%s: hostid %lx too large\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname, gethostid());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cfg = cfg_open(NULL)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to access the configuration: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname, cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cfg_lock(cfg, lk)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to lock the configuration: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname, cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_resource(cfg, hostid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortencall_cfg_close(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_changed && cfg_commit(cfg) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to update the configuration: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname, cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get config from dscfg.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_nodeid_from_cfg(int *nodeid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_cfg_open(CFG_RDLOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_cstring(cfg, "ncallcore.set1", buf, sizeof (buf)) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = sscanf(buf, "%d", nodeid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_cfg_close();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortencall_print(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cfnodeid, clnodeid, rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clnodeid = cfg_issuncluster();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = get_nodeid_from_cfg(&cfnodeid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0 && clnodeid > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("%s: ncall is using the SunCluster "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "nodeid: %d\n"), progname, clnodeid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("%s: ncall is using the default "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "nodeid: %d\n"), progname, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("%s: current configuration:\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* deliberately not i18n'd - "nodeid" is a keyword */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("nodeid %d\n", cfnodeid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortencall_config(const int nodeid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_cfg_open(CFG_WRLOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_cstring(cfg, "ncallcore.set1", buf, sizeof (buf)) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove old config */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, "ncallcore.set1", NULL, 0) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to update the configuration: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s\n"), cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (snprintf(buf, sizeof (buf), "%d", nodeid) >= sizeof (buf)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to update configuration: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "data too long\n"), progname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, "ncallcore", buf, sizeof (buf)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to update the configuration: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_error(NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_changed = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_cfg_close();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("%s: configuration set to:\n"), progname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* deliberately not i18n'd - "nodeid" is a keyword */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("nodeid %d\n", nodeid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef lint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortencalladm_lintmain(int argc, char *argv[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemain(int argc, char *argv[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *dev = "/dev/ncall";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte extern int optind, opterr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_node_t nodeinfo, *nodes;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cflag, dflag, eflag, iflag, pflag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc, fd, opt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int clnodeid, cfnodeid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int up;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *cp, *ping;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int mnode; /* mirror nodeid */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) setlocale(LC_ALL, "");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) textdomain("ncalladm");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte opterr = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cflag = dflag = eflag = iflag = pflag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ping = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname = basename(argv[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((opt = getopt(argc, argv,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cip:"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "deh")) != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (opt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'c':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cflag = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'd':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dflag = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'e':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte eflag = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'h':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'i':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iflag = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'p':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ping = optarg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pflag = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("%s: unknown option\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(cflag || dflag || eflag || iflag || pflag)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (argc != optind) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cflag ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (argc - optind) != 2 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcmp(argv[optind], "nodeid") != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cflag + dflag + eflag + iflag + pflag) > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: multiple options are not supported\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fd = open(dev, O_RDONLY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fd < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to open %s: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname, dev, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ioctl stop into kernel */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, NC_IOC_STOP, 0) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to disable ncall: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (eflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&nodeinfo, sizeof (nodeinfo));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clnodeid = cfg_issuncluster();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfnodeid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get node info */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = gethostname(nodeinfo.nc_nodename,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (nodeinfo.nc_nodename));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to determine hostname: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = get_nodeid_from_cfg(&cfnodeid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (clnodeid > 0 && rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check that the nodeids from the cf file and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cluster match.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (clnodeid != cfnodeid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: nodeid from configuration "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "(%d) != cluster nodeid (%d)\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname, cfnodeid, clnodeid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodeinfo.nc_nodeid = cfnodeid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (clnodeid > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodeinfo.nc_nodeid = clnodeid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodeinfo.nc_nodeid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ioctl node info into kernel and start ncall */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ioctl(fd, NC_IOC_START, &nodeinfo);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to enable ncall: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iflag || pflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodes = getnodelist(fd, &nsize, &mnode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nodes == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to get node info\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *mname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *pnodestr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("Self Node Name: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodes[0].nc_nodename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("Self Node ID: %d\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodes[0].nc_nodeid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * determine which slot is the mirror node.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mnode != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 1; i < nsize; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nodes[i].nc_nodeid == mnode) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mname = nodes[i].nc_nodename;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((mnode == -1) || (i >= nsize)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mname = gettext("unknown");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mnode = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("Mirror Node Name: %s\n"), mname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("Mirror Node ID: %d\n"), mnode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See if we need to translate the node strings.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nsize > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pnodestr = gettext("Node Name: %s\nNode ID: %d\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 1; i < nsize; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Don't print the mirror twice.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nodes[i].nc_nodeid != mnode) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(pnodestr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodes[i].nc_nodename,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodes[i].nc_nodeid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strlen(ping) >= sizeof (nodeinfo.nc_nodename)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: hostname '%s' is too long\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname, ping);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte up = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(nodes[0].nc_nodename, ping) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte up = 1; /* self */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* not self, so ask kernel */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&nodeinfo, sizeof (nodeinfo));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* strlen(ping) checked above */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(nodeinfo.nc_nodename, ping);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte up = ioctl(fd, NC_IOC_PING, nodeinfo);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* model the ping messages on ping(1m) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (up < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to ping host '%s': %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname, ping, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (up > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("%s is alive\n"), ping);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("no answer from %s\n"), ping);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iflag || pflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(nodes);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (argc == optind) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_print();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfnodeid = (int)strtol(argv[optind+1], &cp, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cp != NULL && *cp != '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: nodeid \"%s\" is not an "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "integer number\n"), progname, argv[optind+1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clnodeid = cfg_issuncluster();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (clnodeid > 0 && cfnodeid != clnodeid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: nodeid from command line "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "(%d) != cluster nodeid (%d)\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte progname, cfnodeid, clnodeid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_config(cfnodeid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return a pointer to a list of currently configured
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nodes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return the number of nodes via the nodesizep pointer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return the mirror nodeid via the mirrorp pointer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return NULL on errors.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic ncall_node_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegetnodelist(int ifd, int *nodesizep, int *mirrorp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int maxsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_node_t *noderet = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_node_t *nodelist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ncall_node_t thisnode;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int mirror;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nonet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get this host info and mirror nodeid.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mirror = ioctl(ifd, NC_IOC_GETNODE, &thisnode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mirror < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See if we need to allocate the buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nonet = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxsize = ioctl(ifd, NC_IOC_GETNETNODES, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (maxsize < 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxsize = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nonet = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nodelist = malloc(sizeof (*nodelist) * maxsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nodelist) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nonet == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fetch the node data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnt = ioctl(ifd, NC_IOC_GETNETNODES, nodelist);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cnt > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *nodesizep = cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte noderet = nodelist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *mirrorp = mirror;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *nodesizep = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(nodelist);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memcpy(nodelist, &thisnode, sizeof (*nodelist));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *nodesizep = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte noderet = nodelist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Although we know the mirror nodeid, there
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is no point in returning it as we have
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no information about any other hosts.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *mirrorp = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (noderet);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}