fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
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 * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
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 * See PSARC/1999/462 for more information on the interfaces from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * suncluster that are used here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Static variables
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic scconf_nodeid_t cl_nodeid = (uint_t)0xffff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Global variables
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Tell the linker to keep quiet.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialise the library if we have not done so before.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - IMPORTANT -
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 * - svadm (no options, "print") -- called during sv switchover
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - all boot commands
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 * 0 - success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1 - error, errno is set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *scconf = "/usr/cluster/lib/libscconf.so.1";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *scstat = "/usr/cluster/lib/libscstat.so.1";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First check to see if we really are a cluster as clinfo -n can lie
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* not a cluster */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pipe = popen("/usr/sbin/clinfo -n 2>/dev/null || echo 0", "r");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Already loaded the Sun Cluster device tree */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Try and dlopen the various libraries that we need
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte libscconf = dlopen(scconf, RTLD_LAZY | RTLD_GLOBAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte libscstat = dlopen(scstat, RTLD_LAZY | RTLD_GLOBAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "scconf_get_nodename: %d: %s\n", err, errbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Load the Sun Cluster device tree */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cfg_issuncluster()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return the SunCluster nodeid of this node.
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 return ((int)cl_nodeid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cfg_l_dgname_islocal()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check if disk group is local on a non-SunCluster.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns as cfg_dgname_islocal().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecfg_l_dgname_islocal(char *dgname, char **othernode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *metaset = "/usr/sbin/metaset -s %s -o > /dev/null 2>&1";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (snprintf(command, sizeof (command), metaset, dgname) >=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* metaset doesn't tell us */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cfg_dgname_islocal(char *dgname, char **othernode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -- determine if the named disk service is mastered on this node
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 * 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 Fortecfg_dgname_islocal(char *dgname, char **othernode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dgname == NULL || *dgname == '\0' || othernode == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Handle non-cluster configurations */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (cl_nodeid == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* it has to be local */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lookup the current diskgroup name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (data = (hash_data_t *)nsc_lookup(schash, dgname)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(data->scstat_node_name, cl_nodename)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cfg_l_dgname()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parse the disk group name from the a device pathname on a non-SunCluster.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns as cfg_dgname().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecfg_l_dgname(const char *pathname, char *buffer, size_t buflen)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* not a device pathname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(start, md, (ll = strlen(md))) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no dgname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strncmp(start, vx, (ll = strlen(vx))) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Veritas --
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*start == 'r' && strncmp((start + 1), dsk, ll) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no dgname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no dgname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cp = start, len = 0; *cp != '\0' && *cp != '/'; cp++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no dgname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "cfg_dgname: parse error: *cp = '%c', expected '/'\n", *cp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*cp != 'r' || strncmp((cp + 1), dsk, ll) != 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no dgname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cfg_dgname()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * determine which cluster resource group the pathname belongs to, if any
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NULL - error (errno is set)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ptr to NULL-string - no dgname
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pointer to string - dgname
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecfg_dgname(const char *pathname, char *buffer, size_t buflen)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Handle non-cluster configurations */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (cl_nodeid == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* must be local - return NULL-string dgname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte conferr = scconf_get_ds_by_devt(major(stb.st_rdev),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "scconf_get_ds_by_devt: %d: %s\n", conferr, errbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((char *)NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * init_sc_entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add an entry into the sclist and the schash for future lookups.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - IMPORTANT -
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 * - svadm (no options, "print") -- called during sv switchover
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - all boot commands
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return values:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1 An error occurred.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 Entry added
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 Entry already exists.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate a hash table
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
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 * 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 /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte err = scstat_get_ds_status((scstat_ds_name_t *)dsname, &dsstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "scstat_get_ds_status(): %d: %s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Traverse scstat_ds list, saving away resource in out hash table
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (dsp = dsstatus; dsp; dsp = dsp->scstat_ds_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Skip over NULL scstat_ds_name's */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* See element exits already, error if so */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "scstat_get_ds_status: duplicate %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Traverse the node status list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Only keep trace of primary nodes
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 * Free up scstat resources