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/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This file contains the glue code that allows the NWS software to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * determine whether a cluster disk service is local to this node or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See PSARC/1999/462 for more information on the interfaces from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * suncluster that are used here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/wait.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/mkdev.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <dlfcn.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ncall/ncall.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsc_hash.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "cfg_cluster.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "cfg_impl.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "cfg.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Static variables
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic scconf_nodeid_t cl_nodeid = (uint_t)0xffff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *cl_nodename = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void *libscstat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void *libscconf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic hash_node_t **schash;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int init_sc_entry();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct hash_data_s {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scstat_node_name_t scstat_node_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} hash_data_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Global variables
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint cl_initialized = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Tell the linker to keep quiet.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#pragma weak scconf_get_nodename
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#pragma weak scconf_strerr
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#pragma weak scconf_get_ds_by_devt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#pragma weak scstat_get_ds_status
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#pragma weak scstat_free_ds_status
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#pragma weak scstat_strerr
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialise the library if we have not done so before.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - IMPORTANT -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This must -never- be called from any command that can be started
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from /usr/cluster/lib/sc/run_reserve (and hence
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /usr/cluster/sbin/reconfig) or the system will deadlock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * during switchover. This includes:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - svadm (no options, "print") -- called during sv switchover
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - all boot commands
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - grab this node's cluster nodeid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - attempt to dlopen() the suncluster shared libraries we need
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - grab this node's cluster nodename
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1 - error, errno is set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecfg_cluster_init(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *scconf = "/usr/cluster/lib/libscconf.so.1";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *scstat = "/usr/cluster/lib/libscstat.so.1";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char errbuf[SCCONF_MAXSTRINGLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scconf_nodeid_t id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scconf_errno_t err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FILE *pipe;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First check to see if we really are a cluster as clinfo -n can lie
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl_nodeid == 0xffff) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = system("/usr/sbin/clinfo");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != -1 && WEXITSTATUS(rc) == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* not a cluster */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl_initialized = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl_nodeid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pipe = popen("/usr/sbin/clinfo -n 2>/dev/null || echo 0", "r");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pipe == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "unable to get nodeid: %s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = fscanf(pipe, "%d", &id)) != 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "unable to get nodeid: %s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pclose(pipe);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl_nodeid = id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Already loaded the Sun Cluster device tree */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl_initialized)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Try and dlopen the various libraries that we need
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte libscconf = dlopen(scconf, RTLD_LAZY | RTLD_GLOBAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (libscconf == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto error;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte libscstat = dlopen(scstat, RTLD_LAZY | RTLD_GLOBAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (libscstat == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto error;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = scconf_get_nodename(id, &name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err == SCCONF_EPERM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl_nodename = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (err != SCCONF_NOERR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scconf_strerr(errbuf, err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "scconf_get_nodename: %d: %s\n", err, errbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto error;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl_nodename = name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Load the Sun Cluster device tree */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte init_sc_entry();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl_initialized = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteerror: /* error cleanup */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (libscconf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlclose(libscconf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (libscstat)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dlclose(libscstat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte libscconf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte libscstat = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = ENOSYS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cfg_issuncluster()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return the SunCluster nodeid of this node.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * >0 - running in a SunCluster (value is nodeid of this node)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - not running in a cluster
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1 - failure; errno is set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecfg_issuncluster()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_cluster_init() >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((int)cl_nodeid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecfg_iscluster()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cfg_issuncluster());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cfg_l_dgname_islocal()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check if disk group is local on a non-SunCluster.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns as cfg_dgname_islocal().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef lint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecfg_l_dgname_islocal(char *dgname, char **othernode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *metaset = "/usr/sbin/metaset -s %s -o > /dev/null 2>&1";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char command[1024];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (snprintf(command, sizeof (command), metaset, dgname) >=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (command)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = system(command);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (WEXITSTATUS(rc) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (othernode) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* metaset doesn't tell us */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *othernode = "unknown";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cfg_dgname_islocal(char *dgname, char **othernode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -- determine if the named disk service is mastered on this node
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the disk service is mastered on another node, that nodename
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will be returned in othernode (if not NULL). It is up to the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * calling program to call free() on this value at a later time to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free the memory allocated.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 - disk service is mastered on this node
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - disk service is not mastered on this node (*othernode set)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1 - error (errno will be set)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecfg_dgname_islocal(char *dgname, char **othernode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hash_data_t *data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dgname == NULL || *dgname == '\0' || othernode == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Handle non-cluster configurations */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_cluster_init() < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (cl_nodeid == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* it has to be local */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lookup the current diskgroup name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (data = (hash_data_t *)nsc_lookup(schash, dgname)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(data->scstat_node_name, cl_nodename)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (othernode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *othernode = strdup(data->scstat_node_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = ENODEV;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cfg_l_dgname()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parse the disk group name from the a device pathname on a non-SunCluster.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns as cfg_dgname().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecfg_l_dgname(const char *pathname, char *buffer, size_t buflen)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *dev = "/dev/";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *vx = "vx/";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *md = "md/";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *dsk = "dsk/";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *start, *cp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ll, len, chkdsk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(buffer, buflen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chkdsk = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ll = strlen(dev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(pathname, dev, ll) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* not a device pathname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start = pathname + ll;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(start, md, (ll = strlen(md))) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SVM --
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /dev/md/dgname/{r}dsk/partition
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start += ll;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(start, dsk, strlen(dsk)) == 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*start == 'r' &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncmp((start + 1), dsk, strlen(dsk)) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no dgname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (buffer);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chkdsk = 1; /* check for trailing {r}dsk */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strncmp(start, vx, (ll = strlen(vx))) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Veritas --
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /dev/vx/{r}dsk/dgname/partition
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start += ll;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ll = strlen(dsk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*start == 'r' && strncmp((start + 1), dsk, ll) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start += ll + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (strncmp(start, dsk, ll) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start += ll;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no dgname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (buffer);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no dgname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (buffer);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cp = start, len = 0; *cp != '\0' && *cp != '/'; cp++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len++; /* count length of dgname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*cp == '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no dgname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (buffer);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*cp != '/') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cfg_dgname: parse error: *cp = '%c', expected '/'\n", *cp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = EPROTO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (chkdsk) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cp++; /* skip the NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ll = strlen(dsk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*cp != 'r' || strncmp((cp + 1), dsk, ll) != 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncmp(cp, dsk, ll) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no dgname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (buffer);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len >= buflen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = E2BIG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(buffer, start, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (buffer);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cfg_dgname()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * determine which cluster resource group the pathname belongs to, if any
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NULL - error (errno is set)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ptr to NULL-string - no dgname
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pointer to string - dgname
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecfg_dgname(const char *pathname, char *buffer, size_t buflen)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scconf_errno_t conferr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *dsname = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat stb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char errbuf[SCCONF_MAXSTRINGLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(buffer, buflen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pathname == NULL || *pathname == '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Handle non-cluster configurations */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_cluster_init() < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (cl_nodeid == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* must be local - return NULL-string dgname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (buffer);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(pathname, &stb) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte conferr = scconf_get_ds_by_devt(major(stb.st_rdev),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minor(stb.st_rdev), &dsname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (conferr == SCCONF_ENOEXIST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (buffer);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (conferr != SCCONF_NOERR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scconf_strerr(errbuf, conferr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "scconf_get_ds_by_devt: %d: %s\n", conferr, errbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(buffer, dsname, buflen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(dsname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (buffer);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * init_sc_entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add an entry into the sclist and the schash for future lookups.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - IMPORTANT -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This must -never- be called from any command that can be started
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * from /usr/cluster/lib/sc/run_reserve (and hence
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /usr/cluster/sbin/reconfig) or the system will deadlock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * during switchover. This includes:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - svadm (no options, "print") -- called during sv switchover
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - all boot commands
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return values:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1 An error occurred.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 Entry added
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 Entry already exists.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteinit_sc_entry()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scstat_ds_node_state_t *dsn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scstat_ds_name_t dsname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scstat_ds_t *dsstatus, *dsp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scstat_errno_t err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char errbuf[SCCONF_MAXSTRINGLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hash_data_t *hdp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate a hash table
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((schash = nsc_create_hash()) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the API is broken here - the function is written to expect
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the first argument to be (scstat_ds_name_t), but the function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * declaration in scstat.h requires (scstat_ds_name_t *).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We just cast it to get rid of the compiler warnings.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If "dsname" is NULL, information for all device services is returned
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dsstatus = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dsname = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = scstat_get_ds_status((scstat_ds_name_t *)dsname, &dsstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err != SCSTAT_ENOERR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scstat_strerr(err, errbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "scstat_get_ds_status(): %d: %s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err, errbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = ENOSYS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dsstatus == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = ENODEV;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Traverse scstat_ds list, saving away resource in out hash table
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (dsp = dsstatus; dsp; dsp = dsp->scstat_ds_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Skip over NULL scstat_ds_name's */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dsp->scstat_ds_name == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (dsp->scstat_ds_name[0] == '\0'))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* See element exits already, error if so */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nsc_lookup(schash, dsp->scstat_ds_name)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "scstat_get_ds_status: duplicate %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dsp->scstat_ds_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = EEXIST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Traverse the node status list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (dsn = dsp->scstat_node_state_list; dsn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dsn = dsn->scstat_node_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Only keep trace of primary nodes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dsn->scstat_node_state != SCSTAT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create an element to insert */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hdp = (hash_data_t *)malloc(sizeof (hash_data_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hdp->scstat_node_name = strdup(dsn->scstat_node_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_insert_node(schash, hdp, dsp->scstat_ds_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free up scstat resources
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scstat_free_ds_status(dsstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}