/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This file contains the glue code that allows the NWS software to
* determine whether a cluster disk service is local to this node or
* not.
*
* See PSARC/1999/462 for more information on the interfaces from
* suncluster that are used here.
*/
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <dlfcn.h>
#include "cfg_cluster.h"
#include "cfg_impl.h"
#include "cfg.h"
/*
* Static variables
*/
static void *libscstat;
static void *libscconf;
static int init_sc_entry();
typedef struct hash_data_s {
} hash_data_t;
/*
* Global variables
*/
int cl_initialized = 0;
/*
* Tell the linker to keep quiet.
*/
/*
* Initialise the library if we have not done so before.
*
* - IMPORTANT -
*
* This must -never- be called from any command that can be started
* from /usr/cluster/lib/sc/run_reserve (and hence
* during switchover. This includes:
*
* - svadm (no options, "print") -- called during sv switchover
* - all boot commands
*
* - grab this node's cluster nodeid
* - attempt to dlopen() the suncluster shared libraries we need
* - grab this node's cluster nodename
*
* Returns:
* 0 - success
* -1 - error, errno is set
*/
int
cfg_cluster_init(void)
{
#ifdef DEBUG
#endif
char *name;
int rc;
/*
* First check to see if we really are a cluster as clinfo -n can lie
*/
if (cl_nodeid == 0xffff) {
/* not a cluster */
cl_initialized = 1;
cl_nodeid = 0;
return (0);
}
#ifdef DEBUG
#endif
return (-1);
}
#ifdef DEBUG
#endif
return (-1);
}
}
/* Already loaded the Sun Cluster device tree */
if (cl_initialized)
return (0);
/*
* Try and dlopen the various libraries that we need
*/
goto error;
goto error;
if (err == SCCONF_EPERM) {
cl_nodename = NULL;
} else if (err != SCCONF_NOERR) {
#ifdef DEBUG
#endif
goto error;
} else
cl_nodename = name;
/* Load the Sun Cluster device tree */
cl_initialized = 1;
return (0);
error: /* error cleanup */
if (libscconf)
if (libscstat)
return (-1);
}
/*
* cfg_issuncluster()
*
* Description:
* Return the SunCluster nodeid of this node.
*
* Returns:
* >0 - running in a SunCluster (value is nodeid of this node)
* 0 - not running in a cluster
* -1 - failure; errno is set
*/
int
{
if (cfg_cluster_init() >= 0)
return ((int)cl_nodeid);
else
return (-1);
}
int
{
return (cfg_issuncluster());
}
/*
* cfg_l_dgname_islocal()
* Check if disk group is local on a non-SunCluster.
*
* Returns as cfg_dgname_islocal().
*/
#ifndef lint
static int
{
int rc;
sizeof (command)) {
return (-1);
}
if (rc < 0) {
return (-1);
}
if (WEXITSTATUS(rc) != 0) {
if (othernode) {
/* metaset doesn't tell us */
*othernode = "unknown";
}
return (0);
}
return (1);
}
#endif
/*
* cfg_dgname_islocal(char *dgname, char **othernode)
* -- determine if the named disk service is mastered on this node
*
* If the disk service is mastered on another node, that nodename
* will be returned in othernode (if not NULL). It is up to the
* calling program to call free() on this value at a later time to
* free the memory allocated.
*
* Returns:
* 1 - disk service is mastered on this node
* 0 - disk service is not mastered on this node (*othernode set)
* -1 - error (errno will be set)
*/
int
{
return (-1);
}
/* Handle non-cluster configurations */
if (cfg_cluster_init() < 0) {
return (-1);
} else if (cl_nodeid == 0) {
/* it has to be local */
return (1);
}
/*
* lookup the current diskgroup name
*/
if (othernode)
return (0);
} else {
return (1);
}
} else {
return (-1);
}
}
/*
* cfg_l_dgname()
* parse the disk group name from the a device pathname on a non-SunCluster.
*
* Returns as cfg_dgname().
*/
char *
{
chkdsk = 0;
/* not a device pathname */
return ((char *)NULL);
}
/*
* SVM --
*/
(*start == 'r' &&
/* no dgname */
return (buffer);
}
/*
* Veritas --
*/
else {
/* no dgname */
return (buffer);
}
} else {
/* no dgname */
return (buffer);
}
len++; /* count length of dgname */
if (*cp == '\0') {
/* no dgname */
return (buffer);
}
#ifdef DEBUG
if (*cp != '/') {
"cfg_dgname: parse error: *cp = '%c', expected '/'\n", *cp);
return ((char *)NULL);
}
#endif
if (chkdsk) {
cp++; /* skip the NULL */
/* no dgname */
return (buffer);
}
}
return ((char *)NULL);
}
return (buffer);
}
/*
* cfg_dgname()
* determine which cluster resource group the pathname belongs to, if any
*
* Returns:
* NULL - error (errno is set)
* ptr to NULL-string - no dgname
* pointer to string - dgname
*/
char *
{
#ifdef DEBUG
#endif
return ((char *)NULL);
}
/* Handle non-cluster configurations */
if (cfg_cluster_init() < 0) {
return ((char *)NULL);
} else if (cl_nodeid == 0) {
/* must be local - return NULL-string dgname */
return (buffer);
}
return ((char *)NULL);
}
if (conferr == SCCONF_ENOEXIST) {
return (buffer);
} else if (conferr != SCCONF_NOERR) {
#ifdef DEBUG
#endif
return ((char *)NULL);
}
return (buffer);
}
/*
* init_sc_entry
*
* Add an entry into the sclist and the schash for future lookups.
*
* - IMPORTANT -
*
* This must -never- be called from any command that can be started
* from /usr/cluster/lib/sc/run_reserve (and hence
* during switchover. This includes:
*
* - svadm (no options, "print") -- called during sv switchover
* - all boot commands
*
* Return values:
* -1 An error occurred.
* 0 Entry added
* 1 Entry already exists.
*/
static int
{
#ifdef DEBUG
#endif
/*
* Allocate a hash table
*/
return (-1);
/*
* the API is broken here - the function is written to expect
* the first argument to be (scstat_ds_name_t), but the function
* declaration in scstat.h requires (scstat_ds_name_t *).
*
* We just cast it to get rid of the compiler warnings.
* If "dsname" is NULL, information for all device services is returned
*/
/* LINTED pointer alignment */
if (err != SCSTAT_ENOERR) {
#ifdef DEBUG
#endif
return (-1);
}
return (-1);
}
/*
* Traverse scstat_ds list, saving away resource in out hash table
*/
/* Skip over NULL scstat_ds_name's */
continue;
/* See element exits already, error if so */
return (-1);
}
/* Traverse the node status list */
/*
* Only keep trace of primary nodes
*/
continue;
/* Create an element to insert */
}
}
/*
* Free up scstat resources
*/
return (0);
}