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 <sys/mkdev.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/param.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/wait.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdarg.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <locale.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <search.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libgen.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_s_u.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/unistat/spcs_errors.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/sv.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/sv_impl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/cfg.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsc_hash.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "../sv/svadm.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sv_max_devices;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * support for the special cluster tag "local" to be used with -C in a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cluster for local volumes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SV_LOCAL_TAG "local"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sv_islocal;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * libcfg access.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic CFGFILE *cfg; /* libcfg file pointer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int cfg_changed; /* set to 1 if we need to commit changes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *cfg_cluster_tag; /* local cluster tag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char *implicit_tag; /* implicit cluster tag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Print width for print_sv() output.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define STATWIDTH (SV_MAXPATH / 2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Pathnames.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic const caddr_t sv_rpath = SV_DEVICE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Functions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int read_config_file(const caddr_t, sv_name_t []);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int enable_dev(sv_name_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int disable_dev(const caddr_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void error(spcs_s_info_t *, caddr_t, ...);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void create_cfg_hash();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int find_in_hash(char *path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void destroy_hashtable();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void remove_from_cfgfile(char *path, int setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic caddr_t program;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesv_cfg_open(CFGLOCK mode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg = cfg_open(NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("unable to access the configuration"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOTREACHED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_cluster_tag && *cfg_cluster_tag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_resource(cfg, cfg_cluster_tag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_resource(cfg, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cfg_lock(cfg, mode)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("unable to lock the configuration"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOTREACHED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesv_cfg_close(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_changed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) cfg_commit(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_changed = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteusage(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext("usage:\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "\t%s -h help\n"), program);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "\t%s [-C tag] display status\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte program);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "\t%s [-C tag] -i display "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "extended status\n"), program);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "\t%s [-C tag] -v display "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "version number\n"), program);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "\t%s [-C tag] -e { -f file | volume } enable\n"), program);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "\t%s [-C tag] -d { -f file | volume } disable\n"), program);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "\t%s [-C tag] -r { -f file | volume } reconfigure\n"), program);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_close();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemessage(caddr_t prefix, spcs_s_info_t *status, caddr_t string, va_list ap)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s: ", program, prefix);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) vfprintf(stderr, string, ap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_report(*status, stderr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_ufree(status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteerror(spcs_s_info_t *status, caddr_t string, ...)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_list ap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_start(ap, string);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte message(gettext("error"), status, string, ap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_end(ap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_close();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortewarn(spcs_s_info_t *status, caddr_t string, ...)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_list ap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_start(ap, string);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte message(gettext("warning"), status, string, ap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_end(ap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesv_get_maxdevs(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_name_t svn[1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_list_t svl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sv_max_devices > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fd = open(sv_rpath, O_RDONLY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fd < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("unable to open %s: %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_rpath, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&svl, sizeof (svl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&svn[0], sizeof (svn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svl.svl_names = &svn[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svl.svl_error = spcs_s_ucreate();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, SVIOC_LIST, &svl) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(&svl.svl_error, gettext("unable to get max devs"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_ufree(&svl.svl_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_max_devices = svl.svl_maxdevs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic sv_name_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesv_alloc_svnames(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_name_t *svn = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_get_maxdevs();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn = calloc(sv_max_devices, sizeof (*svn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (svn == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, "unable to allocate %ld bytes of memory",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_max_devices * sizeof (*svn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (svn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesv_check_dgislocal(char *dgname)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *othernode;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check where this disk service is mastered
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = cfg_dgname_islocal(dgname, &othernode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("unable to find "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "disk service, %s: %s"), dgname, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("disk service, %s, is "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "active on node \"%s\"\nPlease re-issue "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "the command on that node"), dgname, othernode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Carry out cluster based checks for a specified volume, or just
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * global options.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesv_check_cluster(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char dgname[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static int sv_iscluster = -1; /* set to 1 if running in a cluster */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Find out if we are running in a cluster
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sv_iscluster == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sv_iscluster = cfg_iscluster()) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("unable to ascertain environment"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!sv_iscluster && cfg_cluster_tag != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("-C is not valid when not in a cluster"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!sv_iscluster || sv_islocal || path == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Cluster-only checks on pathname
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_dgname(path, dgname, sizeof (dgname)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("unable to determine "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "disk group name for %s"), path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_cluster_tag != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do dgislocal check now in case path did not contain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a dgname.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * E.g. adding a /dev/did/ device to a disk service.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_check_dgislocal(cfg_cluster_tag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(dgname, "") == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return; /* NULL dgname is valid */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_cluster_tag == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Implicitly set the cluster tag to dgname
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_check_dgislocal(dgname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (implicit_tag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(implicit_tag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte implicit_tag = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte implicit_tag = strdup(dgname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (implicit_tag == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("unable to allocate memory "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "for cluster tag"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check dgname and cluster tag from -C are the same.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(dgname, cfg_cluster_tag) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("-C (%s) does not match disk group "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "name (%s) for %s"), cfg_cluster_tag,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dgname, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sv_check_dgislocal(cfg_cluster_tag) was called above.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteprint_version(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_version_t svv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&svv, sizeof (svv));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svv.svv_error = spcs_s_ucreate();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fd = open(sv_rpath, O_RDONLY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fd < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("unable to open %s: %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_rpath, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, SVIOC_VERSION, &svv) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(&svv.svv_error,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("unable to read the version number"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOTREACHED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_ufree(&svv.svv_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("Storage Volume version %d.%d.%d.%d\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svv.svv_major_rev, svv.svv_minor_rev,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svv.svv_micro_rev, svv.svv_baseline_rev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (svv.svv_micro_rev) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("Storage Volume version %d.%d.%d\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svv.svv_major_rev, svv.svv_minor_rev, svv.svv_micro_rev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("Storage Volume version %d.%d\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svv.svv_major_rev, svv.svv_minor_rev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemain(int argc, char *argv[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte extern int optind;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte extern char *optarg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *conf_file = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int enable, disable, compare, print, version;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int opt, Cflag, fflag, iflag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) setlocale(LC_ALL, "");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) textdomain("svadm");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte program = strdup(basename(argv[0]));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Cflag = fflag = iflag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte compare = enable = disable = version = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((opt = getopt(argc, argv, "C:def:hirv")) != EOF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (opt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'C':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (Cflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("-C specified multiple times"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOTREACHED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte Cflag++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_cluster_tag = optarg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'e':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte enable++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'd':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disable++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'f':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fflag++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte conf_file = optarg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'i':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iflag++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'r':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Compare running system with sv.cf */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte compare++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'v':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte version++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'h':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOTREACHED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Usage checks
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((enable + disable + compare) > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("-d, -e and -r are mutually exclusive"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fflag && (print || version)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("-f is only valid with -d, -e or -r"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fflag && optind != argc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (print || version) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check for no more args */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (optind != argc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check for inline args */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!fflag && (argc - optind) != 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!print && iflag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check for the special cluster tag and convert into the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * internal representation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_cluster_tag != NULL &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcmp(cfg_cluster_tag, SV_LOCAL_TAG) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_cluster_tag = "-";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_islocal = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Process commands
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (optind != argc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* deal with inline volume argument */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (enable)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = enable_one_sv(argv[optind]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (disable)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = disable_one_sv(argv[optind]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else /* if (compare) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte compare_one_sv(argv[optind]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (enable)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = enable_sv(conf_file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (disable)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = disable_sv(conf_file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (compare)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte compare_sv(conf_file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (print)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_sv(iflag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else /* if (version) */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_version();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* LINT - not static as fwcadm uses it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteenable_sv(char *conf_file)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_name_t *svn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc, ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn = sv_alloc_svnames();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = read_config_file(conf_file, svn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cnt = 0; cnt < index; cnt++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check for more data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (svn[cnt].svn_path[0] == '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This was set when reading sv.conf. After the last
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * line svn_path was set to \0, so we are finished.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We shouldn't get here, but put this in just in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * case.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = enable_dev(&svn[cnt]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc && !ret)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_close();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* LINT - not static as fwcadm uses it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteenable_one_sv(caddr_t path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_name_t svn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_get_maxdevs();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&svn, sizeof (svn));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(svn.svn_path, path, sizeof (svn.svn_path));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn.svn_mode = (NSC_DEVICE | NSC_CACHE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* force NULL termination */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn.svn_path[sizeof (svn.svn_path) - 1] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = enable_dev(&svn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_close();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteenable_dev(sv_name_t *svn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat stb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_conf_t svc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *lcltag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *altname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_check_cluster(svn->svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_open(CFG_WRLOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&svc, sizeof (svc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(svn->svn_path, &stb) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("unable to access %s: %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn->svn_path, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!S_ISCHR(stb.st_mode)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("%s is not a character device - ignored"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn->svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svc.svc_major = major(stb.st_rdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svc.svc_minor = minor(stb.st_rdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(svc.svc_path, svn->svn_path, sizeof (svc.svc_path));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fd = open(sv_rpath, O_RDONLY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fd < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("unable to open %s: %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn->svn_path, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svc.svc_flag = svn->svn_mode;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svc.svc_error = spcs_s_ucreate();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* first, check for duplicates */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = cfg_get_canonical_name(cfg, svn->svn_path, &altname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("sv", NULL, gettext("Unable to parse config file"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("Unable to parse config file"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("'%s' has already been configured as "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "'%s'. Re-enter command with the latter name."),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn->svn_path, altname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* secondly, try to insert it into the dsvol config */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (implicit_tag && *implicit_tag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lcltag = implicit_tag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (cfg_cluster_tag && *cfg_cluster_tag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lcltag = cfg_cluster_tag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lcltag = "-";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = cfg_add_user(cfg, svn->svn_path, lcltag, "sv");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CFG_USER_ERR == rc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("sv", NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to put %s into dsvol cfg"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte program, svn->svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("unable to put %s into dsvol cfg"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn->svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_changed = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CFG_USER_OK == rc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* success */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, SVIOC_ENABLE, &svc) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((CFG_USER_REPEAT == rc) && (SV_EENABLED == errno)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* it's ok -- we were just double-checking */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("sv", &svc.svc_error,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to enable %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte program, svn->svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(&svc.svc_error, gettext("unable to enable %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn->svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove it from dsvol, if we're the ones who put it in */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (CFG_USER_FIRST == rc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) cfg_rem_user(cfg, svn->svn_path, lcltag, "sv");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("sv", NULL, gettext("%s: enabled %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte program, svn->svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (implicit_tag != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_cluster_tag != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("enable_dev: -C %s AND implicit_tag %s!"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_cluster_tag, implicit_tag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(buf, sizeof (buf), "%s - %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svc.svc_path, implicit_tag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(buf, svc.svc_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, "sv", buf, sizeof (buf)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("unable to add %s to configuration storage: %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svc.svc_path, cfg_error(&sev));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_changed = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_ufree(&svc.svc_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine parses the config file passed in via conf_file and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stores the data in the svn array. The return value is the number
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of entries read from conf_file. If an error occurs the error()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * routine is called (which exits the program).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteread_config_file(const caddr_t conf_file, sv_name_t svn[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char line[1024], rdev[1024], junk[1024];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat stb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int lineno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cnt, i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index = 0; /* Current location in svn array */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_name_t *cur_svn; /* Pointer to svn[index] */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FILE *fp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (access(conf_file, R_OK) != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stat(conf_file, &stb) != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !S_ISREG(stb.st_mode)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("cannot read config file %s"), conf_file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fp = fopen(conf_file, "r")) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("unable to open config file %s: %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte conf_file, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lineno = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (fgets(line, sizeof (line), fp) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lineno++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i = strlen(line);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i < 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (line[i-1] == '\n')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte line[i-1] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (i == (sizeof (line) - 1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "line %d: line too long -- should be less than %d characters"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lineno, (sizeof (line) - 1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("line %d: ignored"), lineno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check for comment line.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (line[0] == '#')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnt = sscanf(line, "%s %s", rdev, junk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cnt != 1 && cnt != 2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cnt > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("line %d: invalid format"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lineno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("line %d: ignored"), lineno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdev[sizeof (rdev) - 1] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_svn = &svn[index]; /* For easier reading below */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strlen(rdev) >= sizeof (cur_svn->svn_path)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "line %d: raw device name (%s) longer than %d characters"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lineno, rdev,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (sizeof (cur_svn->svn_path) - 1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("line %d: ignored"), lineno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(cur_svn->svn_path, rdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_svn->svn_mode = (NSC_DEVICE | NSC_CACHE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set the last path to NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn[index].svn_path[0] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fclose(fp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Disable the device from the kernel configuration.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RETURN:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 on success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero on failure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Failures are reported to the user.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedisable_dev(const caddr_t path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat stb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_conf_t svc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_check_cluster(path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(path, &stb) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svc.svc_major = (major_t)-1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svc.svc_minor = (minor_t)-1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svc.svc_major = major(stb.st_rdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svc.svc_minor = minor(stb.st_rdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(sv_rpath, O_RDONLY)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("unable to open %s: %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_rpath, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(svc.svc_path, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svc.svc_error = spcs_s_ucreate();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue the ioctl to attempt to disable this device. Note that all
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the libdscfg details are handled elsewhere.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, SVIOC_DISABLE, &svc) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (errno != SV_EDISABLED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("sv", &svc.svc_error,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: unable to disable %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte program, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(&svc.svc_error,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("unable to disable %s"), path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("sv", NULL, gettext("%s: disabled %s"), program, path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_ufree(&svc.svc_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteprint_cluster_tag(const int setnumber)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char key[CFG_MAX_KEY];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(buf, sizeof (buf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(key, sizeof (key), "sv.set%d.cnode", setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) cfg_get_cstring(cfg, key, buf, sizeof (buf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*buf != '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(buf, "-") == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(" [%s]", gettext("local to node"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(" [%s: %s]", gettext("cluster"), buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* LINT - not static as fwcadm uses it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteprint_sv(int verbose)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_name_t *svn, *svn_system; /* Devices in system */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_list_t svl_system;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd, i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int setnumber;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_check_cluster(NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_open(CFG_RDLOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn_system = sv_alloc_svnames();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(sv_rpath, O_RDONLY)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("unable to open %s: %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_rpath, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Grab the system list from the driver */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svl_system.svl_count = sv_max_devices;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svl_system.svl_names = &svn_system[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svl_system.svl_error = spcs_s_ucreate();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, SVIOC_LIST, &svl_system) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(&svl_system.svl_error, gettext("unable to get list"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_ufree(&svl_system.svl_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We build a hashmap out of the entries from the config file to make
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * searching faster. We end up taking a performance hit when the # of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * volumes is small, but for larger configurations it's a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * HUGE improvement.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* build the hashtable */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_rewind(cfg, CFG_SEC_CONF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte create_cfg_hash();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For each volume found from the kernel, print out
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * info about it from the kernel.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < svl_system.svl_count; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*svn_system[i].svn_path == '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn = &svn_system[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (svn->svn_mode == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("%s [kernel guard]\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn->svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get sv entry from the hashtable */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((setnumber = find_in_hash(svn->svn_path)) != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("%-*s", STATWIDTH, svn->svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verbose) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_cluster_tag(setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We didn't find the entry in the hashtable. Let
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the user know that the persistent storage is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inconsistent with the kernel configuration.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_cluster_tag == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s is configured, but not in the "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "config storage"), svn->svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free up the hashtable */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte destroy_hashtable();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_close();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* LINT - not static as fwcadm uses it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedisable_sv(char *conf_file)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_name_t *svn, *svn_system; /* Devices in system */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_list_t svl_system;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd, i, setnumber;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc, ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn_system = sv_alloc_svnames();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (conf_file == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(sv_rpath, O_RDONLY)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("unable to open %s: %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_rpath, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Grab the system list from the driver */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svl_system.svl_count = sv_max_devices;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svl_system.svl_names = &svn_system[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svl_system.svl_error = spcs_s_ucreate();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, SVIOC_LIST, &svl_system) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(&(svl_system.svl_error),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("unable to get list"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_ufree(&(svl_system.svl_error));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svl_system.svl_count = read_config_file(conf_file, svn_system);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < svl_system.svl_count; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*svn_system[i].svn_path == '\0')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn = &svn_system[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_check_cluster(svn->svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_open(CFG_WRLOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte create_cfg_hash();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((setnumber = find_in_hash(svn->svn_path)) != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = disable_dev(svn->svn_path)) != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remove_from_cfgfile(svn->svn_path, setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (errno == SV_ENODEV) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remove_from_cfgfile(svn->svn_path, setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* warn the user that we didn't find it in cfg file */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s was not found in the config storage"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn->svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* try to disable anyway */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) disable_dev(svn->svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_close();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte destroy_hashtable();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc && !ret)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* LINT - not static as fwcadm uses it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedisable_one_sv(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int setnumber;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_get_maxdevs();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_check_cluster(path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_open(CFG_WRLOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte create_cfg_hash();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((setnumber = find_in_hash(path)) != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove from kernel */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = disable_dev(path)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove the cfgline */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remove_from_cfgfile(path, setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (errno == SV_ENODEV) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remove_from_cfgfile(path, setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* warn the user that we didn't find it in cfg file */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s was not found in the config storage"), path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* still attempt to remove */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) disable_dev(path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte destroy_hashtable();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_close();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecompare_tag(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[CFG_MAX_BUF], vol[CFG_MAX_BUF], cnode[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char key[CFG_MAX_KEY];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int found, setnumber, i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *tag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_check_cluster(path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_resource(cfg, (char *)NULL); /* reset */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_rewind(cfg, CFG_SEC_CONF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_cluster_tag != NULL && implicit_tag != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("compare_tag: -C %s AND implicit_tag %s!"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_cluster_tag, implicit_tag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_cluster_tag != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tag = cfg_cluster_tag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (implicit_tag != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tag = implicit_tag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tag = "-";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sv_max_devices; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setnumber = i + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(key, sizeof (key), "sv.set%d", setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sscanf(buf, "%s - %s", vol, cnode) != 2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(path, vol) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!found) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("unable to find %s in the configuration"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* have name match, compare cnode to new tag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(tag, cnode) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cluster tags match */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* need to change the cluster tag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(key, sizeof (key), "sv.set%d.cnode", setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, key, tag, strlen(tag)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("unable to change cluster tag for %s"), path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_changed = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* change "-" tags to "" for display purposes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(tag, "-") == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tag = "";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(cnode, "-") == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(cnode, "");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: changed cluster tag for %s from \"%s\" to \"%s\"\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte program, path, cnode, tag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("sv", NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s: changed cluster tag for %s from \"%s\" to \"%s\""),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte program, path, cnode, tag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* LINT - not static as fwcadm uses it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecompare_sv(char *conf_file)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_name_t *svn_config; /* Devices in config file */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_name_t *svn_system; /* Devices in system */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_name_t *enable; /* Devices that need enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_list_t svl_system;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int config_cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sys_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int setnumber, i, j;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index = 0; /* Index in enable[] */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int found;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn_config = sv_alloc_svnames();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn_system = sv_alloc_svnames();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte enable = sv_alloc_svnames();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(svn_system, sizeof (svn_system));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&svl_system, sizeof (svl_system));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(enable, sizeof (enable));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Read the configuration file
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The return value is the number of entries
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte config_cnt = read_config_file(conf_file, svn_config);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd0 = open(sv_rpath, O_RDONLY)) < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("unable to open %s: %s"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_rpath, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Grab the system list from the driver */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svl_system.svl_count = sv_max_devices;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svl_system.svl_names = &svn_system[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svl_system.svl_error = spcs_s_ucreate();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd0, SVIOC_LIST, &svl_system) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(&svl_system.svl_error, gettext("unable to get list"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_ufree(&svl_system.svl_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Count the number of devices in the system.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The last entry in the array has '\0' for a path name.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < sv_max_devices; j++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (svn_system[j].svn_path[0] != '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sys_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Compare the configuration array with the system array.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Mark any differences and disable conflicting devices.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < config_cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < sys_cnt; j++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (svn_system[j].svn_path[0] == '\0' ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn_system[j].svn_mode == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check to see if path matches */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(svn_system[j].svn_path,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn_config[i].svn_path) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Found a match */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn_system[j].svn_path[0] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!found) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Minor number not in system = > enable device */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte enable[index].svn_mode = svn_config[i].svn_mode;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(enable[index].svn_path,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn_config[i].svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Disable any devices that weren't in the config file */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < sys_cnt; j++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_check_cluster(NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_open(CFG_WRLOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte create_cfg_hash();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (svn_system[j].svn_path[0] != '\0' &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn_system[j].svn_mode != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("%s: disabling sv: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte program, svn_system[j].svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (disable_dev(svn_system[j].svn_path) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setnumber =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte find_in_hash(svn_system[j].svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (setnumber != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* the volume was found in cfg store */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remove_from_cfgfile(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svn_system[j].svn_path, setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_close();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte destroy_hashtable();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (index) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Config file doesn't match system => enable the devices
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in enable[]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(gettext("%s: enabling new sv: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte program, enable[index].svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) enable_dev(&enable[index]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Search for entries where the cluster tag has changed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_check_cluster(NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_open(CFG_WRLOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sv_max_devices; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (svn_config[i].svn_path[0] == '\0')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte compare_tag(svn_config[i].svn_path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_close();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We assume that the volume is already enabled and we can only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be changing the cluster tag. Anything else is an error.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* LINT - not static as fwcadm uses it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecompare_one_sv(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_get_maxdevs();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_check_cluster(NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_open(CFG_WRLOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte compare_tag(path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_cfg_close();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Read all sets from the libdscfg configuration file, and store everything in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the hashfile.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We assume that the config file has been opened & rewound for us. We store
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the volume name as the key, and the setnumber where we found it as the data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The caller can pass in a pointer to the maximum number of volumes, or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a pointer to NULL, specifying we want 'all' the volumes. The table is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * searched using find_in_hash.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecreate_cfg_hash()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char key[CFG_MAX_KEY], buf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char vol[CFG_MAX_BUF], cnode[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int setnumber;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ENTRY item;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hcreate((size_t)sv_max_devices) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL, gettext("unable to create hash table"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (setnumber = 1; /* CSTYLED */; setnumber++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(key, sizeof (key), "sv.set%d", setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sscanf(buf, "%s - %s", vol, cnode) != 2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte item.key = strdup(vol);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte item.data = (void *)setnumber;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hsearch(item, ENTER) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte error(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("unable to add entry to hash table"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Function to search the hash for a specific volume. If it is found,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we return the set number. If it isn't found, we return -1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefind_in_hash(char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ENTRY *found_entry, item;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int retval = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte item.key = path;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((found_entry = hsearch(item, FIND)) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retval = (int)found_entry->data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (retval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Just a wrapper to destory the hashtable. At some point in the future we
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * might want to do something more.... For instance, verify that the cfg
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * database and the kernel configuration match (?) Just an idea.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedestroy_hashtable()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hdestroy();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function will remove a particular set from the config file.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We make a whole host of assumptions:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * o the hashfile is up to date;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * o The config file has been opened with a WRLOCK for us.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteremove_from_cfgfile(char *path, int setnumber)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char key[CFG_MAX_KEY];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *lcltag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* attempt to remove the volume from config storage */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(key, sizeof (key), "sv.set%d", setnumber);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, key, NULL, 0) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("unable to remove %s from "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "config storage: %s"), path, cfg_error(&sev));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (implicit_tag && *implicit_tag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lcltag = implicit_tag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (cfg_cluster_tag && *cfg_cluster_tag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lcltag = cfg_cluster_tag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lcltag = "-";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_rem_user(cfg, path, lcltag, "sv") != CFG_USER_LAST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte warn(NULL, gettext("unable to remove %s from dsvol"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte path);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_changed = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}