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 */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki * Copyright 2010 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 <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/mnttab.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <limits.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <signal.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <locale.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <langinfo.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libintl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdarg.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/rdc_io.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/rdc_ioctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/rdc_prot.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/cfg.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 "rdcadm.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint maxqfbas = MAXQFBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint maxqitems = MAXQITEMS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint autosync = AUTOSYNC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint asyncthr = ASYNCTHR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint qblock = QBLOCK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemounted(char *device)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char target[NSC_MAXPATH];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct mnttab mntref;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct mnttab mntent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FILE *mntfp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rdsk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdsk = i = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (s = target; i < NSC_MAXPATH && (*s = *device++); i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*s == 'r' && rdsk == 0 && strncmp(device, "dsk/", 4) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdsk = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *s = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mntref.mnt_special = target;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mntref.mnt_mountp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mntref.mnt_fstype = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mntref.mnt_mntopts = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mntref.mnt_time = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mntfp = fopen(MNTTAB, "r");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mntfp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_warn(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("can not check volume %s against mount table"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mntref.mnt_special);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Assume the worst, that it is mounted */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getmntany(mntfp, &mntent, &mntref) != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* found something before EOF */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fclose(mntfp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fclose(mntfp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Needs to match parsing code in rdcboot.c and rdcadm.c */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_decode_flag(int flag, int options)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static char str[32];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (flag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_COPY):
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_FULL)
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-m");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-u");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_REVERSE)
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcat(str, " -r");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_DISABLE):
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-d");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_ENABLE):
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_SETBMP)
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-e");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-E");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_LOG):
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-l");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_HEALTH):
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-H");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_WAIT):
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-w");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_RECONFIG):
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-R ...");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_TUNABLE):
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (maxqfbas != MAXQFBAS)
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcat(str, " -F");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (maxqitems != MAXQITEMS)
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcat(str, " -W");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (autosync != AUTOSYNC)
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcat(str, " -a");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (asyncthr != ASYNCTHR)
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcat(str, " -A");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (qblock != QBLOCK)
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcat(str, " -D");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_SUSPEND):
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-s");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_RESUME):
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-r");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_RESET):
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-R");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_ADDQ):
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-q a");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_REMQ):
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-q d");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case (RDC_CMD_REPQ):
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, "-q r");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(str, gettext("unknown"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (str);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_msg(char *prefix, spcs_s_info_t *status, char *string, va_list ap)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "Remote Mirror: %s\n", prefix);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_report(*status, stderr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "%s: %s: ", program, prefix);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (string && *string != '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) vfprintf(stderr, string, ap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, "\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_err(spcs_s_info_t *status, char *string, ...)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_list ap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_start(ap, string);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_msg(gettext("Error"), status, string, ap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_end(ap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_warn(spcs_s_info_t *status, char *string, ...)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_list ap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_start(ap, string);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_msg(gettext("warning"), status, string, ap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_end(ap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_get_maxsets(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_status_t rdc_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_info_t ustatus;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_status.nset = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ustatus = spcs_s_ucreate();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_IOCTL(RDC_STATUS, &rdc_status, 0, 0, 0, 0, ustatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == SPCS_S_ERROR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_err(&ustatus, gettext("statistics error"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_ufree(&ustatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rdc_status.maxsets);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Look up a set in libcfg to find the setnumber.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ASSUMPTIONS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - a valid cfg handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * INPUTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cfg - cfg handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tohost - secondary hostname
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tofile - secondary volume
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * OUTPUTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set number if found, otherwise -1 for an error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefind_setnumber_in_libcfg(CFGFILE *cfg, char *ctag, char *tohost, char *tofile)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int setnumber;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int entries, rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *buf, *secondary, *shost;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char **entry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *cnode;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int offset = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_warn(NULL, "cfg is NULL while looking up set number");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entries = cfg_get_section(cfg, &entry, "sndr");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (setnumber = 1; setnumber <= entries; setnumber++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf = entry[setnumber - 1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strtok(buf, " "); /* phost */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strtok(NULL, " "); /* primary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strtok(NULL, " "); /* pbitmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte shost = strtok(NULL, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte secondary = strtok(NULL, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ctag && *ctag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strtok(NULL, " "); /* sbitmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strtok(NULL, " "); /* type */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strtok(NULL, " "); /* mode */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strtok(NULL, " "); /* group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnode = strtok(NULL, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ctag && strcmp(cnode, ctag) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* filter this out */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check secondary volume name first, will get less hits */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(secondary, tofile) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(shost, tohost) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = setnumber - offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (setnumber < entries)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(entry[setnumber++]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (entries)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(entry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_group_diskq(CFGFILE *cfg, char *group, char *diskq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char key[CFG_MAX_KEY];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*group == '\0')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 1; ; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&key, sizeof (key));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&buf, sizeof (buf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(key, "sndr.set%d.group", i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_cstring(cfg, key, &buf, sizeof (buf)) < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(group, buf, sizeof (buf)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(key, "sndr.set%d.diskq", i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_cstring(cfg, key, diskq, CFG_MAX_BUF) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_warn(NULL, gettext("unable to retrieve "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "group %s's disk queue"), group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_cfg_setid(CFGFILE *cfg, char *ctag, char *tohost, char *tofile)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int setnum = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int close_cfg = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char key[CFG_MAX_KEY];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char setid[64];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close_cfg = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cfg = cfg_open(NULL)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1); /* message printed by caller */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cfg_lock(cfg, CFG_RDLOCK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setnum = find_setnumber_in_libcfg(cfg, ctag, tohost, tofile);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (setnum < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (setnum);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(key, CFG_MAX_KEY, "sndr.set%d.options", setnum);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_single_option(cfg, CFG_SEC_CONF, key, "setid",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setid, sizeof (setid)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (close_cfg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_log("sndr", NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("%s unable to get unique setid "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "for %s:%s"), program, tohost, tofile);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (close_cfg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (atoi(setid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_new_cfg_setid(CFGFILE *cfg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int setid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *ctag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If in a Sun Cluster, SetIDs need to have a ctag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ctag = cfg_get_resource(cfg)) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ctag = strdup(ctag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_resource(cfg, "setid-ctag");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_cstring(cfg, "setid.set1.value", buf, CFG_MAX_BUF) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setid = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, "setid", "1", CFG_MAX_BUF) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_err(NULL, "Unable to store new setid");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setid = atoi(buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setid++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (setid <= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setid = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&buf, CFG_MAX_BUF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(buf, sizeof (buf), "%d", setid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, "setid.set1.value", buf, CFG_MAX_BUF) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_err(NULL, "Unable to store new setid");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Restore old ctag if in a Sun Cluster */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ctag) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_resource(cfg, ctag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(ctag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (setid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesigset_t origmask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteblock_sigs(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sigset_t allsigs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) sigfillset(&allsigs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sigprocmask(SIG_BLOCK, &allsigs, &origmask) < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_warn(NULL, gettext("Unable to block signals"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteunblock_sigs(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sigprocmask(SIG_SETMASK, &origmask, NULL) < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_warn(NULL, gettext("Unable to unblock signals"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}